Browse Source

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

zhongwei
yang_shj 7 months ago
parent
commit
59300d8cc9
  1. 48
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

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

@ -59,50 +59,28 @@ public class InteractiveSchedule {
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key";
// @XxlJob(GET_INTERACTIVE_RESULT)
// public ReturnT execute(String params) {
// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT);
// Set<String> keySet = redisTemplate.keys(resultKey + "*");
// keySet.parallelStream().forEach(key -> {
// // 根据Key获取sessionId
// List<String> keySplits = Func.toStrList(":", key);
// String sessionId = keySplits.get(2);
// // 查询websocket是否存在连接session
// WebSocketSession session = InteractiveSessionManager.get(sessionId);
// if(session == null) {
// return;
// }
// TextMessage message = new TextMessage(JSON.toJSONString(redisTemplate.opsForValue().get(key)));
// Boolean sendResult = wsService.sendMessage(sessionId, message);
// Assert.isTrue(sendResult, () -> {
// throw new ServiceException(key + "推送消息失败,推送消息体为:" + JSON.toJSONString(redisTemplate.opsForValue().get(key)));
// });
// redisTemplate.delete(key);
// });
// return ReturnT.SUCCESS;
// }
@XxlJob(GET_INTERACTIVE_RESULT) @XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT getInteractiveResult(String params) { public ReturnT getInteractiveResult(String params) {
List<String> sessionIds = StringUtil.isNotBlank(params) && Func.isNotEmpty(params) ? Func.toStrList(",",params) : InteractiveSessionManager.getSessionIds(); Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds)); if(ObjectUtil.isEmpty(json)){
XxlJobLogger.log("未获取到问题标识,或者用户未进行提问!");
return ReturnT.SUCCESS;
}
List<String> sessionIds = JSONObject.parseArray(json.toString(),String.class);
if(CollectionUtil.isEmpty(sessionIds)){
XxlJobLogger.log("问题都已经回答完毕!");
return ReturnT.SUCCESS;
}
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds));
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() + "答案!");
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
if(ObjectUtil.isNotEmpty(json)){
List<String> asks = JSONObject.parseArray(json.toString(),String.class);
// 问题回答完成,去除redis问题标记 // 问题回答完成,去除redis问题标记
if(answerVO.getStatus() == 0){ if(answerVO.getStatus() == 0){
if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message); wsService.sendMessage(session,message);
} sessionIds.remove(answerVO.getSessionId());
asks.remove(answerVO.getSessionId()); redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds));
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(asks));
}
}else{ }else{
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));

Loading…
Cancel
Save