Commit f24e2b0d by RedwindA

Fix: Correctly relay FunctionResponse content for Gemini API

parent 508188ca
...@@ -27,14 +27,14 @@ type FunctionCall struct { ...@@ -27,14 +27,14 @@ type FunctionCall struct {
Arguments any `json:"args"` Arguments any `json:"args"`
} }
type GeminiFunctionResponseContent struct { // type GeminiFunctionResponseContent struct {
Name string `json:"name"` // Name string `json:"name"`
Content any `json:"content"` // Content any `json:"content"`
} // }
type FunctionResponse struct { type FunctionResponse struct {
Name string `json:"name"` Name string `json:"name"`
Response GeminiFunctionResponseContent `json:"response"` Response map[string]interface{} `json:"response"`
} }
type GeminiPartExecutableCode struct { type GeminiPartExecutableCode struct {
......
...@@ -173,17 +173,22 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest, info *relaycommon ...@@ -173,17 +173,22 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest, info *relaycommon
} else if val, exists := tool_call_ids[message.ToolCallId]; exists { } else if val, exists := tool_call_ids[message.ToolCallId]; exists {
name = val name = val
} }
content := common.StrToMap(message.StringContent()) contentMap := common.StrToMap(message.StringContent())
functionResp := &FunctionResponse{ functionResp := &FunctionResponse{
Name: name, Name: name,
Response: GeminiFunctionResponseContent{ Response: contentMap,
Name: name, }
Content: content, // If StrToMap returns nil because message.StringContent() is not a valid JSON object string,
}, // and Gemini strictly requires an object (e.g., {}), this might need adjustment.
} // For example:
if content == nil { // if contentMap == nil && message.StringContent() != "" {
functionResp.Response.Content = message.StringContent() // // Option 1: Send an empty object if that's preferred over null
} // // functionResp.Response = make(map[string]interface{})
// // Option 2: Wrap the plain string if that's ever the case and needs to be an object
// // functionResp.Response = map[string]interface{}{"text_content": message.StringContent()}
// }
// For now, directly assigning contentMap is the most straightforward fix for the reported issue.
*parts = append(*parts, GeminiPart{ *parts = append(*parts, GeminiPart{
FunctionResponse: functionResp, FunctionResponse: functionResp,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment