Guzzle-Swoole icon indicating copy to clipboard operation
Guzzle-Swoole copied to clipboard

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

Open grayTele opened this issue 2 years ago • 1 comments

请求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 avatar Nov 26 '23 13:11 grayTele

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

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

grayTele avatar Nov 26 '23 14:11 grayTele