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

TypeError when constructing OpenAI response choice object with null finish reason. #50

Closed
ManukMinasyan opened this issue Feb 25, 2023 · 5 comments

Comments

@ManukMinasyan
Copy link
Contributor

ManukMinasyan commented Feb 25, 2023

TypeError: OpenAI\Responses\Completions\CreateResponseChoice::__construct(): Argument #4 ($finishReason) must be of type string, null given, called in /vendor/openai-php/client/src/Responses/Completions/CreateResponseChoice.php](*/vendor/openai-php/client/src/Responses/Completions/CreateResponseChoice.php) on line 26
  File "/app/Actions/Document/CreateNewContent.php", line 64, in App\Actions\Document\CreateNewContent::complete
    $result = OpenAI::completions()->create($parameters);
  File "/app/Actions/Document/CreateNewContent.php", line 39, in App\Actions\Document\CreateNewContent::App\Actions\Document\{closure}
    return $this->complete($template, $document, $data);
  File "/app/Actions/Document/CreateNewContent.php", line 42, in App\Actions\Document\CreateNewContent::create
    });
  File "/app/Http/Controllers/App/DocumentController.php", line 182, in App\Http\Controllers\App\DocumentController::writeForMe
    $choices = $contentCreator->create($template, $document, $data);
  File "/public/index.php", line 52
    $request = Request::capture()
...
(77 additional frame(s) were not displayed)
@ManukMinasyan ManukMinasyan changed the title TypeError: OpenAI\Responses\Completions\CreateResponseChoice::__construct(): Argument #4 ($finishReason) must be of type string, null given TypeError when constructing OpenAI response choice object with null finish reason. Feb 25, 2023
@numairawan
Copy link

Getting the same error. Any solution?

@careybaird
Copy link
Contributor

Started seeing this also. Seems to be a recent breaking change in the OpenAI API.

The documentation doesn't say much about valid values for finish_reason, so I suggest we should treat it as potentially null.

I can do a PR maybe later today, will check in here in a few hours.

@careybaird
Copy link
Contributor

Pull request made: #52

@careybaird
Copy link
Contributor

careybaird commented Feb 28, 2023

If anyone else wants to apply this fix without waiting for the new release (and you're using composer), change the package in your composer file like this and run composer update

"openai-php/client": "dev-main as 0.3.1",

Note that we are aliasing it as 0.3.1 so it will still work with other packages that use it as a dependency (e.g. openai-php/laravel)

(remember to change it back when a proper version is released!)

@nunomaduro
Copy link
Contributor

Fixed on v0.3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants