正在显示
1 个修改的文件
包含
3 行增加
和
4 行删除
| @@ -68,13 +68,12 @@ class ChatLogic extends BaseLogic | @@ -68,13 +68,12 @@ class ChatLogic extends BaseLogic | ||
| 68 | header('Connection: keep-alive'); | 68 | header('Connection: keep-alive'); |
| 69 | $aiResponse = ''; | 69 | $aiResponse = ''; |
| 70 | while (!$stream->eof()) { | 70 | while (!$stream->eof()) { |
| 71 | - $chunk = $stream->read(1); | 71 | + $chunk = $stream->read(1024); |
| 72 | $chunk = str_replace(chr(1), '', $chunk); | 72 | $chunk = str_replace(chr(1), '', $chunk); |
| 73 | if ($chunk !== false) { | 73 | if ($chunk !== false) { |
| 74 | - $chunk = json_decode($chunk,true); | ||
| 75 | - $aiResponse .= $chunk['text']; // 累积完整的 AI 回复 | 74 | + $aiResponse .= $chunk; // 累积完整的 AI 回复 |
| 76 | // 使用 en_sse_data 格式化流数据 | 75 | // 使用 en_sse_data 格式化流数据 |
| 77 | - echo $gptService->en_sse_data(trim($chunk['text'])); | 76 | + echo $gptService->en_sse_data(trim($chunk)); |
| 78 | ob_flush(); | 77 | ob_flush(); |
| 79 | flush(); | 78 | flush(); |
| 80 | } | 79 | } |
-
请 注册 或 登录 后发表评论