@@ -45,9 +45,10 @@ public class WebSocketClient extends WebSocketListener { | |||
@Value("${secret.spark.apiKey}") | |||
private String apiKey; | |||
@Value("${secret.spark.hostUrl}") | |||
public static String hostUrl; | |||
public final static Object LOCK = new Object(); | |||
public static String hostUrl = "https://spark-api.xf-yun.com/v2.1/chat"; | |||
// public static String APPID = "3d9282da";//从开放平台控制台中获取 | |||
// public static String APIKEY = "7c217b3a313f4b66fcc14a8e97f85103";//从开放平台控制台中获取 | |||
// public static String APISecret = "ZTRiNDQwMTRlOTlmZDQwMDUwYTdjMDM0";//从开放平台控制台中获取 | |||
@@ -206,7 +207,7 @@ public class WebSocketClient extends WebSocketListener { | |||
header.addProperty("uid","123456789"); | |||
//填充parameter | |||
// chat.addProperty("domain","general"); //1.0版本 | |||
chat.addProperty("domain","generalv2"); // 2.0版本 | |||
chat.addProperty("domain","generalv3"); // 3.0版本 | |||
chat.addProperty("random_threshold",0.5); | |||
chat.addProperty("max_tokens",1024); | |||
chat.addProperty("auditing","default"); | |||
@@ -36,44 +36,42 @@ public class FreeChatTemplate implements BaseTemplate{ | |||
Long operatorId = TerminalSecurityContextHolder.getOperatorId(); | |||
String redisKey = "group:nlp:" + SecurityContextHolder.getLocalMap().get("enterprise_id") + ":" + operatorId; | |||
// 根据content内容调用模版并返回结果 | |||
synchronized (WebSocketClient.LOCK) { | |||
// 通过redis获取数字人上下文信息 | |||
Long size = redisTemplate.opsForList().size(redisKey); | |||
if (size > 8) { | |||
redisTemplate.opsForList().leftPop(redisKey,2); | |||
} | |||
size = redisTemplate.opsForList().size(redisKey); | |||
List<String> context = new ArrayList<>(); | |||
context.add("你是一位公司前台事务的专家。"); | |||
context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | |||
// 通过redis获取数字人上下文信息 | |||
Long size = redisTemplate.opsForList().size(redisKey); | |||
if (size > 8) { | |||
redisTemplate.opsForList().leftPop(redisKey,2); | |||
} | |||
size = redisTemplate.opsForList().size(redisKey); | |||
List<String> context = new ArrayList<>(); | |||
context.add("你是一位企业前台。你来自于缔智元公司。你的名字叫小智,你是一位数字员工。"); | |||
context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | |||
context.add(content); | |||
context.add(content); | |||
//webSocketClient.sendMsg(context); | |||
//webSocketClient.sendMsg(context); | |||
LlmContext llmContext = LlmContext.parse(context,true); | |||
LlmParam param = new LlmParam(); | |||
LlmResponse response = sysLlmService.chat(llmContext,param); | |||
String result = response.getContent(); | |||
LlmContext llmContext = LlmContext.parse(context,true); | |||
LlmParam param = new LlmParam(); | |||
LlmResponse response = sysLlmService.chat(llmContext,param); | |||
String result = response.getContent(); | |||
// 处理数据 | |||
if (result.contains("我是科大讯飞")) { | |||
result = "我是缔智元公司的数字人员工,我采用的是科大讯飞的星火大模型。"; | |||
} | |||
// 处理数据 | |||
if (result.contains("我是科大讯飞")) { | |||
result = result.replaceAll("科大讯飞", "缔智元"); | |||
} | |||
result = result.replaceAll("认知模型", "数字员工"); | |||
result = result.replaceAll("认知智能模型", "数字员工"); | |||
if (result.equals("-1")) { | |||
result = "这个问题超出了我无法回答,您可以提出更多关于公司相关问题。"; | |||
} | |||
if(!StringUtils.isEmpty(result)){ | |||
if(!StringUtils.isEmpty(result)){ | |||
if (result.equals("-1")) { | |||
result = "这个问题超出了我的能力,您可以提出更多关于公司相关问题。"; | |||
} else { | |||
redisTemplate.opsForList().rightPush(redisKey,content); | |||
redisTemplate.opsForList().rightPush(redisKey,result); | |||
} | |||
JSONObject resultJson = new JSONObject(); | |||
resultJson.put("msg",result); | |||
return resultJson; | |||
} | |||
JSONObject resultJson = new JSONObject(); | |||
resultJson.put("msg",result); | |||
return resultJson; | |||
} | |||
public JSONObject handle(String dev, String content, boolean stream) { | |||
@@ -37,40 +37,42 @@ public class MovieChatTemplate implements BaseTemplate{ | |||
// 判断content如果小于5五个字,返回msg:对不起,能否再描述清除一些。 | |||
if(content.length() < 5){ | |||
JSONObject resultJson = new JSONObject(); | |||
resultJson.put("msg","对不起,能否再描述清除一些。"); | |||
resultJson.put("msg","对不起,能否再描述清楚一些。"); | |||
return resultJson; | |||
} | |||
Long operatorId = TerminalSecurityContextHolder.getOperatorId(); | |||
String redisKey = "group:nlp:" + SecurityContextHolder.getLocalMap().get("enterprise_id") + ":" + operatorId; | |||
// 根据content内容调用模版并返回结果 | |||
// 通过redis获取数字人上下文信息 | |||
Long size = redisTemplate.opsForList().size(redisKey); | |||
if (size > 8) { | |||
redisTemplate.opsForList().leftPop(redisKey,2); | |||
} | |||
size = redisTemplate.opsForList().size(redisKey); | |||
List<String> context = new ArrayList<>(); | |||
context.add("你现在扮演一位电影专家,你的话十分严谨。"); | |||
context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | |||
// 通过redis获取数字人上下文信息 | |||
Long size = redisTemplate.opsForList().size(redisKey); | |||
if (size > 8) { | |||
redisTemplate.opsForList().leftPop(redisKey,2); | |||
} | |||
size = redisTemplate.opsForList().size(redisKey); | |||
List<String> context = new ArrayList<>(); | |||
context.add("你是一位电影领域的专家。你来自于缔智元公司。你的名字叫小智"); | |||
context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | |||
context.add(content); | |||
LlmContext llmContext = LlmContext.parse(context,true); | |||
LlmParam param = new LlmParam(); | |||
LlmResponse response = sysLlmService.chat(llmContext,param); | |||
context.add(content); | |||
LlmContext llmContext = LlmContext.parse(context,true); | |||
LlmParam param = new LlmParam(); | |||
LlmResponse response = sysLlmService.chat(llmContext,param); | |||
String result = response.getContent(); | |||
String result = response.getContent(); | |||
String[] blockedWord = {"科大讯飞", "认知模型", "抱歉","认知智能模型"}; | |||
for(String a :blockedWord){ | |||
if(result != null && result.contains(a)){ | |||
result = ""; | |||
break; | |||
} | |||
} | |||
if(!StringUtils.isEmpty(result)){ | |||
// 处理数据 | |||
if (result.contains("我是科大讯飞")) { | |||
result = "我是缔智元公司的数字人员工,我采用的是科大讯飞的星火大模型。"; | |||
} | |||
if(!StringUtils.isEmpty(result)){ | |||
if (result.equals("-1")) { | |||
result = "这个问题超出了我的能力,您可以提出更多关于公司相关问题。"; | |||
} else { | |||
redisTemplate.opsForList().rightPush(redisKey,content); | |||
redisTemplate.opsForList().rightPush(redisKey,result); | |||
} | |||
} | |||
JSONObject resultJson = new JSONObject(); | |||
resultJson.put("msg",result); | |||