@@ -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