|
|
@@ -18,11 +18,13 @@ import com.xueyi.common.core.web.validate.V_A; |
|
|
|
import com.xueyi.common.core.web.validate.V_E; |
|
|
|
import com.xueyi.common.log.annotation.Log; |
|
|
|
import com.xueyi.common.log.enums.BusinessType; |
|
|
|
import com.xueyi.common.mqtt.connection.MqttTemplate; |
|
|
|
import com.xueyi.common.security.annotation.Logical; |
|
|
|
import com.xueyi.common.security.annotation.RequiresPermissions; |
|
|
|
import com.xueyi.common.security.utils.SecurityUtils; |
|
|
|
import com.xueyi.common.web.entity.controller.BaseController; |
|
|
|
import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.*; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.CoversationSessionVo; |
|
|
|
import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; |
|
|
@@ -42,16 +44,16 @@ import com.xueyi.nlt.nlt.domain.LlmContext; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmParam; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmResponse; |
|
|
|
import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; |
|
|
|
import com.xueyi.nlt.nlt.domain.dto.DmPromptDto; |
|
|
|
import com.xueyi.nlt.nlt.domain.dto.DmSensitiveWordDto; |
|
|
|
import com.xueyi.nlt.nlt.domain.po.DmRegularPo; |
|
|
|
import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.DmKnowledgeLibAskVo; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.IntentTemplateVo; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.MarkRecordVo; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.*; |
|
|
|
import com.xueyi.nlt.nlt.mapper.DmRegularMapper; |
|
|
|
import com.xueyi.nlt.nlt.service.IDmIntentService; |
|
|
|
import com.xueyi.nlt.nlt.service.ISensitiveService; |
|
|
|
import com.xueyi.nlt.nlt.service.ISysLlmService; |
|
|
|
import com.xueyi.nlt.nlt.service.*; |
|
|
|
import com.xueyi.nlt.nlt.service.impl.DmSensitiveWordServiceImpl; |
|
|
|
import com.xueyi.nlt.nlt.template.*; |
|
|
|
import com.xueyi.system.api.digitalmans.domain.dto.DmManDeviceDto; |
|
|
@@ -65,9 +67,11 @@ import com.xueyi.system.api.model.LoginUser; |
|
|
|
import com.xueyi.system.api.model.Source; |
|
|
|
import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto; |
|
|
|
import com.xueyi.system.api.organize.feign.RemoteEnterpriseService; |
|
|
|
import com.yomahub.tlog.core.annotation.TLogAspect; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
@@ -88,9 +92,13 @@ import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import static com.xueyi.common.core.constant.digitalman.MessageConstants.SYS_DICT_DATA_SPLITED; |
|
|
|
|
|
|
@@ -135,6 +143,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
@Autowired |
|
|
|
private GenerativeKnowledgeTemplate generativeKnowledgeTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GenerativeWelcomeTemplate generativeWelcomeTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FreeChatTemplate freeChatTemplate; |
|
|
|
|
|
|
@@ -172,6 +183,15 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysLlmService sysLlmService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IDmHotspotService dmHotspotService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MqttTemplate mqttTemplate; |
|
|
|
|
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
private String activeProfile; |
|
|
|
/** |
|
|
|
* 意图请求 |
|
|
|
列表 |
|
|
@@ -209,6 +229,7 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return AjaxResult.success(jsonObjectR.getData()); |
|
|
|
} |
|
|
|
|
|
|
|
@TLogAspect(str="DGMAN-NLT") |
|
|
|
@PostMapping("/api/skill-intent") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult skillIntentApi(@RequestBody DmIntentVo intent) { |
|
|
@@ -347,10 +368,19 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
/** |
|
|
|
* 联动北方大模型请求 |
|
|
|
*/ |
|
|
|
@TLogAspect(str="DGMAN-NLT") |
|
|
|
@PostMapping("/api/searchQuestionAnswer") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult searchQuestionAnswer(@RequestBody DmIntentVo intent) { |
|
|
|
log.info("交互对象:{}",intent.toString()); |
|
|
|
// 定义标注日志对象 |
|
|
|
MarkRecordVo recordVo = new MarkRecordVo(); |
|
|
|
recordVo.setDevId(intent.getDevId()); |
|
|
|
recordVo.setId(IdUtil.getSnowflakeNextId()); |
|
|
|
recordVo.setCreateTime(LocalDateTime.now()); |
|
|
|
recordVo.setQuestion(intent.getContent()); |
|
|
|
recordVo.setHit(1); |
|
|
|
|
|
|
|
redisTemplate.opsForValue().increment("dashboard:server", 1); |
|
|
|
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(intent.getDevId()); |
|
|
|
if (manDeviceDtoR.isFail()) { |
|
|
@@ -362,8 +392,8 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
if (enterpriseDtoR.isOk()) { |
|
|
|
enterpriseName = enterpriseDtoR.getData().getName(); |
|
|
|
} |
|
|
|
recordVo.setTenantId(Long.valueOf(manDeviceDtoR.getData().getTId())); |
|
|
|
DmIntentResponse response = new DmIntentResponse(); |
|
|
|
|
|
|
|
//先调用意图 |
|
|
|
//根据技能调用知识库或大模型 |
|
|
|
CoversationSessionVo sessionObject = (CoversationSessionVo) redisTemplate2.opsForValue().get("group:device" + ":" + intent.getDevId() + ":" +"session"); |
|
|
@@ -371,6 +401,13 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
response.setMsg(""); |
|
|
|
response.setSkillCode("34"); |
|
|
|
response.setH5(flightMessageTemplate.handle(intent.getDevId(),intent.getContent())); |
|
|
|
recordVo.setType(2); |
|
|
|
recordVo.setSkillCode("34"); // 航班查询 |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getH5().toJSONString()); |
|
|
|
recordVo.setAnswers(answers); |
|
|
|
// 记录log |
|
|
|
log.info(recordVo.toString()); |
|
|
|
return AjaxResult.success(response); |
|
|
|
|
|
|
|
} |
|
|
@@ -380,6 +417,12 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
redisTemplate.opsForValue().increment("dashboard:flight", 1); |
|
|
|
pushIntoDashboardRedis(enterpriseName, "查询航班信息", "skill"); |
|
|
|
response.setH5(flightMessageTemplate.handle(intent.getDevId(), intent.getContent())); |
|
|
|
recordVo.setType(2); |
|
|
|
recordVo.setSkillCode("34"); // 航班查询 |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getH5().toJSONString()); |
|
|
|
recordVo.setAnswers(answers); |
|
|
|
log.info(recordVo.toString()); |
|
|
|
return AjaxResult.success(response); |
|
|
|
} |
|
|
|
} |
|
|
@@ -396,6 +439,12 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
content = qaAjax.getResult().get(0).getKnowledgeLib(); |
|
|
|
pushIntoDashboardRedis(enterpriseName,content,"knowledge"); |
|
|
|
response.setH5(JSONObject.from(qaAjax)); |
|
|
|
recordVo.setType(0); |
|
|
|
recordVo.setSkillCode("34"); // 航班查询 |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getH5().getJSONArray("result").getJSONObject(0).getString("answer")); |
|
|
|
recordVo.setAnswers(answers); |
|
|
|
log.info(recordVo.toString()); |
|
|
|
return AjaxResult.success(response); |
|
|
|
} |
|
|
|
} |
|
|
@@ -454,6 +503,14 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
joImage.put("msg","抱歉,您的问题我无法解答。"); |
|
|
|
response.setH5(joImage); |
|
|
|
} |
|
|
|
// 记录日志 |
|
|
|
recordVo.setType(1); |
|
|
|
recordVo.setSkillCode("30"); // 航班查询 |
|
|
|
recordVo.setLlm("lagi"); |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getH5().getString("msg")); |
|
|
|
recordVo.setAnswers(answers); |
|
|
|
log.info(recordVo.toString()); |
|
|
|
return AjaxResult.success(response); |
|
|
|
} |
|
|
|
|
|
|
@@ -510,6 +567,7 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
jo.put("content",knowledgeLibAskVo.getQuestion()); |
|
|
|
ja1.add(jo); |
|
|
|
testJ.put("messages",ja1); |
|
|
|
log.info("北方大请求:{}",testJ.toJSONString()); |
|
|
|
String gatewayheader = LagiConfig.tenantLlmMap.get(enterpriseDtoR.getData().getName()); |
|
|
|
gatewayheader = StringUtils.isEmpty(gatewayheader) ? "": gatewayheader; |
|
|
|
log.info("北方大请求:{}",gatewayheader); |
|
|
@@ -557,11 +615,20 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
/** |
|
|
|
* 意图请求列表 |
|
|
|
*/ |
|
|
|
@TLogAspect(str="DGMAN-NLT") |
|
|
|
@PostMapping("/inner/conversation") |
|
|
|
@ResponseBody |
|
|
|
public R<DmIntentResponse> conversationInner(@RequestBody DmIntentVo intent) { |
|
|
|
DmIntentResponse response = new DmIntentResponse(); |
|
|
|
|
|
|
|
// 记录 |
|
|
|
// 定义标注日志对象 |
|
|
|
MarkRecordVo recordVo = new MarkRecordVo(); |
|
|
|
recordVo.setDevId(intent.getDevId()); |
|
|
|
recordVo.setId(IdUtil.getSnowflakeNextId()); |
|
|
|
recordVo.setCreateTime(LocalDateTime.now()); |
|
|
|
recordVo.setQuestion(intent.getContent()); |
|
|
|
recordVo.setHit(1); |
|
|
|
|
|
|
|
String enterpriseId = (String)SecurityContextHolder.getLocalMap().get("enterprise_id"); |
|
|
|
String enterpriseName = ""; |
|
|
@@ -580,6 +647,11 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
if (response == null || StringUtils.isEmpty(response.getSkillCode())) { |
|
|
|
// 做场景1、2处理 |
|
|
|
if (!StringUtils.isEmpty(response.getMsg())) { |
|
|
|
// 记录log |
|
|
|
recordVo.setType(2); |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getMsg()); |
|
|
|
recordVo.setAnswers(answers); // 航班查询 |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
else { |
|
|
@@ -594,6 +666,11 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
content = qaAjax.getResult().get(0).getKnowledgeLib(); |
|
|
|
pushIntoDashboardRedis(enterpriseName,content,"knowledge"); |
|
|
|
response.setH5(JSONObject.from(qaAjax)); |
|
|
|
// 记录log |
|
|
|
recordVo.setType(2); |
|
|
|
List answers = new ArrayList(); |
|
|
|
answers.add(response.getMsg()); |
|
|
|
recordVo.setAnswers(answers); // 航班查询 |
|
|
|
return R.ok(response); |
|
|
|
} |
|
|
|
else { |
|
|
@@ -734,8 +811,6 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 意图请求 |
|
|
|
列表 |
|
|
@@ -1054,6 +1129,55 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return AjaxResult.error(res); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/inner/generateContextTask") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult generateContextTask() { |
|
|
|
LocalDateTime dateTime = LocalDateTime.now(); |
|
|
|
String date = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
List<JSONObject> contentList = new ArrayList<>(); |
|
|
|
GenerativeWelcomeTemplate.lunar = ""; |
|
|
|
GenerativeWelcomeTemplate.term = null; |
|
|
|
try { |
|
|
|
JSONObject jo = generativeWelcomeTemplate.handle("1", ""); |
|
|
|
JSONArray ja = jo.getJSONArray("data"); |
|
|
|
Long timeStamp = System.currentTimeMillis(); |
|
|
|
JSONObject timeJson = new JSONObject(); |
|
|
|
timeJson.put("timestamp", timeStamp); |
|
|
|
ja.add(timeJson); |
|
|
|
log.info(ja.toJSONString()); |
|
|
|
redisTemplate2.opsForHash().put("group:task" + ":generate", date, AjaxResult.success(ja).toJson().toJSONString()); |
|
|
|
Map<Object, Object> devices = redisTemplate2.opsForHash().entries("group:dgman:device:"); |
|
|
|
for(Object devId:devices.keySet()){ |
|
|
|
mqttTemplate.sendToMqtt("/" + activeProfile + "/" + "digital_man" + "/" + devId.toString() + "/" + "notify" + "/" + "generate-welcome", true, AjaxResult.success(ja).toJson().toJSONString()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("生成任务失败:{}",e.getMessage()); |
|
|
|
return AjaxResult.error("生成任务失败"); |
|
|
|
} |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/syncHotspot") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult syncHotspot(){ |
|
|
|
Integer result = dmHotspotService.syncHotspot(); |
|
|
|
if(result.equals(0)){ |
|
|
|
return AjaxResult.success("同步成功"); |
|
|
|
}else { |
|
|
|
return AjaxResult.error("同步失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/collectHotspot") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult collectHotspot(){ |
|
|
|
Integer result = dmHotspotService.collectHotspot(); |
|
|
|
if(result.equals(0)){ |
|
|
|
return AjaxResult.success("热点收集成功"); |
|
|
|
}else { |
|
|
|
return AjaxResult.error("热点收集失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
interface Auth { |
|
|
|
/** 系统 - 意图管理 |
|
|
|