laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.74k stars 291 forks source link

Connection refused error when streaming OpenAI responses #820

Closed benbjurstrom closed 5 months ago

benbjurstrom commented 7 months ago

Octane Version

2.3.0

Laravel Version

10.41.0

PHP Version

8.3.1

What server type are you using?

FrankenPHP

Server Version

FrankenPHP 1.0.3 | Caddy v2.7.6

Database Driver & Version

N/A

Description

Ran into an issue streaming responses with the openai-php/client package. Calling the createStreamed method in a FrankenPHP Octane environment throws a connection refused error.

I've isolated it to an Octane FrankenPHP issue since streaming works fine using FrankenPHP alone. It also seems to work fine using Octane Swoole.

image

Steps To Reproduce

I created a minimal reproduction of the issue here: https://github.com/benbjurstrom/octane-streaming-bug-report.

benbjurstrom commented 7 months ago

Had a chance to look at this again and confirmed it's not an issue with the openai-php package. Instead this error occurs anytime you pass the stream => true flag to guzzle in a FrankenPHP Octane environment.

    // use GuzzleHttp\Client;

    $client = new Client();
    $response = $client->get('https://api.openai.com/v1/chat/completions', [
        'stream' => true
    ]);
driesvints commented 7 months ago

@dunglas is it okay if I assign these FrankenPHP issues to you?

dunglas commented 7 months ago

@driesvints Sure

LukeAbell commented 5 months ago

@dunglas Any update on this? We're having this issue too. We'd like to use streaming responses for our AI features and recently moved to FrankenPHP.

dunglas commented 5 months ago

I wonder if it's not the same issue as https://github.com/dunglas/frankenphp/issues/582?

LukeAbell commented 5 months ago

@dunglas Not sure but we're having another issue related to streaming that might be related. Streaming an excel file downloads an empty file. It works correctly with valet, but breaks when using frankenphp. Switching to download instead of using a stream fixes the issue.

dunglas commented 5 months ago

Would you be able to provide a simple/small reproducer?

dunglas commented 5 months ago

This is being fixed by https://github.com/dunglas/frankenphp/pull/692.

driesvints commented 5 months ago

Thanks @dunglas. Gonna close this already if it's a Frankenphp thing.