Browse Source

#大模型限制问题完成不在进行消息推送

zhongwei
yang_shj 7 months ago
parent
commit
218a2499cd
  1. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  2. 31
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -21,6 +21,7 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.dto.DeptStationDTO; import org.springblade.system.dto.DeptStationDTO;
import org.springblade.system.feign.IDeptClient; import org.springblade.system.feign.IDeptClient;
@ -102,13 +103,15 @@ public class InteractiveServiceImpl implements IInteractiveService {
return R.fail("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!");
} }
// 添加redis问题会话 // 添加redis问题会话
List<String> asks = (List<String>) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
if(CollectionUtil.isEmpty(asks)){ if(ObjectUtil.isEmpty(json)){
asks = Collections.singletonList(sessionId); List<String> asks = Collections.singletonList(sessionId);
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks));
}else{ }else{
List<String> asks = JSONObject.parseArray(json.toString(),String.class);
asks.add(sessionId); asks.add(sessionId);
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks));
} }
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks);
return R.success("消息发送成功"); return R.success("消息发送成功");
} }

31
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

@ -1,6 +1,7 @@
package com.hnac.hzims.bigmodel.schedule; package com.hnac.hzims.bigmodel.schedule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService;
@ -10,6 +11,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
@ -70,21 +72,24 @@ public class InteractiveSchedule {
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList)); XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList));
answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> {
XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!");
List<String> asks = (List<String>) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
// 问题回答完成,去除redis问题标记 if(ObjectUtil.isNotEmpty(json)){
if(answerVO.getStatus() == 0){ List<String> asks = JSONObject.parseArray(json.toString(),String.class);
if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){ // 问题回答完成,去除redis问题标记
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); if(answerVO.getStatus() == 0){
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){
wsService.sendMessage(session,message); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message);
}
asks.remove(answerVO.getSessionId());
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(asks));
} }
asks.remove(answerVO.getSessionId()); }else{
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
return; TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message);
} }
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message);
}, getAnswerPoolExecutor)); }, getAnswerPoolExecutor));
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }

Loading…
Cancel
Save