Closed mr-vijaychauhan closed 3 weeks ago
Hi @mr-vijaychauhan This feature does not work in the stable version. You can update the package version to 1.0.0-beta in Composer.json. Beta features are available in the beta version.
https://github.com/google-gemini-php/laravel/releases/tag/1.0.0-beta
Following the documented example from the release, I cannot see where the classes are coming from being referenced. Do you have namespaces for these other types in the config? Will this work with the startChat() method?
Specifically: ResponseMimeType, Schema, and DataType
@chrisbeaver Yes, you are right, that part is missing. I will add it. I am sharing the file paths here to make it faster.
use Gemini\Data\GenerationConfig;
use Gemini\Data\Schema;
use Gemini\Enums\DataType;
use Gemini\Data\Content;
use Gemini\Enums\HarmBlockThreshold;
use Gemini\Data\SafetySetting;
use Gemini\Enums\HarmCategory;
use Gemini\Data\Blob;
use Gemini\Enums\ModelType;
use Gemini\Enums\ModelVariation;
use Gemini\Enums\ResponseMimeType;
use Gemini\Enums\MimeType;
use Gemini\Enums\Role;
Thanks for the response. It's not working for me however. I noticed that when I update the package to pull in v1.0.0-beta, that package is requiring google-gemini-php/client:^1.0.0-beta but composer is pulling down google-gemini-php/client:1.0.10. So without the beta, I don't think I'm getting the new classes. I don't know if this is my end, I did clear cache though... Or maybe composer pulls the 1.0.10 since it is referenced with the carat as ^1.0.0.
@chrisbeaver yes I faced same issue. I thought I was doing wrong.. thanks for raised this issue
The fix for the versions is easy.
Just manually install :
composer require google-gemini-php/client=v1.0.0-beta
This will downgrade the package that is installed. It will add this line to your requirements in your composer.json. Just go in your composer.json, remove the requirement for google-gemini-php/client=v1.0.0-beta. Clean up your lock file then with:
composer update nothing
Now you're locked on both packages at v1.0.0-beta, and the classes are available. Now I just need to figure out how to get it to work with chat.
@chrisbeaver okk thanks ! I will try later
Thanks @chrisbeaver its working now
$response = Gemini::generativeModel($model)
->withGenerationConfig(
generationConfig: new GenerationConfig(
responseMimeType: ResponseMimeType::APPLICATION_JSON,
)
)
->generateContent($prompt)
->json();
dd($response);
Currently, the API response I am receiving is in a text format that resembles JSON but includes newline characters (\n) and other formatting issues that make it difficult to parse as structured data.
Official Doc (aistudio.google.com)