Skip to content
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

Add response_mime_type support to generationConfig #31

Open
DrAliRagab opened this issue Apr 9, 2024 · 5 comments
Open

Add response_mime_type support to generationConfig #31

DrAliRagab opened this issue Apr 9, 2024 · 5 comments

Comments

@DrAliRagab
Copy link

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

@Sinitra
Copy link

Sinitra commented May 10, 2024

+1

@Martin-Matchory
Copy link

+1
... and the corresponding responseSchema please
example:

"responseMimeType" => "application/json", "responseSchema" => [ "type" => "ARRAY", "items" => [ "type" => "OBJECT", "properties" => [ "product" => [ "type" => "STRING" ] ] ] ]

@benbowler
Copy link

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.

@benbowler
Copy link

I noticed this library has an open tested PR for mimetype support so I'll close this one.

@DrAliRagab
Copy link
Author

+1 ... and the corresponding responseSchema please 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'],
        ],
    ],
]);

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

No branches or pull requests

4 participants