google gemini_response is string I need in the JSON Structure like this
{
"Title": "chair",
"Description": "A wooden chair with wheels",
"Category": "Furniture",
"Subcategory": "office stuff",
"EstimatedPrice": "$10 – 20 "
}
I try the json_laod() to desearlize but my reponse is not like JSON! How can i do this into a proper JSON ?
2
Answers
JSON Mode has recently been introduced in the Gemini API for the
Gemini 1.5 Pro
andGemini 1.5 Flash
models (sadly not available in the Gemini 1.0 Pro Vision model that you’re using).But both models support image input, just like the pro vision model, as documented here.
Using the Gemini 1.5 Flash model
This model is somewhat limited when it comes to schema – you have to pass it as part of your prompt, for example:
Using the Gemini 1.5 Pro model
If you’re using the Gemini 1.5 Pro model, You can create a Python class to serve as schema and pass it as
response_schema
:Which model should I use ?
I think that depends on what you’re looking for. The differences between the models are listed in the docs and they also come at different prices.
Looks like it’s returning JSON by default? https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini#response
However, see
JSON format responses
Basically add this to a HTTP POST body to get JSON: