Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llms/openai] Bugfix for openallm function calls - must have a Name #1088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llms/openai/openaillm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

// GenerateContent implements the Model interface.
func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageContent, options ...llms.CallOption) (*llms.ContentResponse, error) { //nolint: lll, cyclop, goerr113, funlen

Check failure on line 47 in llms/openai/openaillm.go

View workflow job for this annotation

GitHub Actions / Lint

cognitive complexity 33 of func `(*LLM).GenerateContent` is high (> 30) (gocognit)
if o.CallbacksHandler != nil {
o.CallbacksHandler.HandleLLMGenerateContentStart(ctx, messages)
}
Expand All @@ -68,6 +68,16 @@
msg.Role = RoleUser
case llms.ChatMessageTypeFunction:
msg.Role = RoleFunction
if len(mc.Parts) != 1 {
return nil, fmt.Errorf("expected exactly one part for role %v, got %v", mc.Role, len(mc.Parts))
}
switch p := mc.Parts[0].(type) {
case llms.ToolCallResponse:
msg.Name = p.Name
msg.Content = p.Content
default:
return nil, fmt.Errorf("expected part of type ToolCallResponse for role %v, got %T", mc.Role, mc.Parts[0])
}
case llms.ChatMessageTypeTool:
msg.Role = RoleTool
// Here we extract tool calls from the message and populate the ToolCalls field.
Expand Down
Loading