|
@@ -63,9 +63,9 @@ class ChatLogic extends BaseLogic |
|
@@ -63,9 +63,9 @@ class ChatLogic extends BaseLogic |
|
63
|
$data = ['message' => $message];
|
63
|
$data = ['message' => $message];
|
|
64
|
return response()->stream(function () use ($gptService, $data, $chatId) {
|
64
|
return response()->stream(function () use ($gptService, $data, $chatId) {
|
|
65
|
$fullResponse = ''; // 存储完整 AI 回复
|
65
|
$fullResponse = ''; // 存储完整 AI 回复
|
|
66
|
- $stream = $gptService->get_ai_chat($data); // 获取流
|
|
|
|
67
|
- while (!$stream->eof()) {
|
|
|
|
68
|
- $chunk = $stream->read(1024); // 逐步读取数据块
|
66
|
+ $response = $gptService->get_ai_chat($data); // 获取流
|
|
|
|
67
|
+ while (!$response->eof()) {
|
|
|
|
68
|
+ $chunk = $response->read(1024); // 逐步读取数据块
|
|
69
|
echo $gptService->en_sse_data($chunk); // **封装 SSE 数据**
|
69
|
echo $gptService->en_sse_data($chunk); // **封装 SSE 数据**
|
|
70
|
ob_flush();
|
70
|
ob_flush();
|
|
71
|
flush();
|
71
|
flush();
|