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

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

Loading…
Cancel
Save