diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index 550007c..5ca95c7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -39,8 +39,8 @@ public class InteractiveController { @ApiOperation("提问") @ApiOperationSupport(order = 2) @GetMapping("/ask") - public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId) { - return interactiveService.ask(question, sessionId); + public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId,@RequestParam @ApiParam("用户Id") String userId) { + return interactiveService.ask(question, sessionId, userId); } @ApiOperation("站点、菜单鉴权") 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 938b518..f497498 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 @@ -17,7 +17,7 @@ public interface IInteractiveService { R resolve(ModelFunctionReq req); - R ask(String question,String sessionId); + R ask(String question,String sessionId,String userId); List getAnswerBySessionIds(String sessionIds); 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 8d81e3b..92ce693 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 @@ -16,6 +16,7 @@ import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; @@ -46,11 +47,13 @@ public class InteractiveServiceImpl implements IInteractiveService { private final IJumpPageService jumpPageService; private final IFunctionService functionService; private final BigModelInvokeUrl bigModelInvokeUrl; + private final BladeLogger logger; @Value("${fdp.host}") private String fdpHost; @Override public R resolve(ModelFunctionReq req) { + logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); //TODO 数据鉴权 FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); @@ -68,8 +71,7 @@ public class InteractiveServiceImpl implements IInteractiveService { } @Override - public R ask(String question,String sessionId) { - Long userId = AuthUtil.getUserId(); + public R ask(String question,String sessionId,String userId) { //TODO 保存问题 Map params = new HashMap<>(); params.put("id",sessionId); @@ -77,10 +79,11 @@ public class InteractiveServiceImpl implements IInteractiveService { params.put("query",question); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { - throw new ServiceException("远程调用大模型【发起问答】接口失败!"); - }); - return R.data(JSONObject.parseObject(response.body()).getString("data")); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【发起问答】接口失败!"); + return R.fail("远程调用大模型【发起问答】接口失败!"); + } + return R.success("消息发送成功"); } @Override @@ -89,11 +92,11 @@ public class InteractiveServiceImpl implements IInteractiveService { params.put("ids",sessionIds); HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { + logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); - String data = JSONObject.parseObject(response.body()).getString("data"); - return JSONArray.parseArray(data,AnswerVO.class); + return JSONArray.parseArray(response.body(),AnswerVO.class); } @Override diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index 3ddf2f7..25ea4a8 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -68,9 +68,12 @@ public class InteractiveSchedule { @XxlJob(GET_INTERACTIVE_RESULT) public ReturnT execute(String params) { List sessionIds = InteractiveSessionManager.getSessionIds(); + XxlJobLogger.log("开始获取到sessionId:"+sessionIds); List AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); + XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); AnswerList.parallelStream().forEach(answerVO -> { CompletableFuture.runAsync(() -> { + XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); wsService.sendMessage(session,message); 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 551e5f7..a2dc3c6 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 @@ -60,9 +60,10 @@ public class InteractiveHandler extends TextWebSocketHandler { else { // 发送问题 String context = messageJSON.getString("context"); + String userId = messageJSON.getString("userId"); IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); - R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey()); - log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult)); + R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey(), userId); + log.info("返回结果为:"+ JSON.toJSONString(askResult)); } } }