openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.56k stars 466 forks source link

[Bug]: getErrorCode(): Return value must be of type ?string, int returned #352

Closed matiaslauriti closed 3 months ago

matiaslauriti commented 3 months ago

Description

We are getting a Syntax Error back (getMessage()) and it is reporting an error code (getErrorCode()) = 0... That makes PHP throw a fatal exception as the method has a return type of ?string, but it is an int.

The issue is that you are using declare(strict_types=1) (it never helps at all), because 0 can be converted to a string automatically by PHP...

Related issue: https://github.com/openai-php/client/issues/151

The related file causing problems is: src/Exceptions/ErrorException.php

Steps To Reproduce

I do not have the input that was sent, but we are using: OpenAI::chat()->create($parameters);

OpenAI PHP Client Version

v0.6.2 (laravel pacakge v0.6.0)

PHP Version

8.1.22

Notes

No response

matiaslauriti commented 3 months ago

I just found out that the package we are using is old, and it was "fixed" on newer versions