client icon indicating copy to clipboard operation
client copied to clipboard

Add responseMimeType and responseSchema to GenerationConfig

Open evandromurilo opened this issue 11 months ago • 2 comments

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('....');

evandromurilo avatar Feb 08 '25 18:02 evandromurilo

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!

AstritA avatar Mar 08 '25 15:03 AstritA

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!

edmer664 avatar May 03 '25 07:05 edmer664