From 4d4fece7c909a709411bf2e96a4be6bd266fe93e Mon Sep 17 00:00:00 2001 From: deanyychen Date: Wed, 16 Aug 2023 17:40:04 +0800 Subject: [PATCH] bug: role assistant message maybe have function_call --- llms/openai/openaillm_chat.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index 3bf32daeb..aa9529717 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -40,6 +40,7 @@ func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options return r[0].Message, nil } +//nolint:funlen func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error) { // nolint:lll,cyclop opts := llms.CallOptions{} for _, opt := range options { @@ -58,6 +59,12 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, msg.Role = "system" case schema.ChatMessageTypeAI: msg.Role = "assistant" + if aiChatMsg, ok := m.(schema.AIChatMessage); ok && aiChatMsg.FunctionCall != nil { + msg.FunctionCall = &openaiclient.FunctionCall{ + Name: aiChatMsg.FunctionCall.Name, + Arguments: aiChatMsg.FunctionCall.Arguments, + } + } case schema.ChatMessageTypeHuman: msg.Role = "user" case schema.ChatMessageTypeGeneric: