|
|
|
@@ -3,6 +3,9 @@ package com.xueyi.nlt.nlt.template; |
|
|
|
import com.alibaba.druid.util.StringUtils; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
import com.xueyi.common.core.context.SecurityContextHolder; |
|
|
|
import com.xueyi.common.core.web.result.AjaxResult; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.KnowledgeVo; |
|
|
|
import com.xueyi.nlt.api.nlt.feign.RemoteQAService; |
|
|
|
import com.xueyi.nlt.netty.client.WebSocketClientManager; |
|
|
|
import com.xueyi.nlt.nlt.context.TerminalSecurityContextHolder; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmContext; |
|
|
|
@@ -33,6 +36,9 @@ public class FreeChatTemplate implements BaseTemplate{ |
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String,String> redisTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RemoteQAService remoteQAService; |
|
|
|
|
|
|
|
private Map<String,String> correctWordsMap = new HashMap<>(); |
|
|
|
|
|
|
|
// 中航信领导来访临时对策 |
|
|
|
@@ -57,12 +63,13 @@ public class FreeChatTemplate implements BaseTemplate{ |
|
|
|
List<String> context = new ArrayList<>(); |
|
|
|
context.add("你是缔智元公司的前台,你叫小智,你是一位数字人。"); |
|
|
|
context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); |
|
|
|
|
|
|
|
content = generatePrompts(content); |
|
|
|
context.add(content); |
|
|
|
|
|
|
|
//webSocketClient.sendMsg(context); |
|
|
|
|
|
|
|
LlmContext llmContext = LlmContext.parse(context,true); |
|
|
|
llmContext.setDevId(devId); |
|
|
|
LlmParam param = new LlmParam(); |
|
|
|
LlmResponse response = sysLlmService.chat(llmContext,param); |
|
|
|
String result = response.getContent(); |
|
|
|
@@ -108,7 +115,7 @@ public class FreeChatTemplate implements BaseTemplate{ |
|
|
|
} |
|
|
|
|
|
|
|
//context.addAll(redisTemplate.opsForList().range(redisKey,size-2,size)); |
|
|
|
content = "请用简短的话回答下面的问题:" + content; |
|
|
|
content = generatePrompts(content); |
|
|
|
context.add(content); |
|
|
|
//使用stream去除context列表中所有字符串中的引号 |
|
|
|
context = context.stream().map(s -> s.replaceAll("\"", "")).collect(java.util.stream.Collectors.toList()); |
|
|
|
@@ -132,4 +139,35 @@ public class FreeChatTemplate implements BaseTemplate{ |
|
|
|
public JSONObject handle(String dev, String content, Long tenantId) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private String addHotspot(String content) { |
|
|
|
KnowledgeVo vo = new KnowledgeVo(); |
|
|
|
String result = ""; |
|
|
|
vo.setQuestion(content); |
|
|
|
AjaxResult hotspotResult = remoteQAService.searchHotspot(vo); |
|
|
|
log.info("hotspotResult:{}",hotspotResult); |
|
|
|
if(hotspotResult.get("data") == null){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
try{ |
|
|
|
List<String> hotspotList = (List<String>) hotspotResult.get("data"); |
|
|
|
for(String hotspot : hotspotList){ |
|
|
|
result = result + hotspot + ","; |
|
|
|
} |
|
|
|
result = result.substring(0,result.length()-1); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("查询热点词失败",e); |
|
|
|
return result; |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private String generatePrompts(String content){ |
|
|
|
String msg = addHotspot(content); |
|
|
|
if(msg.equals("")){ |
|
|
|
return "请用简短的话回答下面的问题:" + content; |
|
|
|
} |
|
|
|
String result = "请根据下面的信息:'''/n" + msg + "/n'''请用简短的话回答下面的问题:" + content; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |