Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
zhongwei
haungxing 7 months ago
parent
commit
7e360f2eb5
  1. 26
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  2. 51
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  3. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java
  4. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java

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

@ -30,10 +30,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import java.util.*;
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -49,15 +49,25 @@ import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*;
@RequiredArgsConstructor @RequiredArgsConstructor
public class InteractiveServiceImpl implements IInteractiveService { public class InteractiveServiceImpl implements IInteractiveService {
private final BladeLogger logger;
private final IJumpPageService jumpPageService; private final IJumpPageService jumpPageService;
private final IFunctionService functionService; private final IFunctionService functionService;
private final BigModelInvokeUrl bigModelInvokeUrl; private final BigModelInvokeUrl bigModelInvokeUrl;
private final BladeLogger logger;
private final IDeptClient deptClient; private final IDeptClient deptClient;
private final IUserClient userClient; private final IUserClient userClient;
private final RedisTemplate redisTemplate;
@Value("${fdp.host}") @Value("${fdp.host}")
private String fdpHost; private String fdpHost;
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key";
@Override @Override
public R resolve(ModelFunctionReq req) { public R resolve(ModelFunctionReq req) {
logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req));
@ -80,7 +90,7 @@ public class InteractiveServiceImpl implements IInteractiveService {
public R ask(String question,String sessionId,String userId) { public R ask(String question,String sessionId,String userId) {
Map<String,Object> params = new HashMap<>(); Map<String,Object> params = new HashMap<>();
params.put("id",sessionId); params.put("id",sessionId);
params.put("userid",userId.toString()); params.put("userid", userId);
params.put("query",question); params.put("query",question);
params.put("stationids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); params.put("stationids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).toArray()); params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).toArray());
@ -90,6 +100,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
log.error("远程调用大模型【发起问答】接口失败!"); log.error("远程调用大模型【发起问答】接口失败!");
return R.fail("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!");
} }
// 添加redis问题会话
List<String> asks = (List<String>) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
if(CollectionUtil.isEmpty(asks)){
asks = Collections.singletonList(sessionId);
}else{
asks.add(sessionId);
}
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,asks);
return R.success("消息发送成功"); return R.success("消息发送成功");
} }

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

@ -3,31 +3,23 @@ package com.hnac.hzims.bigmodel.schedule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
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.server.InteractiveWsServer;
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; 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.log.exception.ServiceException; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.ParamCache;
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.util.Assert;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.GET_INTERACTIVE_RESULT;
/** /**
* @Author: huangxing * @Author: huangxing
@ -37,11 +29,16 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*;
@AllArgsConstructor @AllArgsConstructor
public class InteractiveSchedule { public class InteractiveSchedule {
private final RedisTemplate redisTemplate;
private final InteractiveWsService wsService; private final InteractiveWsService wsService;
private final IInteractiveService interactiveService; private final IInteractiveService interactiveService;
private final ThreadPoolExecutor getAnswerPoolExecutor; private final ThreadPoolExecutor getAnswerPoolExecutor;
private final RedisTemplate redisTemplate;
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key";
// @XxlJob(GET_INTERACTIVE_RESULT) // @XxlJob(GET_INTERACTIVE_RESULT)
// public ReturnT execute(String params) { // public ReturnT execute(String params) {
// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT);
@ -68,17 +65,27 @@ public class InteractiveSchedule {
@XxlJob(GET_INTERACTIVE_RESULT) @XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT execute(String params) { public ReturnT execute(String params) {
List<String> sessionIds = InteractiveSessionManager.getSessionIds(); List<String> sessionIds = InteractiveSessionManager.getSessionIds();
XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(","))); XxlJobLogger.log("开始获取到sessionId:"+ String.join(",", sessionIds));
List<AnswerVO> AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds));
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); XxlJobLogger.log("获取到答案:"+JSON.toJSONString(answerList));
AnswerList.parallelStream().forEach(answerVO -> { answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> {
CompletableFuture.runAsync(() -> { XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!");
XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); List<String> asks = (List<String>) redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); // 问题回答完成,去除redis问题标记
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); if(answerVO.getStatus() == 0){
wsService.sendMessage(session,message); if(CollectionUtil.isNotEmpty(asks) && asks.contains(answerVO.getSessionId())){
}, getAnswerPoolExecutor); 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,asks);
return;
}
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message);
}, getAnswerPoolExecutor));
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }
} }

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

@ -56,8 +56,7 @@ public class InteractiveHandler extends TextWebSocketHandler {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }else {
else {
// 发送问题 // 发送问题
String context = messageJSON.getString("context"); String context = messageJSON.getString("context");
String userId = messageJSON.getString("userId"); String userId = messageJSON.getString("userId");

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java

@ -60,7 +60,7 @@ public class GenerateServiceImpl extends BaseServiceImpl<GenerateMapper, Generat
if(!ObjectUtil.isEmpty(filter.getDataOrigin())){ if(!ObjectUtil.isEmpty(filter.getDataOrigin())){
eq("DATA_ORIGIN",filter.getDataOrigin()); eq("DATA_ORIGIN",filter.getDataOrigin());
} }
orderByDesc("create_time"); orderByDesc("FILL_DATE");
}}; }};
IPage pages = super.page(Condition.getPage(query), queryWrapper); IPage pages = super.page(Condition.getPage(query), queryWrapper);
List list = GenerateWrapper.build().listVO(pages.getRecords()); List list = GenerateWrapper.build().listVO(pages.getRecords());

Loading…
Cancel
Save