google-gemini / generative-ai-dart

The official Dart library for the Google Gemini API
https://ai.google.dev/gemini-api/docs/get-started/tutorial?lang=dart
Apache License 2.0
540 stars 110 forks source link

Is it possible to add mandatory JSON format response #128

Closed xeno-sama closed 3 months ago

xeno-sama commented 4 months ago

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 ?

natebosch commented 4 months ago

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 commented 3 months ago

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