Guzzle-Swoole
Guzzle-Swoole copied to clipboard
服务端响应为stream流式响应时不能使用协程,仍然会堵塞执行
请求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
}
}
设置 DefaultHandler::setDefaultHandler(SwooleHandler::class); 不生效,只能设置单个设置才行
$handler = new SwooleHandler();
$stack = HandlerStack::create($handler);
$client = new \GuzzleHttp\Client(['handler' => $stack]);