Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function calling with a response mime type: 'application/json' is unsupported #195

Closed
skoru01 opened this issue Jul 29, 2024 · 9 comments
Closed
Labels
status:awaiting user response Awaiting a response from the author status:stale Issue/PR will be closed automatically if there's no further activity

Comments

@skoru01
Copy link

skoru01 commented Jul 29, 2024

Description of the bug:

Hi,
i am using Function calling along with generationConfig and then i am getting below error message.

How can we use function calling tools along with GenerationConfig in this SDK, since i want to add temperature, topK and topP to function calling for more accuracy response.

Request:

Screenshot 2024-07-29 at 12 38 26 PM
Response payload: {
  "error": {
    "code": 400,
    "message": "Function calling with a response mime type: 'application/json' is unsupported",
    "status": "INVALID_ARGUMENT"
  }
}

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

@andrewheard
Copy link
Collaborator

Hi @skoru01, this error is specifically for responseMIMEType in GenerationConfig. It's possible to set temperature, topK and topP with function calling, for example:

let generativeModel = GenerativeModel(
  name: "gemini-1.5-flash-latest",
  apiKey: apiKey,
  generationConfig: GenerationConfig(temperature: 0.0, topP: 0.99, topK: 1),
  tools: [Tool(functionDeclarations: [...])]
)

If you'd like to use JSON format responses in some cases, and function calling in others, you could create a separate instance of the model / generation config for the two use cases. Does that answer your question?

@andrewheard andrewheard added the status:awaiting user response Awaiting a response from the author label Jul 29, 2024
@skoru01
Copy link
Author

skoru01 commented Jul 29, 2024

Hi @andrewheard Thanks for the suggestion. i will try it. Is it not possible to use responseMIMEType along with function calling? function calling is giving more accurate options and i want json as well.

i am using gemini-1.5-flash-latest and sometimes i am getting pretty python or json string instead of JSON. Where as gemini-1.5-pro-latest really not giving accurate result as like gemini-1.5-flash-latest

@andrewheard
Copy link
Collaborator

@skoru01 Would it be possible for you to describe your use case of function calling in more detail? Potentially you could add an additional function for your final response and use the function calling mode ANY. This way it would never produce a natural-language/text response. In Swift the setup would look something like:

let model = GenerativeModel(
  ...,
  tools: [Tool(functionDeclarations: [...])],
  toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: .any))
)

@skoru01
Copy link
Author

skoru01 commented Jul 29, 2024

@andrewheard Thanks you, i will check this and get back to you if its not working.

@cabljac
Copy link

cabljac commented Jul 30, 2024

Hi! I'm looking an issue over in genkit and I think it's related/the same problem, but in Node.js. We're setting responseMimeType as 'application/json' and also adding tools in a chat request. Is this not possible then?

@andrewheard

Copy link

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

@github-actions github-actions bot added the status:stale Issue/PR will be closed automatically if there's no further activity label Aug 14, 2024
@skoru01
Copy link
Author

skoru01 commented Aug 16, 2024

@skoru01 Would it be possible for you to describe your use case of function calling in more detail? Potentially you could add an additional function for your final response and use the function calling mode ANY. This way it would never produce a natural-language/text response. In Swift the setup would look something like:

let model = GenerativeModel(
  ...,
  tools: [Tool(functionDeclarations: [...])],
  toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: .any))
)

Hi @andrewheard Sorry for the late response. GenerationConfig working good. but below code causing issue

let model = GenerativeModel(
  ...,
  tools: [Tool(functionDeclarations: [...])],
  toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: .any))
)

Response

{
  "error": {
    "code": 500,
    "message": "An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting",
    "status": "INTERNAL"
  }
}

FYI, if send .auto over FunctionCallingConfig, its working fine.

@github-actions github-actions bot removed the status:stale Issue/PR will be closed automatically if there's no further activity label Aug 17, 2024
Copy link

github-actions bot commented Sep 5, 2024

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

@github-actions github-actions bot added the status:stale Issue/PR will be closed automatically if there's no further activity label Sep 5, 2024
Copy link

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:awaiting user response Awaiting a response from the author status:stale Issue/PR will be closed automatically if there's no further activity
Projects
None yet
Development

No branches or pull requests

3 participants