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

Undefined array key "safetyRatings" #7

Closed
koossaayy opened this issue Apr 14, 2024 · 2 comments
Closed

Undefined array key "safetyRatings" #7

koossaayy opened this issue Apr 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@koossaayy
Copy link

koossaayy commented Apr 14, 2024

Hello,
Running the following code

    $chat = Gemini::chat()
        ->startChat(history: [
            Content::parse(part: "You have the following transcript.  Hello, guys. Today,....", role: Role::USER),
            Content::parse(part: 'I understand', role: Role::MODEL),
            Content::parse(part: "Summarize it", role: Role::USER),
            Content::parse(part: 'In this video, the speaker discusses three ways to return JSON from API controllers or routes in Laravel: 1. **Directly returning an Eloquent collection or model:** Laravel will automatically convert this to JSON. 2.....', role: Role::MODEL),
            Content::parse(part: "What is the best way to send api data ? according to the transcript", role: Role::USER),
            Content::parse(part: 'According to the transcript, the best way to send API data is to use Eloquent API resources....', role: Role::MODEL),
            Content::parse(part: 'Thank You', role: Role::USER),
            Content::parse(part: 'You\'re welcome! I\'m glad I could be of assistance.', role: Role::MODEL),

        ]);

    $response = $chat->sendMessage('Show me an example for that ');
    echo $response->text();

Will return the mentioned error.
Here is the full error stack : https://flareapp.io/share/xmN9W6p5

Update:
Commenting the last entries in the history, won't trigger that error. I guess that's something I am doing on my end, with the prompts. I will try more, and see.

    $chat = Gemini::chat()
        ->startChat(history: [
            Content::parse(part: "You have the following transcript.  Hello, guys....", role: Role::USER),
            Content::parse(part: 'I understand', role: Role::MODEL),
            Content::parse(part: "Summarize it", role: Role::USER),
            Content::parse(part: 'In this video, the speaker discusses three ways to return JSON from API controllers or routes in Laravel: 1. **Directly returning an Eloquent collection or model:*....', role: Role::MODEL),
            Content::parse(part: "What is the best way to send api data ? according to the transcript", role: Role::USER),
            Content::parse(part: 'According to the transcript, the best way to send API data is to use Eloquent API resources. ....', role: Role::MODEL),
            // Content::parse(part: 'Thank You', role: Role::USER),
            // Content::parse(part: 'You\'re welcome! I\'m glad I could be of assistance.', role: Role::MODEL),

        ]);

    $response = $chat->sendMessage('Thank you ');
    echo $response->text();
@aydinfatih
Copy link
Contributor

Hello @koossaayy,
Thanks for your feedback.
I was able to reproduce the problem locally. As far as I understand, it seems to be a general problem with gemini ai. Gemini returns the following response in some requests other than the normal api response. I am continuing to investigate the problem and will let you know when I find the most appropriate solution.

{ 
    "finishReason":  "RECITATION",
    "index" :  0,
} 

google/generative-ai-docs#257

@aydinfatih aydinfatih added the bug Something isn't working label Apr 16, 2024
@aydinfatih
Copy link
Contributor

aydinfatih commented Apr 23, 2024

Hello @koossaayy
We have a new fix for this issue. Can you try again after composer update?
https://github.com/google-gemini-php/client/releases/tag/1.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants