Skip to content

How to get finishReason value #68

@GeekTNT

Description

@GeekTNT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions