Skip to content

Commit 5c9504a

Browse files
committed
fixes tmc#1029
1 parent 1975058 commit 5c9504a

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

llms/openai/openaillm.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
6969
case llms.ChatMessageTypeFunction:
7070
msg.Role = RoleFunction
7171
case llms.ChatMessageTypeTool:
72-
msg.Role = RoleTool
7372
// Here we extract tool calls from the message and populate the ToolCalls field.
74-
75-
// parse mc.Parts (which should have one entry of type ToolCallResponse) and populate msg.Content and msg.ToolCallID
76-
if len(mc.Parts) != 1 {
77-
return nil, fmt.Errorf("expected exactly one part for role %v, got %v", mc.Role, len(mc.Parts))
78-
}
79-
switch p := mc.Parts[0].(type) {
80-
case llms.ToolCallResponse:
81-
msg.ToolCallID = p.ToolCallID
82-
msg.Content = p.Content
83-
default:
84-
return nil, fmt.Errorf("expected part of type ToolCallResponse for role %v, got %T", mc.Role, mc.Parts[0])
73+
for _, p := range mc.Parts {
74+
switch p.(type) {
75+
case llms.ToolCallResponse:
76+
tr := p.(llms.ToolCallResponse)
77+
rep := &ChatMessage{}
78+
rep.Role = RoleTool
79+
rep.ToolCallID = tr.ToolCallID
80+
rep.Content = tr.Content
81+
chatMsgs = append(chatMsgs, rep)
82+
default:
83+
return nil, fmt.Errorf("expected part of type ToolCallResponse for role %v, got %T", mc.Role, mc.Parts[0])
84+
}
8585
}
86-
86+
continue
8787
default:
8888
return nil, fmt.Errorf("role %v not supported", mc.Role)
8989
}

0 commit comments

Comments
 (0)