Commit cb34216f authored by 赵灿灿's avatar 赵灿灿

新增插件调用信息

parent f4d35759
Pipeline #22940 failed with stages
in 4 minutes and 53 seconds
......@@ -975,5 +975,118 @@ public class LangChainController {
}
//调用插件智能体
@GetMapping("/sseIntelligentNew")
public ResponseEntity<SseEmitter> sseIntelligentNew(@RequestParam String chatMessage,@RequestParam String dialogId,
@RequestParam String selectedExpert ,@RequestParam String selectedOrg) {
String condition="";
String regionName= chatService.getAuthRegionName();
if("内部专家".equals(selectedExpert)) {
if ("组织内".equals(selectedOrg) && StringUtils.isNotEmpty(regionName)) {
condition = ",只能查找" + regionName;
} else if ("组织外".equals(selectedOrg) && StringUtils.isNotEmpty(regionName)) {
condition = ",排除" + regionName;
}
}
String urlAddr = "http://10.32.41.25:40349/invoke/api/open/sse/unifiedcapability";
//String urlAddr = chatService.getUrl(selectedExpert);
AgentChatParams agentChatParams = new AgentChatParams();
agentChatParams.setKeyword(chatMessage);
agentChatParams.setRequestId(getRequestId());
agentChatParams.setDialogId(dialogId);
agentChatParams.setHistory(5);
AgentChatRequest agentChatRequest = new AgentChatRequest();
if("外部专家".equals(selectedExpert))
agentChatRequest.setCapabilityCode("cd438f7a96964382998bc89b957bf3dc");
else {
agentChatRequest.setCapabilityCode("5386f9144ee042578d1c0f66c2598d06");
}
agentChatRequest.setCapabilityType("2");
agentChatRequest.setParams(agentChatParams);
SseEmitter emitter = new SseEmitter(0L);
QuestionRequest questionRequest=new QuestionRequest();
questionRequest.setKeyword(chatMessage+condition);
questionRequest.setRequestId(getRequestId());
questionRequest.setDialogId(dialogId);
Conversations conversations=chatService.saveConversations(dialogId,chatMessage,selectedExpert);
Messages messagesQusetion=new Messages();
messagesQusetion.setRequestId(dialogId);
messagesQusetion.setContent(chatMessage);
messagesQusetion.setRole("user");
messagesQusetion.setModelName("qwen2.5-72b");
messagesQusetion=chatService.insertQuestionMessage(conversations,messagesQusetion);
Messages messagesContent=new Messages();
messagesContent.setRole("assistant");
messagesContent.setModelName("qwen2.5-72b");
messagesContent.setParentMsgId(messagesQusetion.getId());
messagesContent.setSort(messagesQusetion.getSort()+1);
chatService.insertMessage(conversations,messagesContent);
String params = JsonUtils.objectToJson(agentChatRequest);
StringBuffer content =new StringBuffer();
StringBuffer lineCotent =new StringBuffer();
new Thread(() -> {
CloseableHttpClient closeableHttpClient = httpClientPool.sseHttpClient();
HttpPost httpPost = new HttpPost(urlAddr);
try {
httpPost.setHeader("AuthToken", "4009fe23e6b648539792330c14f5ed8e");
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(params, StandardCharsets.UTF_8));
logger.info("调用智宇智能体请求体:" + params);
boolean isSendStop = false;
try (CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
InputStream inputStream = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))){
// 检查响应码
int statusCode = response.getStatusLine().getStatusCode();
// 持续读取 SSE 数据流
String line;
while ((line = reader.readLine()) != null) {
logger.info("Response body:" + line);
if (!line.startsWith("data:CALLBACK#")) {
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("stop".equals(data)) {
emitter.send(SseEmitter.event().data("stop"), MediaType.parseMediaType("application/json; charset=UTF-8"));
isSendStop = true;
} else {
lineCotent.append(data);
String sendData = data.replace("attachment#[]#attachment", "").replace("source#[]#source", "")
.replace("#", "").replace("*", "");
emitter.send(SseEmitter.event().data(sendData), MediaType.parseMediaType("application/json; charset=UTF-8"));
if (!sendData.startsWith("SUGGEST["))
content.append(sendData);
}
}
}
}
}catch (Exception e) {
emitter.completeWithError(e);
logger.error("调用智宇智能体接口异常: ", e);
}
if (!isSendStop){//如果没有发送stop,发送stop。
emitter.send(SseEmitter.event().data("stop"), MediaType.parseMediaType("application/json; charset=UTF-8"));
}
emitter.complete(); // 流结束
} catch (Exception e) {
emitter.completeWithError(e);
logger.info(e.getMessage());
} finally {
messagesContent.setContent(content.toString());
chatService.updateMessage(messagesContent);
logger.info(lineCotent.toString());
}
}).start();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_EVENT_STREAM_VALUE)
.body(emitter);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment