Skip to content

Add responseMimeType and responseSchema to GenerationConfig #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

evandromurilo
Copy link

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

@AstritA
Copy link
Contributor

AstritA commented Mar 8, 2025

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!

@edmer664
Copy link

edmer664 commented May 3, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants