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

[Bug]: Warning: Undefined array key "code" in Responses/FineTuning/RetrieveJobResponseError.php on line 42 #362

Open
alek-s-andr opened this issue Mar 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@alek-s-andr
Copy link

Description

A am getting the error when run any method on the $openAIClient->fineTuning() endpoint, for example $openAIClient->fineTuning()->createJob($params);.
This run leads to fatal error:
PHP Fatal error: Uncaught TypeError: OpenAI\Responses\FineTuning\RetrieveJobResponseError::__construct(): Argument #1 ($code) must be of type string, null given, called in vendor/openai-php/client/src/Responses/FineTuning/RetrieveJobResponseError.php on line 37 and defined in vendor/openai-php/client/src/Responses/FineTuning/RetrieveJobResponseError.php:20

2024-03-29-13-14-15

Steps To Reproduce

Run $openAIClient->fineTuning()->retrieveJob('ftjob-...');

OpenAI PHP Client Version

v0.8.4

PHP Version

8.1.27

Notes

https://platform.openai.com/docs/api-reference/fine-tuning/object
I did a little research and found out that the returned fine-tuning job object from OpenAI API actually contains the parameter error which contains other object with key error (but this is not mentioned in the OpenAI documentation) in the absence of an error:

2024-03-29-12-44-08

@alek-s-andr alek-s-andr added the bug Something isn't working label Mar 29, 2024
alek-s-andr added a commit to alek-s-andr/openai-php-client that referenced this issue Mar 29, 2024
@alek-s-andr
Copy link
Author

I created a PR with a fix for this issue: #363

@BrainPackIO
Copy link

BrainPackIO commented Apr 2, 2024

Here is how you can create a completely new install that recreates this error. I have also included the fix

php -v

PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies

composer require openai-php/client

composer dump-autoload    

nano index.php

Paste this:

<?php
require __DIR__ . '/vendor/autoload.php';

$client = OpenAI::client('insert-your-key-here');

$response = $client->fineTuning()->listJobs();
?>

php index.php

Error Response:

PHP Warning: Undefined array key "code" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 35

Warning: Undefined array key "code" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 35
PHP Warning: Undefined array key "param" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 36

Warning: Undefined array key "param" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 36
PHP Warning: Undefined array key "message" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 37

Warning: Undefined array key "message" in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 37
PHP Fatal error: Uncaught TypeError: OpenAI\Responses\FineTuning\RetrieveJobResponseError::__construct(): Argument #1 ($code) must be of type string, null given, called in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 34 and defined in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php:20
Stack trace:
#0 vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php(34): OpenAI\Responses\FineTuning\RetrieveJobResponseError->__construct(NULL, NULL, NULL)
#1 vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponse.php(70): OpenAI\Responses\FineTuning\RetrieveJobResponseError::from(Array)
#2 vendor\openai-php\client\src\Responses\FineTuning\ListJobsResponse.php(45): OpenAI\Responses\FineTuning\RetrieveJobResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation))
#3 [internal function]: OpenAI\Responses\FineTuning\ListJobsResponse::OpenAI\Responses\FineTuning{closure}(Array)
#4 vendor\openai-php\client\src\Responses\FineTuning\ListJobsResponse.php(45): array_map(Object(Closure), Array)
#5 vendor\openai-php\client\src\Resources\FineTuning.php(51): OpenAI\Responses\FineTuning\ListJobsResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation))
#6 index.php(6): OpenAI\Resources\FineTuning->listJobs()
#7 {main}
thrown in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 20

Fatal error: Uncaught TypeError: OpenAI\Responses\FineTuning\RetrieveJobResponseError::__construct(): Argument #1 ($code) must be of type string, null given, called in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 34 and defined in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php:20
Stack trace:
#0 vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php(34): OpenAI\Responses\FineTuning\RetrieveJobResponseError->__construct(NULL, NULL, NULL)
#1 vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponse.php(70): OpenAI\Responses\FineTuning\RetrieveJobResponseError::from(Array)
#2 vendor\openai-php\client\src\Responses\FineTuning\ListJobsResponse.php(45): OpenAI\Responses\FineTuning\RetrieveJobResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation))
#3 [internal function]: OpenAI\Responses\FineTuning\ListJobsResponse::OpenAI\Responses\FineTuning{closure}(Array)
#4 vendor\openai-php\client\src\Responses\FineTuning\ListJobsResponse.php(45): array_map(Object(Closure), Array)
#5 vendor\openai-php\client\src\Resources\FineTuning.php(51): OpenAI\Responses\FineTuning\ListJobsResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation))
#6 index.php(6): OpenAI\Resources\FineTuning->listJobs()
#7 {main}
thrown in vendor\openai-php\client\src\Responses\FineTuning\RetrieveJobResponseError.php on line 20

Fix:

Inside file src\Responses\FineTuning\RetrieveJobResponseError.php

Change:

private function __construct(
    public readonly string $code,
    public readonly ?string $param,
    public readonly string $message,
) {
}

To:

private function __construct(
    public readonly ?string $code,
    public readonly ?string $param,
    public readonly ?string $message,
) {
}

Change:

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

To:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants