openai-php / client

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

Error when listing available models #246

Closed simohammedhttp closed 11 months ago

simohammedhttp commented 11 months ago

Hi,

I tried this code in the docs:

$response = $client->models()->list();
$response->object;
foreach ($response->data as $result) {
    $result->id;
    $result->object;
}
$response->toArray();

I got this error:

Warning: Undefined array key "permission" in C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\RetrieveResponse.php on line 51

Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given in C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\RetrieveResponse.php:49 Stack trace: #0 C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\RetrieveResponse.php(49): array_map(Object(Closure), NULL) #1 C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\ListResponse.php(44): OpenAI\Responses\Models\RetrieveResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation)) #2 [internal function]: OpenAI\Responses\Models\ListResponse::OpenAI\Responses\Models{closure}(Array) #3 C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\ListResponse.php(44): array_map(Object(Closure), Array) #4 C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Resources\Models.php(30): OpenAI\Responses\Models\ListResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation)) #5 C:\xampp\htdocs\myproject\openai-test.php(37): OpenAI\Resources\Models->list() #6 {main} thrown in C:\xampp\htdocs\myproject\OpenAI\vendor\openai-php\client\src\Responses\Models\RetrieveResponse.php on line 49

gehrisandro commented 11 months ago

Hi @simohammedhttp

You are using an old version of the client. This issue has already been fixed.