修改ai对话中(空参考) 漏洞解决问题——已测试通过
This commit is contained in:
@@ -4,8 +4,8 @@ import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cms.domain.chat.ChatRequest;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.var;
|
||||
import okhttp3.*;
|
||||
import okio.BufferedSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -97,18 +97,34 @@ public class ChatClient {
|
||||
}
|
||||
|
||||
// 逐行读取 SSE 格式的响应
|
||||
try (var bufferedSource = body.source()) {
|
||||
//判断 bufferedSource
|
||||
if (bufferedSource != null) {
|
||||
return;
|
||||
}
|
||||
BufferedSource bufferedSource = body.source();
|
||||
if (bufferedSource == null) {
|
||||
System.out.println("bufferedSource 为空,直接返回");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
while (!bufferedSource.exhausted()) {
|
||||
String chunk = bufferedSource.readUtf8Line();
|
||||
if (chunk != null && !chunk.trim().isEmpty()) {
|
||||
callback.onData(chunk);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("读取流异常"+ e);
|
||||
} finally {
|
||||
try {
|
||||
bufferedSource.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
/*try (var bufferedSource = body.source()) {
|
||||
while (!bufferedSource.exhausted()) {
|
||||
String chunk = bufferedSource.readUtf8Line();
|
||||
if (chunk != null && !chunk.trim().isEmpty()) {
|
||||
callback.onData(chunk);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// 通知流结束
|
||||
callback.onComplete();
|
||||
|
||||
Reference in New Issue
Block a user