|
|
@@ -20,6 +20,7 @@ import com.xueyi.common.log.annotation.Log; |
|
|
|
import com.xueyi.common.log.enums.BusinessType; |
|
|
|
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.response.DmIntentResponse; |
|
|
@@ -34,6 +35,7 @@ import com.xueyi.nlt.api.nlt.feign.RemoteIntentService; |
|
|
|
import com.xueyi.nlt.api.nlt.feign.RemoteLandingLlmService; |
|
|
|
import com.xueyi.nlt.api.nlt.feign.RemoteQAService; |
|
|
|
import com.xueyi.nlt.netty.client.WebSocketClientManager; |
|
|
|
import com.xueyi.nlt.nlt.config.LagiConfig; |
|
|
|
import com.xueyi.nlt.nlt.config.XunFeiSensitiveConfig; |
|
|
|
import com.xueyi.nlt.nlt.context.TerminalSecurityContextHolder; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmContext; |
|
|
@@ -43,6 +45,7 @@ import com.xueyi.nlt.nlt.domain.dto.DmIntentDto; |
|
|
|
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.mapper.DmRegularMapper; |
|
|
@@ -58,6 +61,7 @@ import com.xueyi.system.api.digitalmans.feign.RemoteDigitalmanService; |
|
|
|
import com.xueyi.system.api.digitalmans.feign.RemoteManDeviceService; |
|
|
|
import com.xueyi.system.api.digitalmans.feign.RemoteQuestionanswersService; |
|
|
|
import com.xueyi.system.api.digitalmans.feign.RemoteSkillService; |
|
|
|
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; |
|
|
@@ -329,6 +333,16 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
public AjaxResult searchQA( DmKnowledgeLibAskVo vo) { |
|
|
|
KnowledgeVo knowledgeVo = new KnowledgeVo(); |
|
|
|
knowledgeVo.setManCode(null); |
|
|
|
knowledgeVo.setTenantId(vo.getEnterpriseId()); |
|
|
|
knowledgeVo.setQuestion(vo.getQuestion()); |
|
|
|
R<DmKnowledgeResponse> dmKnowledgeResponseR = remoteQAService.query(knowledgeVo); |
|
|
|
|
|
|
|
return AjaxResult.success(dmKnowledgeResponseR); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 联动北方大模型请求 |
|
|
@@ -385,12 +399,15 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return AjaxResult.success(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String category = LagiConfig.tenantCategoryMap.get(enterpriseName); |
|
|
|
if (StringUtils.isEmpty(category)) { |
|
|
|
category = "airport"; |
|
|
|
} |
|
|
|
JSONObject joResult = new JSONObject(); |
|
|
|
joResult.put("msg",""); |
|
|
|
joResult.put("target",0); |
|
|
|
DmLandingLlmVo vo = new DmLandingLlmVo(); |
|
|
|
vo.setCategory("airport"); |
|
|
|
vo.setCategory(category); |
|
|
|
vo.addDmLlm("user", intent.getContent()); |
|
|
|
JSONObject testJ = new JSONObject(); |
|
|
|
testJ.put("category","airport"); |
|
|
@@ -400,7 +417,7 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
jo.put("content",intent.getContent()); |
|
|
|
ja1.add(jo); |
|
|
|
testJ.put("messages",ja1); |
|
|
|
JSONObject resultJson = remoteLandingLlmService.query(testJ); |
|
|
|
JSONObject resultJson = remoteLandingLlmService.query(category,testJ); |
|
|
|
log.info("北方大返回:{}",resultJson.toString()); |
|
|
|
if (resultJson.get("status").equals("success")) { |
|
|
|
JSONArray ja = resultJson.getJSONArray("data"); |
|
|
@@ -451,6 +468,88 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/knowledgeQuery") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult knowledgeQuery(@RequestBody DmKnowledgeLibAskVo knowledgeLibAskVo) { |
|
|
|
log.info("用户信息:{}",knowledgeLibAskVo); |
|
|
|
// 获取用户信息 |
|
|
|
LoginUser user = SecurityUtils.getLoginUser(); |
|
|
|
String enterpriseId = (String)SecurityContextHolder.getLocalMap().get("enterprise_id"); |
|
|
|
R<SysEnterpriseDto> enterpriseDtoR = enterpriseService.getInfo(Long.parseLong(enterpriseId)); |
|
|
|
Source source = SourceUtil.getSourceCache(enterpriseDtoR.getData().getStrategyId()); |
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
// 通过知识库查询数据 |
|
|
|
if (knowledgeLibAskVo.getType() == 0) { |
|
|
|
// 知识库查询 |
|
|
|
AjaxResult qaAjax = searchQA(knowledgeLibAskVo); |
|
|
|
log.info("知识库返回:{}",qaAjax.toString()); |
|
|
|
String content = ""; |
|
|
|
JSONObject qaJson = qaAjax.toJson(); |
|
|
|
if (qaJson.containsKey("data") && qaJson.getJSONObject("data").getString("accurate").equals("1")) { |
|
|
|
JSONObject answer = qaJson.getJSONObject("data").getJSONArray("result").getJSONObject(0); |
|
|
|
if (answer!= null) { |
|
|
|
result.put("text",answer.getString("answer")); |
|
|
|
result.put("type","1"); |
|
|
|
} |
|
|
|
return AjaxResult.success(result); |
|
|
|
} |
|
|
|
} else { |
|
|
|
JSONObject joResult = new JSONObject(); |
|
|
|
joResult.put("msg",""); |
|
|
|
joResult.put("target",0); |
|
|
|
DmLandingLlmVo vo = new DmLandingLlmVo(); |
|
|
|
vo.setCategory(knowledgeLibAskVo.getName()); |
|
|
|
vo.addDmLlm("user", user.getUserName()); |
|
|
|
JSONObject testJ = new JSONObject(); |
|
|
|
testJ.put("category",knowledgeLibAskVo.getName()); |
|
|
|
JSONArray ja1 = new JSONArray(); |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("role","user"); |
|
|
|
jo.put("content",knowledgeLibAskVo.getQuestion()); |
|
|
|
ja1.add(jo); |
|
|
|
testJ.put("messages",ja1); |
|
|
|
String gatewayheader = LagiConfig.tenantLlmMap.get(enterpriseDtoR.getData().getName()); |
|
|
|
gatewayheader = StringUtils.isEmpty(gatewayheader) ? "": gatewayheader; |
|
|
|
JSONObject resultJson = remoteLandingLlmService.query(gatewayheader,testJ); |
|
|
|
log.info("北方大返回:{}",resultJson.toString()); |
|
|
|
if (resultJson.get("status").equals("success")) { |
|
|
|
JSONArray ja = resultJson.getJSONArray("data"); |
|
|
|
if (ja.size() > 0) { |
|
|
|
String text = ja.getJSONObject(0).getString("text"); |
|
|
|
result.put("type","5"); |
|
|
|
result.put("text",text); |
|
|
|
result.put("llm","lagi"); |
|
|
|
if (ja.getJSONObject(0).containsKey("filename")) { |
|
|
|
// TODO: 2023/9/27 合并知识到知识库 |
|
|
|
String libName = ja.getJSONObject(0).getString("filename").split("\\.")[0]; |
|
|
|
// 添加到知识数据库 |
|
|
|
result.put("fileName",libName); |
|
|
|
} |
|
|
|
if (ja.getJSONObject(0).containsKey("imageList") && ja.getJSONObject(0).getJSONArray("imageList").size() > 0) { |
|
|
|
JSONObject joImage = new JSONObject(); |
|
|
|
result.put("imageUrl",ja.getJSONObject(0).getJSONArray("imageList").getString(0)); |
|
|
|
} |
|
|
|
if (ja.getJSONObject(0).containsKey("context")) { |
|
|
|
result.put("context",ja.getJSONObject(0).getString("context")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 判断知识库类型,如果是1,调用searchQA(),如果是2,调用remoteLandingLlmService.query() |
|
|
|
return AjaxResult.success(result); |
|
|
|
} |
|
|
|
@PostMapping("/give_a_like") |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult giveALike(@RequestBody MarkRecordVo recordVo) { |
|
|
|
// 获取缓存nlt:record:origin前十的列表 |
|
|
|
if (redisTemplate2.opsForHash().hasKey("nlt:record:origin",String.valueOf(recordVo.getId()))) { |
|
|
|
redisTemplate.opsForList().rightPush("nlt:record:marked", JSONObject.toJSONString(recordVo)); |
|
|
|
redisTemplate.opsForHash().delete("nlt:record:origin",String.valueOf(recordVo.getId())); |
|
|
|
} |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 意图请求列表 |
|
|
@@ -632,6 +731,8 @@ public class DmIntentController extends BaseController<DmIntentQuery, DmIntentDt |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 意图请求 |
|
|
|
列表 |
|
|
|