diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java index 48e9881..f67abfb 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.google.common.collect.Lists; import com.hnac.hzims.bigmodel.business.dto.RunReportAnalyseRequest; import com.hnac.hzims.bigmodel.business.feign.IAuthClient; -import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; @@ -21,6 +20,7 @@ import com.hnac.hzinfo.exception.HzServiceException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; @@ -29,6 +29,7 @@ import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.concurrent.TimeUnit; /** @@ -51,10 +52,11 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void ask(String question, String sessionId, String userId) { - Map params = new HashMap<>(); - params.put("chat_id",sessionId); + Map params = new HashMap<>(); + params.put("chat_id", sessionId); params.put("user_id", userId); - params.put("query",question); + params.put("query", question); + params.put("q_id", UUID.randomUUID()); Map authDataIds = this.getAuthDataIds(userId); params.putAll(authDataIds); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantAsk(), params); @@ -69,30 +71,34 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void specialAsk(String sessionId, String userId, Map extra) { - Map params = new HashMap<>(); - params.put("chat_id",sessionId); + Map params = new HashMap<>(); + params.put("chat_id", sessionId); params.put("user_id", userId); - params.put("extra",extra); + params.put("extra", extra); + params.put("q_id", UUID.randomUUID()); Map authDataIds = this.getAuthDataIds(userId); params.putAll(authDataIds); - log.info("调用大模型接口:{},传参为:{}",gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(),JSON.toJSONString(params)); + log.info("调用大模型接口:{},传参为:{}", gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), JSON.toJSONString(params)); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), params); sessionRedisManager.addSessionId(sessionId); } @Override public void specialAsk(QuestionDTO question) { - RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), JSON.toJSONString(question)); + Map questionMap = JsonUtil.toMap(JSON.toJSONString(question)); + questionMap.put("q_id", UUID.randomUUID()); + RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), JSON.toJSONString(questionMap)); sessionRedisManager.addSessionId(question.getChatId()); } @Override public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) { - Map params = new HashMap<>(); + Map params = new HashMap<>(); params.put("chat_id", sessionId); params.put("user_id", userId); params.put("query", question); params.put("knowledge", knowledge); + params.put("q_id", UUID.randomUUID()); Map authDataIds = this.getAuthDataIds(userId); params.putAll(authDataIds); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantKnowledgeAsk(), params); @@ -101,13 +107,17 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void knowledgeAsk(QuestionDTO question) { - RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantKnowledgeAsk(), JSON.toJSONString(question)); + Map questionMap = JsonUtil.toMap(JSON.toJSONString(question)); + questionMap.put("q_id", UUID.randomUUID()); + RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantKnowledgeAsk(), JSON.toJSONString(questionMap)); sessionRedisManager.addSessionId(question.getChatId()); } @Override public void analyseAsk(QuestionDTO question) { - RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantAnalyseAsk(), JSON.toJSONString(question)); + Map questionMap = JsonUtil.toMap(JSON.toJSONString(question)); + questionMap.put("q_id", UUID.randomUUID()); + RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantAnalyseAsk(), JSON.toJSONString(questionMap)); sessionRedisManager.addSessionId(question.getChatId()); } @@ -121,8 +131,8 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void askAbort(String sessionId) { - Map params = new HashMap<>(); - params.put("chat_id",sessionId); + Map params = new HashMap<>(); + params.put("chat_id", sessionId); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAskAbort(), params); sessionRedisManager.removeSessionId(sessionId); } @@ -131,73 +141,74 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { this.askAbort(sessionId); // 循环获取该会话ID中断状态,当状态等于-2或重连超6次则中断返回结果 int status = 999; - int attempts = 0; + int attempts = 0; while (status > 0) { // 若重连超过10次 则抛出错误 - if(attempts >= 8) { + if (attempts >= 8) { throw new HzServiceException("中断失败!长时间未获取到中断状态"); } List answers = this.getAnswerBySessionIds(sessionId); - if(Func.isNotEmpty(answers)) { - log.info(answers.get(0).getStatus()+""); + if (Func.isNotEmpty(answers)) { + log.info(answers.get(0).getStatus() + ""); status = answers.get(0).getStatus(); } // 若获取到的状态不等于2 则延时0.5秒 - if(status > 0) { + if (status > 0) { try { Thread.sleep(500); } catch (InterruptedException e) { throw new RuntimeException(e); } } - attempts ++; + attempts++; } } @Override public void smartReportGeneratePower(RunReportAnalyseRequest req) { - Map params = new HashMap<>(); + Map params = new HashMap<>(); String sessionId = IdWorker.get32UUID(); - params.put("chat_id",sessionId); + params.put("chat_id", sessionId); params.put("user_id", CommonConstant.SYSTEM_USER.toString()); params.put("data", req.getAnalyseDTOS()); params.put("query", ""); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getSmartReportGeneratePower(), params); // 将sessionId存入redis,拿到数据之后输入月报中 JSONObject report = new JSONObject(); - report.put("stationCode",req.getStationCode()); - report.put("month",req.getMonth()); - report.put("sessionId",sessionId); - redisTemplate.opsForList().leftPush(RedisKeyConstants.RUN_REPORT_SESSION_ID,JSON.toJSONString(report)); - redisTemplate.expire(RedisKeyConstants.RUN_REPORT_SESSION_ID,5, TimeUnit.MINUTES); + report.put("stationCode", req.getStationCode()); + report.put("month", req.getMonth()); + report.put("sessionId", sessionId); + redisTemplate.opsForList().leftPush(RedisKeyConstants.RUN_REPORT_SESSION_ID, JSON.toJSONString(report)); + redisTemplate.expire(RedisKeyConstants.RUN_REPORT_SESSION_ID, 5, TimeUnit.MINUTES); } @Override public void updateKnowledge(String name) { - Map params = new HashMap<>(); - params.put("name",name); + Map params = new HashMap<>(); + params.put("name", name); RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getUpdateKnowledge(), params); } @Override public List hotQuestions() { try { - return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference>(){}); - } - catch (Exception e) { - log.error("An error occurred",e); + return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference>() { + }); + } catch (Exception e) { + log.error("An error occurred", e); return Lists.newArrayList(); } } @Override public List getAnswerBySessionIds(String sessionIds) { - Map params = new HashMap<>(); - params.put("chat_ids",Func.toStrList(",",sessionIds).toArray()); - return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantStatus(), params, new TypeReference>(){}); + Map params = new HashMap<>(); + params.put("chat_ids", Func.toStrList(",", sessionIds).toArray()); + return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantStatus(), params, new TypeReference>() { + }); } - private Map getAuthDataIds(String userId) { + private Map getAuthDataIds(String userId) { Map result = new HashMap<>(2); R> authDataR = authClient.getAuthData(userId); result.putAll(authDataR.getData()); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java index 7b45d20..d1373ba 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java @@ -65,8 +65,8 @@ public class AgentLogServiceImpl extends ServiceImpl startStopTimeRecord() { String param = "";