client icon indicating copy to clipboard operation
client copied to clipboard

feat: allow JSON mode

Open jnlin opened this issue 1 year ago • 1 comments

Resolve google-gemini-php/client#8

Use v1beta as default base URL to support the feature

jnlin avatar Jul 19 '24 07:07 jnlin

With models/gemini-pro, API returns Json mode is not enabled for models/gemini-pro Working on models/gemini-1.5-pro

Maybe add an example of use to use in ReadMe:

        $generationConfig = new GenerationConfig(
            1,
            [],
            null,
            null,
            null,
            null,
            'application/json',
            [
                'type' => 'array',
                'items' => [
                    'type' => 'object',
                    'properties' => [
                        'product_name' => [
                            'type' => 'string'
                        ]
                    ]
                ]
             ],

        );

        $generativeModel = $client
            ->generativeModel('models/gemini-1.5-pro')
            ->withGenerationConfig($generationConfig)
            ->generateContent("Give me 5 names for my product, it's a bottle of tea"); 

Output :

[
  {
    "product_name": "SereniTea"
  },
  {
    "product_name": "Tea'light"
  },
  {
    "product_name": "The Daily Brew"
  },
  {
    "product_name": "Zen Leaves"
  },
  {
    "product_name": "Bottled Bliss"
  }
]

camilleislasse avatar Aug 07 '24 19:08 camilleislasse

This PR will make the library completely dependent on the beta. A separate branch can be created for beta and proceed from there. I am therefore closing this PR.

aydinfatih avatar Sep 28 '24 11:09 aydinfatih

Hi @jnlin @camilleislasse 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

aydinfatih avatar Sep 28 '24 19:09 aydinfatih