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