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

'json_object' is not of type 'object' - 'response_format' #265

Closed simohammedhttp closed 10 months ago

simohammedhttp commented 10 months ago

Hi,

I used this script:

$response = $client->chat()->create([
    'model' => 'gpt-3.5-turbo-1106',
    'max_tokens' => 6,
    'temperature' => 0.2,
    'response_format' => 'json_object',
    'messages' => [
        ['role' => 'user', 'content' => $prompt],
    ],
]);

I got the error: Uncaught OpenAI\Exceptions\ErrorException: 'json_object' is not of type 'object' - 'response_format' in c:\xampp\htdocs\OpenAI\vendor\openai-php\client\src\Transporters\HttpTransporter.php:131

What is the proper way to use response_format and is it even supported by the library?

Thanks.

gehrisandro commented 10 months ago

Hi @simohammedhttp

This error is thrown by the API because your request in wrong. It should be 'response_format' => ['type' => 'json_object'],