google-gemini-php / client

⚡️ Gemini PHP is a community-maintained PHP API client that allows you to interact with the Gemini AI API.
MIT License
192 stars 41 forks source link

support new JSON response mode for Gemini 1.5 Pro #19

Closed dmaicher closed 6 months ago

dmaicher commented 6 months ago

Fixes #18

This allows doing

$client
    ->generativeModel('models/gemini-1.5-pro-latest')
    ->withGenerationConfig(new GenerationConfig(responseMimeType: 'application/json'))

and the response will be JSON then.

aydinfatih commented 6 months ago

Hello, First of all, thank you for your feedback. This feature is currently in beta. Including it in the package might be a problem at the moment.

https://github.com/google-gemini-php/client/issues/14

dmaicher commented 6 months ago

Yeah I see. Maybe allowing GenerationConfig|Arrayable might be a solution? being constrained for the allowed config by this lib seems not so ideal. Whenever new config options are available this would require an update/release as we see with this issue.

aydinfatih commented 6 months ago

The package is currently not sending requests to the beta api. Therefore the stable api will not recognize this feature. I plan to create a separate branch for this and other beta features, so that those who want to use beta features can access them through this branch.

https://github.com/google-gemini-php/client/blob/06536196184cb6b29f096e29705a175b7b7350af/src/Factory.php#L33

dmaicher commented 6 months ago

The package is currently not sending requests to the beta api

yeah not by default but its easily possible with

Gemini::factory()->withBaseUrl('https://generativelanguage.googleapis.com/v1beta/')

Thanks for looking into it :+1:

aydinfatih commented 6 months ago

Yes, this is possible, but anyone using the package will need to be aware that this parameter only works in beta. As I said, I'm planning to open a separate branch for the beta to add these features, I'll let you know when that's done.

beliven-daniele-sarnari commented 5 months ago

Hello @aydinfatih do you have any update regarding the beta branch? Thanks

pionl commented 5 months ago

Hi @aydinfatih maybe instead of separate branch BetaGenerationConfig could be provided ?

avengerweb commented 4 months ago

I also think that the decision to exclude beta APIs is like putting the package on the shelf. Most generative AI providers release or mark their first revisions as beta or preview versions. Since this is a relatively new area, most users are really looking to use the latest versions.

aydinfatih commented 1 month ago

Hi @dmaicher @beliven-daniele-sarnari @avengerweb @pionl This feature has been added to the beta version. You can use it by updating the version of the package in composer.json to the version I specified.

https://packagist.org/packages/google-gemini-php/client#1.0.0-beta

You can check the PR https://github.com/google-gemini-php/client/pull/34