client
client copied to clipboard
Add responseMimeType and responseSchema to GenerationConfig
This allows structured output usage.
$client = new Client($key);
$clent = $client->withV1BetaVersion()->generativeModel('gemini-2.0-flash');
$config = (new GenerationConfig())
->withResponseMimeType(MimeType::APPLICATION_JSON)
->withResponseSchema([
'type' => 'string',
'enum' => [
'hotdog',
'fries',
'coke'
]
]);
$client->withGenerationConfig($config)->generateContent('....');
This PR is essential to use a structured response schema. It avoids having to give them in the prompt.
It follows the implementation of Google's API documentation : https://ai.google.dev/gemini-api/docs/structured-output?lang=rest
I find the addition very relevant!
Just passing by, but I really need this feature!
Looks solid—follows Google’s API docs and improves predictability. No conflicts either, so hoping this gets merged soon!