作者 lyh

gx

@@ -63,9 +63,9 @@ class ChatLogic extends BaseLogic @@ -63,9 +63,9 @@ class ChatLogic extends BaseLogic
63 $data = ['message' => $message]; 63 $data = ['message' => $message];
64 return response()->stream(function () use ($gptService, $data, $chatId) { 64 return response()->stream(function () use ($gptService, $data, $chatId) {
65 $fullResponse = ''; // 存储完整 AI 回复 65 $fullResponse = ''; // 存储完整 AI 回复
66 - $stream = $gptService->get_ai_chat($data); // 获取流  
67 - while (!$stream->eof()) {  
68 - $chunk = $stream->read(1024); // 逐步读取数据块 66 + $response = $gptService->get_ai_chat($data); // 获取流
  67 + while (!$response->eof()) {
  68 + $chunk = $response->read(1024); // 逐步读取数据块
69 echo $gptService->en_sse_data($chunk); // **封装 SSE 数据** 69 echo $gptService->en_sse_data($chunk); // **封装 SSE 数据**
70 ob_flush(); 70 ob_flush();
71 flush(); 71 flush();
@@ -46,8 +46,7 @@ class GptService @@ -46,8 +46,7 @@ class GptService
46 // **流式请求** 46 // **流式请求**
47 $payload->stream = true; 47 $payload->stream = true;
48 $response = $client->chat($payload); 48 $response = $client->chat($payload);
49 - $stream = $response->getBody();  
50 - return $stream; 49 + return $response;
51 } 50 }
52 } 51 }
53 52