cookbook icon indicating copy to clipboard operation
cookbook copied to clipboard

Returning a Fixed Json

Open Praj-17 opened this issue 1 year ago • 1 comments
trafficstars

Hi I am working on audio understanding and would like the script return me the output in a fixed output format. Something like this

{
    "name": "set_output_json_format",
    "parameters": {
        "type": "object",
        "properties": {
            "count": {
                "type": "string",
                "description": "Represents the number of times the user has chanted correctly"
            },
            "mantra": {
                "type": "string",
                "description": "Represents the mantra chanted"
            }
        }
    }
}

How can I do it in the Audio Script?

Praj-17 avatar Apr 12 '24 16:04 Praj-17

Hi, please see this tutorial:

https://ai.google.dev/tutorials/structured_data_extraction

We are working on adding a "json_schema" to the API in the next release, that will make this simpler.

MarkDaoust avatar Apr 17 '24 18:04 MarkDaoust

The API supports this now. Check out the JSON mode recipe: https://github.com/google-gemini/cookbook/blob/main/quickstarts/JSON_mode.ipynb

markmcd avatar Aug 27 '24 23:08 markmcd