client icon indicating copy to clipboard operation
client copied to clipboard

How to get finishReason value

Open nemhal opened this issue 9 months ago • 1 comments

Hello,

I'm using

$input  = "Do something";
$client->geminiFlash()->generateContent($input);

And sometimes it fails with the following output (finishReason RECITATION):

It happens for eg. when I want to translate a text, that's copyrighted.

object(Gemini\Responses\GenerativeModel\GenerateContentResponse)#30 (3) {
  ["candidates"]=>
  array(1) {
    [0]=>
    object(Gemini\Data\Candidate)#25 (7) {
      ["content"]=>
      object(Gemini\Data\Content)#16 (2) {
        ["parts"]=>
        array(0) {
        }
        ["role"]=>
        enum(Gemini\Enums\Role::MODEL)
      }
      ["finishReason"]=>
      enum(Gemini\Enums\FinishReason::RECITATION)
      ["safetyRatings"]=>
      array(0) {
      }
      ["citationMetadata"]=>
      object(Gemini\Data\CitationMetadata)#31 (1) {
        ["citationSources"]=>
        array(4) {
...

More on the finishReason respones https://cloud.google.com/vertex-ai/generative-ai/docs/reference/python/latest/vertexai.generative_models.FinishReason

Is there a way to check the finishReason value. Or even better, can you make it so if the finishReason is not STOP to return the exception.

I can provide the content I used for the testing if needed.

Thank you.

nemhal avatar Mar 22 '25 19:03 nemhal

Hey @nemhal, we just tagged a new 2.0 version which implements all that gemini has to offer right now. Could you give it a try and see if you get what you expect?

You can find more information in upgrade guide

To update you can run:

composer require google-gemini-php/client:^2.0

Plytas avatar May 09 '25 14:05 Plytas

@nemhal I'm closing this issue due to inactivity. If you still need help with this, feel free to re-open.

Plytas avatar May 30 '25 08:05 Plytas