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]: Error handling for RetrieveJobResponse::from() #336

Open marcocanestrari opened 4 months ago

marcocanestrari commented 4 months ago

Description

On line 70 in /Responses/FineTuning/RetriveJobResponse.php $attributes['error'] is checked assuming it's empty if there are no errors. If there are errors, RetrieveJobResponseError::from($attributes['error'])is added to the array.

isset($attributes['error']) ? RetrieveJobResponseError::from($attributes['error']) : 'null',

Apparently, OpenAI has changed the response to

[error] => Array
        (
            [error] => 
        )

The line should be updated to

isset($attributes['error']['error']) ? RetrieveJobResponseError::from($attributes['error']['error']) : 'null',

I'd do it myself and push a PR but I'm new with OpenAI APIs, and since this started yesterday after an outage, it could only be a bug from their ends that will get fixed soon.

What do you all think?

Steps To Reproduce

Call $client->fineTuning()->listJobs();

An error should get thrown:

Fatal error: Uncaught Error: OpenAI\Responses\FineTuning\RetrieveJobResponseError::__construct(): Argument #1 ($code) must be of type string, null given, called in

OpenAI PHP Client Version

v0.8.4

PHP Version

8.3.0

Notes

No response

axelbecher commented 4 months ago

It appears to me, OpenAI currently returns


[error] => Array
        (
            [error] => 
        )

When everything worked fine and a real error still looks like

[error] => Array
        (
            [code] => '12345'
            [message] => 'Bla'
            ...
        )