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]: Undefined array key "code" $client->fineTuning()->listJobs() #337

Open vestaxpdx opened 4 months ago

vestaxpdx commented 4 months ago

Description

I am suddenly getting: Undefined array key "code" when calling $client->fineTuning()->listJobs()

I guess openai have changed something?

Issue seems to be here: openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php

 /**
     * Acts as static factory, and returns a new Response instance.
     *
     * @param  array{code: string, param: ?string, message: string}  $attributes
     */
    public static function from(array $attributes): ?self
    {
        return new self(
            $attributes['code'],
            $attributes['param'],
            $attributes['message'],
        );
    }

Steps To Reproduce

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

OpenAI PHP Client Version

v0.8.4

PHP Version

8.2

Notes

Potentially related issue: https://github.com/openai-php/client/issues/336

vestaxpdx commented 4 months ago

Form some quick debugging it seems $attributes only contains $attributes['error'] which = null.

The only way I could quickly hot fix to get my project working again was by adding null coalescing operators, which is a dirty fix I know...

return new self(
            $attributes['code'] ?? '',
            $attributes['param'] ?? '',
            $attributes['message'] ?? '',
        );

Then my finetune jobs load again as normal.

marcocanestrari commented 4 months ago

Hey, yes, it's related: the ticket explores the reason of that error and a possible fix: https://github.com/openai-php/client/issues/336

adnane-ka commented 2 weeks ago

I'm facing the same issue, any solution?