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]: Uncaught JsonException #339

Open sera1t opened 4 months ago

sera1t commented 4 months ago

Description

Hello, I installed the library, everything is fine, but for some reason, when I try to make a request, it gives me this error in the console.

[Mon Feb 19 12:51:13 2024] 127.0.0.1:53566 [500]: GET /chat/tet.php - Uncaught JsonException: Syntax error in /var/www/chatbot/vendor/openai-php/client/src/Transporters/HttpTransporter.php:61 Stack trace:

0 /var/www/chatbot/vendor/openai-php/client/src/Transporters/HttpTransporter.php(61): json_decode()

1 /var/www/chatbot/vendor/openai-php/client/src/Resources/Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject()

2 /var/www/chatbot/public/chat/tet.php(10): OpenAI\Resources\Chat->create()

3 {main}

Next OpenAI\Exceptions\UnserializableResponse: Syntax error in /var/www/chatbot/vendor/openai-php/client/src/Transporters/HttpTransporter.php:63 Stack trace:

0 /var/www/chatbot/vendor/openai-php/client/src/Resources/Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject()

1 /var/www/chatbot/public/chat/tet.php(10): OpenAI\Resources\Chat->create()

2 {main}

thrown in /var/www/chatbot/vendor/openai-php/client/src/Transporters/HttpTransporter.php on line 63

Steps To Reproduce

I'm trying to run this code $client = OpenAI::client($apiKey);

$response = $client->chat()->create([ 'model' => 'gpt-4', 'messages' => [ ['role'=>'system', 'content' => 'Assistant'], ['role' => 'user', 'content' => 'Hello!'], ], ]);

OpenAI PHP Client Version

v0.8.4

PHP Version

8.1

Notes

No response