openai-php / client

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

[Bug]: Idle timeout reached for "https://api.openai.com/v1/chat/completions" #294

Closed nekromoff closed 6 months ago

nekromoff commented 6 months ago

Description

Fatal error: Uncaught Symfony\Component\HttpClient\Exception\TimeoutException: Idle timeout reached for "https://api.openai.com/v1/chat/completions". in /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Chunk/ErrorChunk.php:56 Stack trace: #0 /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Response/CommonResponseTrait.php(146): Symfony\Component\HttpClient\Chunk\ErrorChunk->isFirst() #1 /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Response/TransportResponseTrait.php(52): Symfony\Component\HttpClient\Response\CurlResponse::initialize() #2 /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Internal/HttplugWaitLoop.php(119): Symfony\Component\HttpClient\Response\CurlResponse->getStatusCode() #3 /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Psr18Client.php(107): Symfony\Component\HttpClient\Internal\HttplugWaitLoop::createPsr7Response() #4 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(49): Symfony\Component\HttpClient\Psr18Client->sendRequest() #5 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(102): OpenAI\Transporters\HttpTransporter->OpenAI\Transporters\{closure}() #6 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(49): OpenAI\Transporters\HttpTransporter->sendRequest() #7 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Resources/Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject() #8 /var/www/html/xxx/chatgpt/test.php(9): OpenAI\Resources\Chat->create() #9 {main} Next Symfony\Component\HttpClient\Psr18NetworkException: Idle timeout reached for "https://api.openai.com/v1/chat/completions". in /var/www/html/xxx/chatgpt/vendor/symfony/http-client/Psr18Client.php:113 Stack trace: #0 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(49): Symfony\Component\HttpClient\Psr18Client->sendRequest() #1 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(102): OpenAI\Transporters\HttpTransporter->OpenAI\Transporters\{closure}() #2 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(49): OpenAI\Transporters\HttpTransporter->sendRequest() #3 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Resources/Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject() #4 /var/www/html/xxx/chatgpt/test.php(9): OpenAI\Resources\Chat->create() #5 {main} Next OpenAI\Exceptions\TransporterException: Idle timeout reached for "https://api.openai.com/v1/chat/completions". in /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php:108 Stack trace: #0 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php(49): OpenAI\Transporters\HttpTransporter->sendRequest() #1 /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Resources/Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject() #2 /var/www/html/xxx/chatgpt/test.php(9): OpenAI\Resources\Chat->create() #3 {main} thrown in /var/www/html/xxx/chatgpt/vendor/openai-php/client/src/Transporters/HttpTransporter.php on line 108

Steps To Reproduce

run longer prompt using:

$response = $client->chat()->create([
    'model' => 'gpt-4',
    //'temperature' => 0.2,
    'max_tokens' => 1500, // 4097
    'messages' => [
        ['role' => 'user', 'content' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'],
    ],
]);

where xxxxxxxx is about 1150 chars long. This error will happen all the time. Very short (under 200 chars) prompts work.

OpenAI PHP Client Version

0.8.0

PHP Version

8.3.0

Notes

No response

nekromoff commented 6 months ago

composer.json versions:

"symfony/http-client": "^7.0",
        "nyholm/psr7": "^1.8",
        "openai-php/client": "^0.8.0",
        "guzzlehttp/guzzle": "^7.8"
StandingFuture commented 6 months ago

Would love if we were able to specify timeout. My application often has long responses and this is causing timeouts. Made me have to switch to using gpt3.5 for now until this is fixed.

nekromoff commented 6 months ago

Good catch, switching to 3.5-turbo works. Still a serious issue for v4 making it completely unusable for longer prompts.

polucorus commented 6 months ago

Good catch, switching to 3.5-turbo works. Still a serious issue for v4 making it completely unusable for longer prompts.

I've had this issue on the 3.5 turbo many times.

StandingFuture commented 6 months ago

Good catch, switching to 3.5-turbo works. Still a serious issue for v4 making it completely unusable for longer prompts.

I have been able to use long prompts and they work just fine. I think the problem is with longer responses taking too long and causing it to timeout.

gehrisandro commented 6 months ago

Hi

This is a problem with the (default) timeout configured in the HTTP client you are using.

I've added a troubleshooting section to the docs explaining how to increase the timeouts: https://github.com/openai-php/client?tab=readme-ov-file#timeout

I hope this helps. Otherwise please let me know.