Yurunsoft / Guzzle-Swoole

让基于 Guzzle 的项目完美无缝兼容 Swoole 协程,支持:Guzzle、Elasticsearch client——来自宇润 PHP 全家桶
MIT License
161 stars 21 forks source link

服务端响应为stream流式响应时不能使用协程,仍然会堵塞执行 #29

Open grayTele opened 10 months ago

grayTele commented 10 months ago

请求openai的流式响应输出

{
    "url": "https:\/\/api.openai.com\/v1\/chat\/completions",
    "method": "POST",
    "data": {
        "model": "gpt-3.5-turbo",
        "messages": [{
            "role": "user",
            "content": "200字以上笑话"
        }],
        "temperature": 1,
        "frequency_penalty": 0,
        "presence_penalty": 0,
        "stream": true,
        "top_p": 1
    }
}
grayTele commented 10 months ago

设置 DefaultHandler::setDefaultHandler(SwooleHandler::class); 不生效,只能设置单个设置才行

   $handler = new SwooleHandler();
                        $stack = HandlerStack::create($handler);
                    $client = new \GuzzleHttp\Client(['handler' => $stack]);