From 38cff317a022ae67cae9b04d1ce6f1e11f23c8a5 Mon Sep 17 00:00:00 2001 From: Yan <1964649083@qq.com> Date: Sat, 28 Dec 2024 17:46:56 +0800 Subject: [PATCH] fix: add index in the tool calls when chat by stream (gemini) --- dto/openai_response.go | 4 ++++ relay/channel/gemini/relay-gemini.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dto/openai_response.go b/dto/openai_response.go index 0f603ad2..4b4a614e 100644 --- a/dto/openai_response.go +++ b/dto/openai_response.go @@ -86,6 +86,10 @@ type ToolCall struct { Function FunctionCall `json:"function"` } +func (c *ToolCall) SetIndex(i int) { + c.Index = &i +} + type FunctionCall struct { Description string `json:"description,omitempty"` Name string `json:"name,omitempty"` diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index cbaa2796..dda84084 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -370,7 +370,6 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp choice.Message.SetToolCalls(tool_calls) is_tool_call = true } - // 过滤掉空行 choice.Message.SetStringContent(strings.Join(texts, "\n")) @@ -425,6 +424,7 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) (*dto.C if part.FunctionCall != nil { isTools = true if call := getToolCall(&part); call != nil { + call.SetIndex(len(choice.Delta.ToolCalls)) choice.Delta.ToolCalls = append(choice.Delta.ToolCalls, *call) } } else {