diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java index 7f8d6d5..8179cba 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -27,4 +27,5 @@ public class BigModelInvokeUrl { private String updateCanvas; + private String assistantKnowledgeAsk; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java index 40b06ea..241a25b 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java @@ -2,11 +2,8 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import io.swagger.annotations.ApiParam; import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.RequestParam; -import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; @@ -33,4 +30,14 @@ public interface IInteractiveService { Boolean authentication(String stationId, String userId, String func); Boolean removeSessionId(String sessionId); + + /** + * 发起知识库问答 + * @param question 问题 + * @param sessionId 会话id + * @param userId 用户id + * @param knowledge 知识库名称 + * @return 发起结果 + */ + R knowledgeAsk(String question, String sessionId, String userId, String knowledge); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index 4e835a0..f150638 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -246,6 +246,31 @@ public class InteractiveServiceImpl implements IInteractiveService { return true; } + /** + * 发起知识库问答 + */ + @Override + public R knowledgeAsk(String question, String sessionId, String userId, String knowledge) { + Map params = new HashMap<>(); + params.put("id", sessionId); + params.put("userid", userId); + params.put("query", question); + params.put("knowledge", knowledge); + params.put("stationids", this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) + .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); + params.put("projectids", this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId) + .filter(Func::isNotEmpty).map(String::valueOf).toArray()); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk()) + .body(JSON.toJSONString(params)).execute(); + logger.info("interactive:knowledgeAsk", "知识库问答传参为:" + JSON.toJSONString(params) + " 结果为:" + response.body()); + if (response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【发起知识库问答】接口失败!"); + return R.fail("远程调用大模型【发起知识库问答】接口失败!"); + } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + private List getStationPermissionsById(String userId) { R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index 96dfc4e..585b15e 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -62,20 +62,26 @@ public class InteractiveHandler extends TextWebSocketHandler { } catch (IOException e) { throw new RuntimeException(e); } - }else { + } else { String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); - this.handleMessage(messageJSON,sessionId); + this.handleMessage(messageJSON, sessionId); } } - private void handleMessage(JSONObject messageContext,String sessionId) { + private void handleMessage(JSONObject messageContext, String sessionId) { Boolean isSpecial = messageContext.getBoolean("isSpecial"); - if(Func.isEmpty(isSpecial) || !isSpecial) { + if (Func.isEmpty(isSpecial) || !isSpecial) { String context = messageContext.getString("context"); String userId = messageContext.getString("userId"); + String knowledge = messageContext.getString("knowledge"); IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); - R askResult = interactiveService.ask(context, sessionId, userId); - log.info("返回结果为:"+ JSON.toJSONString(askResult)); + if (knowledge != null) { + R askResult = interactiveService.knowledgeAsk(context, sessionId, userId, knowledge); + log.info("知识库问答返回结果:" + JSON.toJSONString(askResult)); + } else { + R askResult = interactiveService.ask(context, sessionId, userId); + log.info("返回结果为:"+ JSON.toJSONString(askResult)); + } } else { String funcCode = messageContext.getString("funcCode");