fix: add index in the tool calls when chat by stream (gemini)
This commit is contained in:
@@ -86,6 +86,10 @@ type ToolCall struct {
|
|||||||
Function FunctionCall `json:"function"`
|
Function FunctionCall `json:"function"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ToolCall) SetIndex(i int) {
|
||||||
|
c.Index = &i
|
||||||
|
}
|
||||||
|
|
||||||
type FunctionCall struct {
|
type FunctionCall struct {
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
|||||||
@@ -370,7 +370,6 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
|
|||||||
choice.Message.SetToolCalls(tool_calls)
|
choice.Message.SetToolCalls(tool_calls)
|
||||||
is_tool_call = true
|
is_tool_call = true
|
||||||
}
|
}
|
||||||
// 过滤掉空行
|
|
||||||
|
|
||||||
choice.Message.SetStringContent(strings.Join(texts, "\n"))
|
choice.Message.SetStringContent(strings.Join(texts, "\n"))
|
||||||
|
|
||||||
@@ -425,6 +424,7 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) (*dto.C
|
|||||||
if part.FunctionCall != nil {
|
if part.FunctionCall != nil {
|
||||||
isTools = true
|
isTools = true
|
||||||
if call := getToolCall(&part); call != nil {
|
if call := getToolCall(&part); call != nil {
|
||||||
|
call.SetIndex(len(choice.Delta.ToolCalls))
|
||||||
choice.Delta.ToolCalls = append(choice.Delta.ToolCalls, *call)
|
choice.Delta.ToolCalls = append(choice.Delta.ToolCalls, *call)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user