作者 lyh

gx

... ... @@ -63,9 +63,9 @@ class ChatLogic extends BaseLogic
$data = ['message' => $message];
return response()->stream(function () use ($gptService, $data, $chatId) {
$fullResponse = ''; // 存储完整 AI 回复
$stream = $gptService->get_ai_chat($data); // 获取流
while (!$stream->eof()) {
$chunk = $stream->read(1024); // 逐步读取数据块
$response = $gptService->get_ai_chat($data); // 获取流
while (!$response->eof()) {
$chunk = $response->read(1024); // 逐步读取数据块
echo $gptService->en_sse_data($chunk); // **封装 SSE 数据**
ob_flush();
flush();
... ...
... ... @@ -46,8 +46,7 @@ class GptService
// **流式请求**
$payload->stream = true;
$response = $client->chat($payload);
$stream = $response->getBody();
return $stream;
return $response;
}
}
... ...