Fixed the problem of arguments not being stringified.
Fix panic: candidate.Content.Parts out of range
This commit is contained in:
parent
78cbbd9ac8
commit
1588716e05
@ -172,11 +172,16 @@ func getToolCalls(candidate *ChatCandidate) []model.Tool {
|
|||||||
if item.FunctionCall == nil {
|
if item.FunctionCall == nil {
|
||||||
return toolCalls
|
return toolCalls
|
||||||
}
|
}
|
||||||
|
argsBytes, err := json.Marshal(item.FunctionCall.Arguments)
|
||||||
|
if err != nil {
|
||||||
|
logger.FatalLog("getToolCalls failed: " + err.Error())
|
||||||
|
return toolCalls
|
||||||
|
}
|
||||||
toolCall := model.Tool{
|
toolCall := model.Tool{
|
||||||
Id: fmt.Sprintf("call_%s", random.GetUUID()),
|
Id: fmt.Sprintf("call_%s", random.GetUUID()),
|
||||||
Type: "function",
|
Type: "function",
|
||||||
Function: model.Function{
|
Function: model.Function{
|
||||||
Arguments: item.FunctionCall.Arguments,
|
Arguments: string(argsBytes),
|
||||||
Name: item.FunctionCall.FunctionName,
|
Name: item.FunctionCall.FunctionName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -199,11 +204,15 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse {
|
|||||||
},
|
},
|
||||||
FinishReason: constant.StopFinishReason,
|
FinishReason: constant.StopFinishReason,
|
||||||
}
|
}
|
||||||
if candidate.Content.Parts[i].FunctionCall != nil {
|
if len(candidate.Content.Parts) > 0 {
|
||||||
|
if candidate.Content.Parts[0].FunctionCall != nil {
|
||||||
choice.Message.ToolCalls = getToolCalls(&candidate)
|
choice.Message.ToolCalls = getToolCalls(&candidate)
|
||||||
} else if len(candidate.Content.Parts) > 0 {
|
} else {
|
||||||
choice.Message.Content = candidate.Content.Parts[i].Text
|
choice.Message.Content = candidate.Content.Parts[0].Text
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
choice.Message.Content = ""
|
||||||
|
choice.FinishReason = candidate.FinishReason
|
||||||
}
|
}
|
||||||
fullTextResponse.Choices = append(fullTextResponse.Choices, choice)
|
fullTextResponse.Choices = append(fullTextResponse.Choices, choice)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user