mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-05-04 11:09:02 +00:00
fix: issue where consecutive calls to multiple tools in gemini all returned an index of 0
This commit is contained in:
@@ -1141,6 +1141,8 @@ func GeminiChatStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *
|
|||||||
id := helper.GetResponseID(c)
|
id := helper.GetResponseID(c)
|
||||||
createAt := common.GetTimestamp()
|
createAt := common.GetTimestamp()
|
||||||
finishReason := constant.FinishReasonStop
|
finishReason := constant.FinishReasonStop
|
||||||
|
toolCallIndexByChoice := make(map[int]map[string]int)
|
||||||
|
nextToolCallIndexByChoice := make(map[int]int)
|
||||||
|
|
||||||
usage, err := geminiStreamHandler(c, info, resp, func(data string, geminiResponse *dto.GeminiChatResponse) bool {
|
usage, err := geminiStreamHandler(c, info, resp, func(data string, geminiResponse *dto.GeminiChatResponse) bool {
|
||||||
response, isStop := streamResponseGeminiChat2OpenAI(geminiResponse)
|
response, isStop := streamResponseGeminiChat2OpenAI(geminiResponse)
|
||||||
@@ -1148,6 +1150,28 @@ func GeminiChatStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *
|
|||||||
response.Id = id
|
response.Id = id
|
||||||
response.Created = createAt
|
response.Created = createAt
|
||||||
response.Model = info.UpstreamModelName
|
response.Model = info.UpstreamModelName
|
||||||
|
for choiceIdx := range response.Choices {
|
||||||
|
choiceKey := response.Choices[choiceIdx].Index
|
||||||
|
for toolIdx := range response.Choices[choiceIdx].Delta.ToolCalls {
|
||||||
|
tool := &response.Choices[choiceIdx].Delta.ToolCalls[toolIdx]
|
||||||
|
if tool.ID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m := toolCallIndexByChoice[choiceKey]
|
||||||
|
if m == nil {
|
||||||
|
m = make(map[string]int)
|
||||||
|
toolCallIndexByChoice[choiceKey] = m
|
||||||
|
}
|
||||||
|
if idx, ok := m[tool.ID]; ok {
|
||||||
|
tool.SetIndex(idx)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
idx := nextToolCallIndexByChoice[choiceKey]
|
||||||
|
nextToolCallIndexByChoice[choiceKey] = idx + 1
|
||||||
|
m[tool.ID] = idx
|
||||||
|
tool.SetIndex(idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.LogDebug(c, fmt.Sprintf("info.SendResponseCount = %d", info.SendResponseCount))
|
logger.LogDebug(c, fmt.Sprintf("info.SendResponseCount = %d", info.SendResponseCount))
|
||||||
if info.SendResponseCount == 0 {
|
if info.SendResponseCount == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user