diff --git a/relay/adaptor/gemini/main.go b/relay/adaptor/gemini/main.go index e006c594..8b934d30 100644 --- a/relay/adaptor/gemini/main.go +++ b/relay/adaptor/gemini/main.go @@ -172,11 +172,16 @@ func getToolCalls(candidate *ChatCandidate) []model.Tool { if item.FunctionCall == nil { return toolCalls } + argsBytes, err := json.Marshal(item.FunctionCall.Arguments) + if err != nil { + logger.FatalLog("getToolCalls failed: " + err.Error()) + return toolCalls + } toolCall := model.Tool{ Id: fmt.Sprintf("call_%s", random.GetUUID()), Type: "function", Function: model.Function{ - Arguments: item.FunctionCall.Arguments, + Arguments: string(argsBytes), Name: item.FunctionCall.FunctionName, }, } @@ -199,11 +204,15 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse { }, FinishReason: constant.StopFinishReason, } - if candidate.Content.Parts[i].FunctionCall != nil { - choice.Message.ToolCalls = getToolCalls(&candidate) - } else if len(candidate.Content.Parts) > 0 { - choice.Message.Content = candidate.Content.Parts[i].Text - + if len(candidate.Content.Parts) > 0 { + if candidate.Content.Parts[0].FunctionCall != nil { + choice.Message.ToolCalls = getToolCalls(&candidate) + } else { + choice.Message.Content = candidate.Content.Parts[0].Text + } + } else { + choice.Message.Content = "" + choice.FinishReason = candidate.FinishReason } fullTextResponse.Choices = append(fullTextResponse.Choices, choice) }