generative-ai-dart icon indicating copy to clipboard operation
generative-ai-dart copied to clipboard

Is it possible to add mandatory JSON format response

Open xeno-sama opened this issue 10 months ago • 1 comments

i see in google docs an example for CURL

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$API_KEY
-H 'Content-Type: application/json'
-X POST
-d '{ "contents":[{ "parts":[{"text": "List 5 popular cookie recipes using this JSON schema: { "type": "object", "properties": { "recipe_name": { "type": "string" },}}"}] }], "generationConfig": { "response_mime_type": "application/json", } }'

so is it possible to add "response_mime_type": "application/json", to generationConfig ?

xeno-sama avatar Apr 22 '24 07:04 xeno-sama

The current way to enforce JSON format response is to use function calling. The 0.3.1 release supports the tool config argument which can force the model to reply with a function call, and the function call can specify the JSON schema for the argument.

Support for JSON schemas without function calling is under consideration.

natebosch avatar Apr 23 '24 23:04 natebosch

The mimeType field is supported. Handled by https://github.com/google-gemini/generative-ai-dart/pull/156

natebosch avatar May 22 '24 15:05 natebosch