Error when providing a function call results back to Gemini

Hello,

I’m getting the “Request contains an invalid argument.” error when posting those results back to Gemini. Any ideas whats wrong? This is OpenAI style request that works fine for both OpenAI and xAI and it looks valid when asked Gemini in the chat.

{
“model”:“gemini-1.5-flash”,
“messages”:[
{
“content”:“what’s the weather in Stamford, ct”,
“role”:“user”
},
{
“name”:“get_current_weather”,
“role”:“function”,
“content”:“{"description":"Mostly cloudy","temperature":"5","unit":""}”
}
],
“tools”:[
{
“type”:“function”,
“function”:{
“name”:“get_current_weather”,
“parameters”:{
“type”:“object”,
“properties”:{
“location”:{
“type”:“string”,
“description”:“The city and state, e.g. San Francisco, CA”
},
“unit”:{
“type”:“string”,
“enum”:[
“celsius”,
“fahrenheit”
]
}
},
“required”:[
“location”
]
},
“description”:“Get the current weather in a given location”
}
}
]
}

1 Like

Welcome to the forum.

The payload isn’t valid json. The quotes are smart quotes, that might have happened because the text was processed by a word processor that decided they look better if they are not just this character “. Anyway, after replacing the quotes with the valid character(”), the payload is still not valid json: the problem is with this line

"content":"{'description':'Mostly cloudy','temperature':'5','unit':''}"

where, if the ’ in front of “description” is changed to the " it was in your payload, the string terminates right after the { and the “description” is left naked (unquoted).

With these changes, you might have success, I did not test whether the model will take that response. One more thing: it helps us if, when posting code or a json message, you use three backticks at the start and end to “fence” that code or json.

Hope that helps

1 Like

Hello,

Thank you very much for a prompt response. I suppose those smart quotes appeared somehow during formatting. Original unformatted request is just fine. Please see it below. Those requests are good for both OpenAI and xAI…

{
  "model" : "gemini-1.5-flash",
  "messages" : [{"content":"what’s the weather in Stamford, ct","role":"user"},{"name":"get_current_weather","role":"function","content":"{\"description\":\"Clear skies\",\"temperature\":\"1\",\"unit\":\"\"}"}],
  "tools":[{"type":"function","function":{"name":"get_current_weather","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]},"description":"Get the current weather in a given location"}}]
  	
}
1 Like