|
...
|
...
|
@@ -63,10 +63,18 @@ class ChatLogic extends BaseLogic |
|
|
|
}
|
|
|
|
$data = ['message' => $message];
|
|
|
|
$stream = $gptService->get_ai_chat($data); // 获取流
|
|
|
|
$streamHelper = new Stream($stream);
|
|
|
|
$streamHelper->echo();
|
|
|
|
$res_message = $streamHelper->getData();
|
|
|
|
$this->saveChatItem($chatId, $res_message,1);
|
|
|
|
header('Content-Type: text/event-stream');
|
|
|
|
header('Cache-Control: no-cache');
|
|
|
|
header('Connection: keep-alive');
|
|
|
|
while (!feof($stream)) {
|
|
|
|
$chunk = fread($stream, 1024);
|
|
|
|
if ($chunk !== false) {
|
|
|
|
echo "data: " . trim($chunk) . "\n\n";
|
|
|
|
ob_flush();
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|