我改了点东西
This commit is contained in:
parent
864b25e919
commit
9df062b972
@ -485,7 +485,7 @@ public class ConversationServiceImpl implements ConversationService {
|
||||
// log.info("构建模型补全请求对象,请求参数1: {}", modelCompletionsReqVO);
|
||||
|
||||
// 调用模型服务进行流式处理
|
||||
ModelCompletionsRespVO modelCompletionsRespVO = modelService.modelCompletionsStream(selfModelUrl, modelCompletionsReqVO, emitter, chatReqVO.getUuid(), chatReqVO.getGroupId());
|
||||
ModelCompletionsRespVO modelCompletionsRespVO = modelService.modelCompletionsStream(selfModelUrl, modelCompletionsReqVO, emitter, chatReqVO.getUuid(), chatReqVO.getGroupId(),knowledgeBaseString);
|
||||
if (modelCompletionsRespVO == null) {
|
||||
throw exception(MODEL_COMPLETIONS_ERROR);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class ModelService {
|
||||
* @param url 模型服务的 URL
|
||||
* @param req 模型补全请求对象
|
||||
*/
|
||||
public ModelCompletionsRespVO modelCompletionsStream (String url, ModelCompletionsReqVO req, SseEmitter emitter, String uuid, String groupId) {
|
||||
public ModelCompletionsRespVO modelCompletionsStream (String url, ModelCompletionsReqVO req, SseEmitter emitter, String uuid, String groupId,String knowledgeBaseString) {
|
||||
req.setStream(true);
|
||||
log.info("开始处理模型补全请求");
|
||||
|
||||
@ -170,7 +170,7 @@ public class ModelService {
|
||||
try {
|
||||
String jsonString = JSON.toJSONString(req);
|
||||
log.info("开始处理模型补全请求,参数3: {}", jsonString);
|
||||
answer = sendPostRequest(url, jsonString, emitter, uuid, groupId);
|
||||
answer = sendPostRequest(url, jsonString, emitter, uuid, groupId,knowledgeBaseString);
|
||||
} catch (Exception e) {
|
||||
emitter.completeWithError(e);
|
||||
|
||||
@ -223,7 +223,7 @@ public class ModelService {
|
||||
* @param requestBody 请求体内容
|
||||
* @throws IOException 发送请求或处理响应时可能抛出的 IO 异常
|
||||
*/
|
||||
private String sendPostRequest (String apiUrl, String requestBody, SseEmitter emitter, String uuid, String groupId) throws IOException {
|
||||
private String sendPostRequest (String apiUrl, String requestBody, SseEmitter emitter, String uuid, String groupId,String knowledgeBaseString) throws IOException {
|
||||
// 创建 HttpClient 实例
|
||||
HttpClient httpClient = HttpClients.createDefault();
|
||||
|
||||
@ -237,7 +237,7 @@ public class ModelService {
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
// 处理响应实体
|
||||
return handleResponseEntity(response, emitter, uuid, groupId);
|
||||
return handleResponseEntity(response, emitter, uuid, groupId,knowledgeBaseString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,7 +267,7 @@ public class ModelService {
|
||||
*
|
||||
* @param response HttpResponse 对象
|
||||
*/
|
||||
private String handleResponseEntity (HttpResponse response, SseEmitter emitter, String uuid, String groupId) {
|
||||
private String handleResponseEntity (HttpResponse response, SseEmitter emitter, String uuid, String groupId,String knowledgeBaseString) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
// 获取响应实体
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
@ -303,7 +303,7 @@ public class ModelService {
|
||||
// if (i!=1 && i!=2) {
|
||||
// line = line.replaceAll("\n", " ");
|
||||
|
||||
String content = parseStreamLine(line, uuid,groupId);
|
||||
String content = parseStreamLine(line, uuid,groupId,knowledgeBaseString);
|
||||
if (content != null) {
|
||||
emitter.send(
|
||||
SseEmitter.event()
|
||||
@ -339,7 +339,7 @@ public class ModelService {
|
||||
* @param line 流式响应中的单行JSON数据
|
||||
* @return 处理后的文本内容(若无有效内容返回null)
|
||||
*/
|
||||
private String parseStreamLine (String line, String uuid, String groupId) {
|
||||
private String parseStreamLine (String line, String uuid, String groupId,String knowledgeBaseString) {
|
||||
if (StringUtils.isNotBlank(line)) {
|
||||
if (line.startsWith("data: ")) {
|
||||
String dataString = extractJsonFromDataString(line);
|
||||
@ -370,6 +370,7 @@ public class ModelService {
|
||||
chatReqVO.setUuid(uuid);
|
||||
chatReqVO.setGroupId(groupId);
|
||||
chatReqVO.setContent("");
|
||||
chatReqVO.setIsExist(!StringUtils.isBlank(knowledgeBaseString));
|
||||
chatReqVO.setFinish_reason(true);
|
||||
return JSON.toJSONString(chatReqVO);
|
||||
}
|
||||
|
@ -22,6 +22,11 @@ public class ChatReqVO {
|
||||
*/
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* 是否有知识库命中
|
||||
*/
|
||||
private Boolean isExist;
|
||||
|
||||
/**
|
||||
* 是否结束对话
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user