|
...
|
...
|
@@ -68,13 +68,12 @@ class ChatLogic extends BaseLogic |
|
|
|
header('Connection: keep-alive');
|
|
|
|
$aiResponse = '';
|
|
|
|
while (!$stream->eof()) {
|
|
|
|
$chunk = $stream->read(1);
|
|
|
|
$chunk = $stream->read(1024);
|
|
|
|
$chunk = str_replace(chr(1), '', $chunk);
|
|
|
|
if ($chunk !== false) {
|
|
|
|
$chunk = json_decode($chunk,true);
|
|
|
|
$aiResponse .= $chunk['text']; // 累积完整的 AI 回复
|
|
|
|
$aiResponse .= $chunk; // 累积完整的 AI 回复
|
|
|
|
// 使用 en_sse_data 格式化流数据
|
|
|
|
echo $gptService->en_sse_data(trim($chunk['text']));
|
|
|
|
echo $gptService->en_sse_data(trim($chunk));
|
|
|
|
ob_flush();
|
|
|
|
flush();
|
|
|
|
}
|
...
|
...
|
|