正在显示
1 个修改的文件
包含
4 行增加
和
4 行删除
| @@ -66,15 +66,15 @@ class ChatLogic extends BaseLogic | @@ -66,15 +66,15 @@ class ChatLogic extends BaseLogic | ||
| 66 | header('Content-Type: text/event-stream'); | 66 | header('Content-Type: text/event-stream'); |
| 67 | header('Cache-Control: no-cache'); | 67 | header('Cache-Control: no-cache'); |
| 68 | header('Connection: keep-alive'); | 68 | header('Connection: keep-alive'); |
| 69 | - while (!feof($stream)) { | ||
| 70 | - $chunk = fread($stream, 1024); | 69 | + while (!$stream->eof()) { |
| 70 | + $chunk = $stream->read(1024); | ||
| 71 | if ($chunk !== false) { | 71 | if ($chunk !== false) { |
| 72 | - echo "data: " . trim($chunk) . "\n\n"; | 72 | + // 使用 en_sse_data 格式化流数据 |
| 73 | + echo $gptService->en_sse_data(trim($chunk)); | ||
| 73 | ob_flush(); | 74 | ob_flush(); |
| 74 | flush(); | 75 | flush(); |
| 75 | } | 76 | } |
| 76 | } | 77 | } |
| 77 | - fclose($stream); | ||
| 78 | return true; | 78 | return true; |
| 79 | } | 79 | } |
| 80 | 80 |
-
请 注册 或 登录 后发表评论