client icon indicating copy to clipboard operation
client copied to clipboard

[Bug]: Undefined array key "code" $client->fineTuning()->listJobs()

Open vestaxpdx opened this issue 2 years ago • 3 comments

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 avatar Feb 10 '24 15:02 vestaxpdx

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.

vestaxpdx avatar Feb 10 '24 15:02 vestaxpdx

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

marcocanestrari avatar Feb 10 '24 17:02 marcocanestrari

I'm facing the same issue, any solution?

adnane-ka avatar Jun 18 '24 19:06 adnane-ka