From 5c9504a3a41add5f26a78b9a819e0489f07c2d86 Mon Sep 17 00:00:00 2001 From: Martin Buhr Date: Mon, 23 Sep 2024 08:57:27 +1200 Subject: [PATCH] fixes #1029 --- llms/openai/openaillm.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/llms/openai/openaillm.go b/llms/openai/openaillm.go index 699c0d304..378a278c2 100644 --- a/llms/openai/openaillm.go +++ b/llms/openai/openaillm.go @@ -69,21 +69,21 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten case llms.ChatMessageTypeFunction: msg.Role = RoleFunction case llms.ChatMessageTypeTool: - msg.Role = RoleTool // Here we extract tool calls from the message and populate the ToolCalls field. - - // parse mc.Parts (which should have one entry of type ToolCallResponse) and populate msg.Content and msg.ToolCallID - 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.ToolCallID = p.ToolCallID - msg.Content = p.Content - default: - return nil, fmt.Errorf("expected part of type ToolCallResponse for role %v, got %T", mc.Role, mc.Parts[0]) + for _, p := range mc.Parts { + switch p.(type) { + case llms.ToolCallResponse: + tr := p.(llms.ToolCallResponse) + rep := &ChatMessage{} + rep.Role = RoleTool + rep.ToolCallID = tr.ToolCallID + rep.Content = tr.Content + chatMsgs = append(chatMsgs, rep) + default: + return nil, fmt.Errorf("expected part of type ToolCallResponse for role %v, got %T", mc.Role, mc.Parts[0]) + } } - + continue default: return nil, fmt.Errorf("role %v not supported", mc.Role) }