openai-php / client

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

ErrorException: That model is currently overloaded with other requests. #123

Closed nerra0pos closed 1 year ago

nerra0pos commented 1 year ago

I am getting this error sometimes:

`[12-May-2023 20:10:23 UTC] PHP Fatal error: Uncaught OpenAI\Exceptions\ErrorException: That model is currently overloaded with other requests. You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID XXXXXXXXX in your message.) in /var/www/html/vendor/openai-php/client/src/Transporters/HttpTransporter.php:66 Stack trace:

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

1 /var/www/html/get.php(232): OpenAI\Resources\Chat->create()

2 /var/www/html/get.php(492): poll()

3 {main}

thrown in /var/www/html/vendor/openai-php/client/src/Transporters/HttpTransporter.php on line 66`

Here is my code:

try { $response = $client->chat()->create([ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'system', 'content' => 'XXXXXXX'], ['role' => 'user', 'content' => 'YYYYYY'], ], ]); } catch (ErrorException $e) { write_log("OpenAI error [Exception]: ".$e->getMessage()); $api_error = true; }

Why do I still get a Fatal PHP error that breaks the code? The exception seems to get missed.

pb30 commented 1 year ago

Try updating the catch to:

catch (\OpenAI\Exceptions\ErrorException $e) 
nerra0pos commented 1 year ago

Thanks, will try.

nerra0pos commented 1 year ago

I can confirm this solved the problem. Thanks @pb30