合并分支 'lyh-server' 到 'master'
gx 查看合并请求 !1702
正在显示
1 个修改的文件
包含
5 行增加
和
0 行删除
| @@ -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 |
-
请 注册 或 登录 后发表评论