作者 lyh

gx

@@ -69,12 +69,17 @@ class ChatLogic extends BaseLogic @@ -69,12 +69,17 @@ class ChatLogic extends BaseLogic
69 while (!$stream->eof()) { 69 while (!$stream->eof()) {
70 $chunk = $stream->read(1024); 70 $chunk = $stream->read(1024);
71 if ($chunk !== false) { 71 if ($chunk !== false) {
  72 + $aiResponse .= $chunk; // 累积完整的 AI 回复
72 // 使用 en_sse_data 格式化流数据 73 // 使用 en_sse_data 格式化流数据
73 echo $gptService->en_sse_data(trim($chunk)); 74 echo $gptService->en_sse_data(trim($chunk));
74 ob_flush(); 75 ob_flush();
75 flush(); 76 flush();
76 } 77 }
77 } 78 }
  79 + // 确保数据不是空的
  80 + if (!empty(trim($aiResponse)) && $chatId) {
  81 + $this->saveChatItem($chatId, trim($aiResponse), 1); // 存入数据库
  82 + }
78 return true; 83 return true;
79 } 84 }
80 85