Add `response_mime_type` support to `generationConfig`
According to google docs here https://ai.google.dev/docs/gemini_api_overview#json
We can instruct Gemini to return json by adding "response_mime_type": "application/json" to generationConfig
I hope this will be added to generationConfig
+1
+1
... and the corresponding responseSchema please
example:
"responseMimeType" => "application/json", "responseSchema" => [ "type" => "ARRAY", "items" => [ "type" => "OBJECT", "properties" => [ "product" => [ "type" => "STRING" ] ] ] ]
PR here, I will test this with a project shortly and update it as needed. Feel free to test for your purposes @Martin-Matchory @Sinitra @DrAliRagab and let me know if it works.
I noticed this library has an open tested PR for mimetype support so I'll close this one.
+1 ... and the corresponding
responseSchemaplease example:
"responseMimeType" => "application/json", "responseSchema" => [ "type" => "ARRAY", "items" => [ "type" => "OBJECT", "properties" => [ "product" => [ "type" => "STRING" ] ] ] ]
Yes, both responseMimeType and responseSchema should be added.
This is a working example using laravel http:
$response = Http::baseUrl($this->baseUrl)
->withHeaders([
'x-goog-api-key' => $this->apiKey,
])
->asJson()
->acceptJson()
->post("v1beta/models/{$this->model}:generateContent", [
'contents' => [
'parts' => [
[
'text' => $instructions,
],
]
],
'generationConfig' => [
'responseMimeType' => 'application/json',
'responseSchema' => [
'type' => 'object',
'properties' => [
'score' => [
'type' => 'number',
'minimum' => 0,
'maximum' => 1,
'format' => 'float',
],
],
'required' => ['score'],
],
],
]);
#65