| 작성자 | SHA1 | 메시지 | 날짜 |
|---|---|---|---|
|
|
4bb4a6203d |
新增:
1、在闲聊时可以根据收集到的热点进行问答。 |
1 년 전 |
|
|
6564611197 |
新增:
1、新增实时热点推荐 |
1 년 전 |
| @@ -0,0 +1,19 @@ | |||||
| package com.xueyi.nlt.api.nlt.domain.vo; | |||||
| import lombok.Data; | |||||
| import java.io.Serial; | |||||
| @Data | |||||
| public class HotspotVo { | |||||
| @Serial | |||||
| private static final long serialVersionUID = 1L; | |||||
| protected String title; | |||||
| protected String content; | |||||
| protected String label; | |||||
| protected Long timestamp; | |||||
| } | |||||
| @@ -1,19 +1,20 @@ | |||||
| package com.xueyi.nlt.api.nlt.feign; | package com.xueyi.nlt.api.nlt.feign; | ||||
| import com.alibaba.fastjson2.JSONObject; | |||||
| import com.xueyi.common.core.constant.basic.SecurityConstants; | import com.xueyi.common.core.constant.basic.SecurityConstants; | ||||
| import com.xueyi.common.core.constant.basic.ServiceConstants; | import com.xueyi.common.core.constant.basic.ServiceConstants; | ||||
| import com.xueyi.common.core.web.result.AjaxResult; | import com.xueyi.common.core.web.result.AjaxResult; | ||||
| import com.xueyi.common.core.web.result.R; | import com.xueyi.common.core.web.result.R; | ||||
| import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; | import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | import com.xueyi.nlt.api.nlt.domain.vo.response.DmIntentResponse; | ||||
| import com.xueyi.nlt.api.nlt.feign.factory.RemoteIntentFallbackFactory; | import com.xueyi.nlt.api.nlt.feign.factory.RemoteIntentFallbackFactory; | ||||
| import org.springframework.cloud.openfeign.FeignClient; | import org.springframework.cloud.openfeign.FeignClient; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | import org.springframework.web.bind.annotation.PostMapping; | ||||
| import org.springframework.web.bind.annotation.RequestBody; | import org.springframework.web.bind.annotation.RequestBody; | ||||
| import org.springframework.web.bind.annotation.RequestHeader; | import org.springframework.web.bind.annotation.RequestHeader; | ||||
| import org.springframework.web.bind.annotation.ResponseBody; | |||||
| import java.util.List; | |||||
| @FeignClient(contextId = "remoteIntentService", value = ServiceConstants.NLT_SERVICE, fallbackFactory = RemoteIntentFallbackFactory.class) | @FeignClient(contextId = "remoteIntentService", value = ServiceConstants.NLT_SERVICE, fallbackFactory = RemoteIntentFallbackFactory.class) | ||||
| public interface RemoteIntentService { | public interface RemoteIntentService { | ||||
| @@ -29,4 +30,10 @@ public interface RemoteIntentService { | |||||
| @PostMapping("/intent/inner/generateContextTask") | @PostMapping("/intent/inner/generateContextTask") | ||||
| public AjaxResult generateContextTask(); | public AjaxResult generateContextTask(); | ||||
| @PostMapping("/intent/inner/syncHotspot") | |||||
| public AjaxResult syncHotspot(); | |||||
| @PostMapping("/intent/inner/collectHotspot") | |||||
| public AjaxResult collectHotspot(@RequestBody List<HotspotVo> hotspotVo); | |||||
| } | } | ||||
| @@ -29,4 +29,7 @@ public interface RemoteQAService { | |||||
| @PostMapping ("/knowledge") | @PostMapping ("/knowledge") | ||||
| R<DmKnowledgeResponse> query(@RequestBody KnowledgeVo vo); | R<DmKnowledgeResponse> query(@RequestBody KnowledgeVo vo); | ||||
| @PostMapping("/searchHotspot") | |||||
| AjaxResult searchHotspot(@RequestBody KnowledgeVo vo); | |||||
| } | } | ||||
| @@ -31,6 +31,11 @@ public class RemoteQAFallbackFactory implements FallbackFactory<RemoteQAService> | |||||
| public R<DmKnowledgeResponse> query(KnowledgeVo vo) { | public R<DmKnowledgeResponse> query(KnowledgeVo vo) { | ||||
| return R.fail("知识库查询失败"); | return R.fail("知识库查询失败"); | ||||
| } | } | ||||
| @Override | |||||
| public AjaxResult searchHotspot(KnowledgeVo vo) { | |||||
| return AjaxResult.error("查询失败"); | |||||
| } | |||||
| }; | }; | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,19 @@ | |||||
| package com.xueyi.job.task; | |||||
| import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | |||||
| @Component("dmGenerativeKnowledgeTask") | |||||
| public class DmSyncHotspotsTask { | |||||
| private static final Logger log = LoggerFactory.getLogger(DmSyncHotspotsTask.class); | |||||
| @Autowired | |||||
| private RemoteIntentService remoteIntentService; | |||||
| public void syncHotspot() { | |||||
| log.info("定时任务调度测试:向数字人下发实时热点"); | |||||
| remoteIntentService.syncHotspot(); | |||||
| } | |||||
| } | |||||
| @@ -24,13 +24,8 @@ import com.xueyi.common.security.annotation.RequiresPermissions; | |||||
| import com.xueyi.common.security.utils.SecurityUtils; | import com.xueyi.common.security.utils.SecurityUtils; | ||||
| import com.xueyi.common.web.entity.controller.BaseController; | import com.xueyi.common.web.entity.controller.BaseController; | ||||
| import com.xueyi.nlt.api.netty.domain.vo.DmWebSocketMessageVo; | 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.response.DmIntentResponse; | ||||
| import com.xueyi.nlt.api.nlt.domain.vo.CoversationSessionVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmIntentVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmLandingLlmVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.DmRecognitionVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.KnowledgeVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.TaskKnowledgeVo; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.response.DmKnowledgeResponse; | import com.xueyi.nlt.api.nlt.domain.vo.response.DmKnowledgeResponse; | ||||
| import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; | ||||
| import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; | import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; | ||||
| @@ -46,11 +41,9 @@ import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; | |||||
| import com.xueyi.nlt.nlt.domain.dto.DmSensitiveWordDto; | import com.xueyi.nlt.nlt.domain.dto.DmSensitiveWordDto; | ||||
| import com.xueyi.nlt.nlt.domain.po.DmRegularPo; | import com.xueyi.nlt.nlt.domain.po.DmRegularPo; | ||||
| import com.xueyi.nlt.nlt.domain.query.DmIntentQuery; | 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.NLPLogVo; | |||||
| import com.xueyi.nlt.nlt.domain.vo.*; | |||||
| import com.xueyi.nlt.nlt.mapper.DmRegularMapper; | import com.xueyi.nlt.nlt.mapper.DmRegularMapper; | ||||
| import com.xueyi.nlt.nlt.service.IDmHotspotService; | |||||
| import com.xueyi.nlt.nlt.service.IDmIntentService; | import com.xueyi.nlt.nlt.service.IDmIntentService; | ||||
| import com.xueyi.nlt.nlt.service.ISensitiveService; | import com.xueyi.nlt.nlt.service.ISensitiveService; | ||||
| import com.xueyi.nlt.nlt.service.ISysLlmService; | import com.xueyi.nlt.nlt.service.ISysLlmService; | ||||
| @@ -183,6 +176,9 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||||
| @Autowired | @Autowired | ||||
| private ISysLlmService sysLlmService; | private ISysLlmService sysLlmService; | ||||
| @Autowired | |||||
| private IDmHotspotService dmHotspotService; | |||||
| @Autowired | @Autowired | ||||
| MqttTemplate mqttTemplate; | MqttTemplate mqttTemplate; | ||||
| @@ -1173,6 +1169,35 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt | |||||
| return success(); | return success(); | ||||
| } | } | ||||
| @PostMapping("/inner/syncHotspot") | |||||
| @ResponseBody | |||||
| public AjaxResult syncHotspot(){ | |||||
| return dmHotspotService.syncHotspot(); | |||||
| } | |||||
| @PostMapping("/inner/collectHotspot") | |||||
| @ResponseBody | |||||
| public AjaxResult collectHotspot(@RequestBody List<HotspotVo> hotspotVo){ | |||||
| return dmHotspotService.collectHotspot(hotspotVo); | |||||
| } | |||||
| @PostMapping("/api/updateHotspot") | |||||
| @ResponseBody | |||||
| public AjaxResult updateHotspot(@RequestBody JSONObject hotspotData){ | |||||
| if(hotspotData == null||hotspotData.isEmpty()||!hotspotData.containsKey("data")){ | |||||
| return AjaxResult.error("上传热点新闻失败"); | |||||
| } | |||||
| log.info(hotspotData.getString("data")); | |||||
| List<HotspotVo> hotspotVoList = hotspotData.getList("data",HotspotVo.class); | |||||
| return dmHotspotService.collectHotspot(hotspotVoList); | |||||
| } | |||||
| @PostMapping("/api/testForHotspot") | |||||
| public AjaxResult testForHotspot(){ | |||||
| return dmHotspotService.syncHotspot(); | |||||
| } | |||||
| interface Auth { | interface Auth { | ||||
| /** 系统 - 意图管理 | /** 系统 - 意图管理 | ||||
| 管理 - 列表 */ | 管理 - 列表 */ | ||||
| @@ -0,0 +1,13 @@ | |||||
| package com.xueyi.nlt.nlt.service; | |||||
| import com.xueyi.common.core.web.result.AjaxResult; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||||
| import java.util.List; | |||||
| public interface IDmHotspotService { | |||||
| public AjaxResult syncHotspot(); | |||||
| public AjaxResult collectHotspot(List<HotspotVo> hotspotVo); | |||||
| } | |||||
| @@ -0,0 +1,61 @@ | |||||
| package com.xueyi.nlt.nlt.service.impl; | |||||
| import com.alibaba.fastjson2.JSONArray; | |||||
| import com.alibaba.fastjson2.JSONObject; | |||||
| import com.xueyi.common.core.web.result.AjaxResult; | |||||
| import com.xueyi.common.mqtt.connection.MqttTemplate; | |||||
| import com.xueyi.nlt.api.nlt.domain.vo.HotspotVo; | |||||
| import com.xueyi.nlt.nlt.service.IDmHotspotService; | |||||
| 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.context.annotation.Primary; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.time.LocalDateTime; | |||||
| import java.time.format.DateTimeFormatter; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @Service | |||||
| @Primary | |||||
| public class DmHotspotServiceImpl implements IDmHotspotService { | |||||
| private static final Logger log = LoggerFactory.getLogger(DmHotspotServiceImpl.class); | |||||
| @Autowired | |||||
| RedisTemplate<Object,Object> redisTemplate; | |||||
| @Autowired | |||||
| MqttTemplate mqttTemplate; | |||||
| @Value("${spring.profiles.active}") | |||||
| private String activeProfile; | |||||
| @Override | |||||
| public AjaxResult syncHotspot() { | |||||
| LocalDateTime dateTime = LocalDateTime.now(); | |||||
| String date = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | |||||
| String result = (String) redisTemplate.opsForHash().get("group:task:hotspot", date); | |||||
| log.info(result); | |||||
| JSONArray resultArray = JSONArray.parseArray(result); | |||||
| resultArray.stream().forEach(item -> JSONObject.from(item).remove("content")); | |||||
| Map<Object, Object> devices = redisTemplate.opsForHash().entries("group:dgman:device:"); | |||||
| for(Object devId:devices.keySet()){ | |||||
| mqttTemplate.sendToMqtt("/" + activeProfile + "/" + "digital_man" + "/" + devId.toString() + "/" + "notify" + "/" + "generate-hotspot", true, AjaxResult.success(resultArray).toJson().toJSONString()); | |||||
| } | |||||
| return AjaxResult.success(); | |||||
| } | |||||
| @Override | |||||
| public AjaxResult collectHotspot(List<HotspotVo> hotspotVoList) { | |||||
| LocalDateTime dateTime = LocalDateTime.now(); | |||||
| String date = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | |||||
| Long timestamp = System.currentTimeMillis(); | |||||
| hotspotVoList.stream().forEach(hotspotVo -> hotspotVo.setTimestamp(timestamp)); | |||||
| redisTemplate.opsForHash().put("group:task:hotspot", date, JSONArray.from(hotspotVoList).toJSONString()); | |||||
| return AjaxResult.success(); | |||||
| } | |||||
| } | |||||
| @@ -3,6 +3,9 @@ package com.xueyi.nlt.nlt.template; | |||||
| import com.alibaba.druid.util.StringUtils; | import com.alibaba.druid.util.StringUtils; | ||||
| import com.alibaba.fastjson2.JSONObject; | import com.alibaba.fastjson2.JSONObject; | ||||
| import com.xueyi.common.core.context.SecurityContextHolder; | 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.netty.client.WebSocketClientManager; | ||||
| import com.xueyi.nlt.nlt.context.TerminalSecurityContextHolder; | import com.xueyi.nlt.nlt.context.TerminalSecurityContextHolder; | ||||
| import com.xueyi.nlt.nlt.domain.LlmContext; | import com.xueyi.nlt.nlt.domain.LlmContext; | ||||
| @@ -33,6 +36,9 @@ public class FreeChatTemplate implements BaseTemplate{ | |||||
| @Autowired | @Autowired | ||||
| private RedisTemplate<String,String> redisTemplate; | private RedisTemplate<String,String> redisTemplate; | ||||
| @Autowired | |||||
| private RemoteQAService remoteQAService; | |||||
| private Map<String,String> correctWordsMap = new HashMap<>(); | private Map<String,String> correctWordsMap = new HashMap<>(); | ||||
| // 中航信领导来访临时对策 | // 中航信领导来访临时对策 | ||||
| @@ -57,12 +63,13 @@ public class FreeChatTemplate implements BaseTemplate{ | |||||
| List<String> context = new ArrayList<>(); | List<String> context = new ArrayList<>(); | ||||
| context.add("你是缔智元公司的前台,你叫小智,你是一位数字人。"); | context.add("你是缔智元公司的前台,你叫小智,你是一位数字人。"); | ||||
| context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | context.addAll(redisTemplate.opsForList().range(redisKey,size-6,size)); | ||||
| content = generatePrompts(content); | |||||
| context.add(content); | context.add(content); | ||||
| //webSocketClient.sendMsg(context); | //webSocketClient.sendMsg(context); | ||||
| LlmContext llmContext = LlmContext.parse(context,true); | LlmContext llmContext = LlmContext.parse(context,true); | ||||
| llmContext.setDevId(devId); | |||||
| LlmParam param = new LlmParam(); | LlmParam param = new LlmParam(); | ||||
| LlmResponse response = sysLlmService.chat(llmContext,param); | LlmResponse response = sysLlmService.chat(llmContext,param); | ||||
| String result = response.getContent(); | String result = response.getContent(); | ||||
| @@ -108,7 +115,7 @@ public class FreeChatTemplate implements BaseTemplate{ | |||||
| } | } | ||||
| //context.addAll(redisTemplate.opsForList().range(redisKey,size-2,size)); | //context.addAll(redisTemplate.opsForList().range(redisKey,size-2,size)); | ||||
| content = "请用简短的话回答下面的问题:" + content; | |||||
| content = generatePrompts(content); | |||||
| context.add(content); | context.add(content); | ||||
| //使用stream去除context列表中所有字符串中的引号 | //使用stream去除context列表中所有字符串中的引号 | ||||
| context = context.stream().map(s -> s.replaceAll("\"", "")).collect(java.util.stream.Collectors.toList()); | 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) { | public JSONObject handle(String dev, String content, Long tenantId) { | ||||
| return null; | 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; | |||||
| } | |||||
| } | } | ||||