octane icon indicating copy to clipboard operation
octane copied to clipboard

Connection refused error when streaming OpenAI responses

Open benbjurstrom opened this issue 1 year ago • 3 comments

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 avatar Jan 19 '24 06:01 benbjurstrom

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
    ]);

benbjurstrom avatar Jan 21 '24 22:01 benbjurstrom

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

driesvints avatar Jan 22 '24 09:01 driesvints

@driesvints Sure

dunglas avatar Jan 22 '24 10:01 dunglas

@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.

LukeAbell avatar Mar 27 '24 01:03 LukeAbell

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

dunglas avatar Mar 27 '24 05:03 dunglas

@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.

LukeAbell avatar Mar 27 '24 16:03 LukeAbell

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

dunglas avatar Mar 27 '24 17:03 dunglas

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

dunglas avatar Mar 31 '24 16:03 dunglas

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

driesvints avatar Apr 02 '24 07:04 driesvints