Browse Source

fix:大模型架构调整

zhongwei
haungxing 7 months ago
parent
commit
0ad8854306
  1. 0
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java
  2. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java
  3. 46
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java
  4. 44
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java
  5. 22
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java
  6. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java
  7. 63
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  8. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  9. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java
  10. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java
  11. 17
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java
  12. 33
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java
  13. 47
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java
  14. 23
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java
  15. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java
  16. 16
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java
  17. 120
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  18. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  19. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java
  20. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  21. 23
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java
  22. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java
  23. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java
  24. 23
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java
  25. 73
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java
  26. 7
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java
  27. 29
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java
  28. 28
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java
  29. 48
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java

0
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java

@ -0,0 +1,11 @@
package com.hnac.hzims.bigmodel.interactive.constants;
/**
* @Author: huangxing
* @Date: 2024/06/21 16:35
*/
public interface InfoMessageConstant {
String ERROR_MESSAGE = "非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。";
}

46
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java

@ -0,0 +1,46 @@
package com.hnac.hzims.bigmodel.interactive.factory;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
/**
* @Author: huangxing
* @Date: 2024/06/21 18:44
*/
public class AnswerResolveFactory {
public static final String DIAGNOSE_ANSWER_SERVICE = "diagnoseAnswerResolveService";
public static final String CHOICE_ANSWER_SERVICE = "choiceAnswerResolveService";
public static final String REMOTE_ANSWER_SERVICE = "remoteAnswerResolveService";
public static final String PARAM_ANSWER_SERVICE = "paramAnswerResolveService";
public static IResolveService getResolveService(String funcCode) {
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode);
if(Func.isNotEmpty(funcRouteEnum)) {
switch (funcRouteEnum) {
case DIAGNOSE:
return SpringUtil.getBean(DIAGNOSE_ANSWER_SERVICE);
case CHOOSE_VIDEO:
case CHOOSE_CANVAS:
case CHOOSE_STATION:
case CHOOSE_FAULT:
case CHOOSE_YC:
case CHOOSE_YK:
return SpringUtil.getBean(CHOICE_ANSWER_SERVICE);
case CONFIRM_YK:
return SpringUtil.getBean(REMOTE_ANSWER_SERVICE);
case SHOW_PARAM:
return SpringUtil.getBean(PARAM_ANSWER_SERVICE);
default:
throw new ServiceException("service解析失败!");
}
}
throw new ServiceException("service解析失败!");
}
}

44
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java

@ -0,0 +1,44 @@
package com.hnac.hzims.bigmodel.interactive.factory;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.function.service.IFunctionService;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
/**
* @Author: huangxing
* @Date: 2024/06/21 15:53
*/
public class ResolveFactory {
public static final String CANVAS_RESOLVE_SERVICE = "canvasResolveService";
public static final String VIDEO_RESOLVE_SERVICE = "videoResolveService";
/**
* 获取解析函数需要的service
* @param funcCode 函数编号
* @return 解析函数所需service
*/
public static IResolveService getResolveService(String funcCode) {
BladeLogger logger = SpringUtil.getBean(BladeLogger.class);
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode);
if(Func.isNotEmpty(funcRouteEnum)) {
switch(funcRouteEnum) {
case OPEN_CANVAS:
return SpringUtil.getBean("canvasResolveService");
case OPEN_VIDEO:
return SpringUtil.getBean("videoResolveService");
default:
logger.error("hzims:bigModel:getResolveService","函数解析失败,函数编号为:" + funcCode);
throw new ServiceException("service解析失败");
}
}
throw new ServiceException("service解析失败");
}
}

22
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java

@ -0,0 +1,22 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import java.util.Arrays;
import java.util.stream.Stream;
/**
* @Author: huangxing
* @Date: 2024/06/21 18:39
*/
public interface IAnswerResolveService {
AnswerVO resolve(AnswerVO answer);
default Stream<JSONObject> extraStream(AnswerVO answer) {
return Arrays.stream(answer.getExtras()).map(JSON::toJSONString).map(JSONObject::parseObject);
}
}

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java

@ -1,7 +1,9 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;
@ -15,4 +17,5 @@ public interface IHznlmInteractiveService {
List<AuthDataVO> getAuthData(@RequestBody @Valid AuthDataDTO req);
ResolveResultVO resolve(ModelFunctionReq req);
}

63
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java

@ -0,0 +1,63 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import org.springblade.core.tool.api.R;
import java.util.List;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/06/21 17:20
*/
public interface IHznlmInvokeService {
/**
* 基础问题
* @param question 提问问题
* @param sessionId 会话ID
* @param userId 提问人ID
* @return 提问结果
*/
void ask(String question, String sessionId, String userId);
/**
* 特殊问题
* @param sessionId 会话ID
* @param userId 提问人ID
* @param extra 特殊问题内容
* @return 提问结果
*/
void specialAsk(String sessionId, String userId, Map<String,Object> extra);
/**
* 知识库问题
* @param question 问题名称
* @param sessionId 会话ID
* @param userId 提问人ID
* @param knowledge 知识库名称
*/
void knowledgeAsk(String question, String sessionId, String userId, String knowledge);
/**
* 删除对话记录
* @param sessionId 会话ID
*/
void removeSessionId(String sessionId);
/**
* 获取热点问题
* @return 热点问题
*/
List hotQuestions();
/**
* 查询问答状态
* @param sessionIds 会话ID按逗号分隔
* @return 答案列表
*/
List<AnswerVO> getAnswerBySessionIds(String sessionIds);
}

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java

@ -13,6 +13,7 @@ import java.util.Map;
* @Author: huangxing
* @Date: 2024/04/26 14:51
*/
@Deprecated
public interface IInteractiveService {
ExtraVO resolveStations(String startTime, String endTime, String type, String enumType);

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java

@ -9,6 +9,7 @@ import java.util.Map;
* @Author: huangxing
* @Date: 2024/04/26 11:46
*/
@Deprecated
public interface IJumpPageService {
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args);

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java

@ -8,6 +8,7 @@ import java.util.Map;
* @Author: huangxing
* @Date: 2024/05/09 08:50
*/
@Deprecated
public interface IParamsService {
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args);

17
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java

@ -0,0 +1,17 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
/**
* @Author: huangxing
* @Date: 2024/06/21 15:39
*/
public interface IResolveService {
ExtraVO resolve(Long id);
ResolveResultVO resolve(ModelFunctionReq req);
}

33
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java

@ -0,0 +1,33 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import com.hnac.hzinfo.sdk.v5.scada.ScadaClient;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @Author: huangxing
* @Date: 2024/06/21 15:39
*/
@Service(ResolveFactory.CANVAS_RESOLVE_SERVICE)
@AllArgsConstructor
@Slf4j
public class CanvasResolveServiceImpl implements IResolveService {
private final ScadaClient scadaClient;
@Override
public ResolveResultVO resolve(ModelFunctionReq req) {
return null;
}
@Override
public ExtraVO resolve(Long id) {
return null;
}
}

47
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java

@ -0,0 +1,47 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory;
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: huangxing
* @Date: 2024/06/21 19:02
* @Describe 选项答案解析服务层
*/
@AllArgsConstructor
@Service(AnswerResolveFactory.CHOICE_ANSWER_SERVICE)
@Slf4j
public class ChoiceAnswerResolveServiceImpl implements IAnswerResolveService {
@Override
public AnswerVO resolve(AnswerVO answer) {
List<ExtraVO> extraList = this.extraStream(answer).map(this::getExtra).collect(Collectors.toList());
answer.setExtras(extraList.toArray());
return answer;
}
private ExtraVO getExtra(JSONObject originExtra) {
ExtraVO result = new ExtraVO();
JSONArray selections = JSONArray.parseArray(JSON.toJSONString(originExtra.get("data")));
result.setSelection(selections);
result.setSpecial(true);
String funcCode = originExtra.getString("func");
result.setFuncCode(funcCode);
result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType());
return result;
}
}

23
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java

@ -0,0 +1,23 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory;
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @Author: huangxing
* @Date: 2024/06/21 18:59
*/
@Service(AnswerResolveFactory.DIAGNOSE_ANSWER_SERVICE)
@Slf4j
@AllArgsConstructor
public class DiagnoseAnswerResolveServiceImpl implements IAnswerResolveService {
@Override
public AnswerVO resolve(AnswerVO answer) {
return null;
}
}

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java

@ -36,6 +36,7 @@ import java.util.stream.Collectors;
*/
@Service
@AllArgsConstructor
@Deprecated
public class ExtraResolveStrategyService {
public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS";

16
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java

@ -2,8 +2,12 @@ package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum;
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO;
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
@ -21,7 +25,7 @@ import java.util.stream.Collectors;
@Service
@AllArgsConstructor
@Slf4j
public class HzllmInteractiveServiceImpl implements IHznlmInteractiveService {
public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService {
private final AuthenticationService authenticationService;
@ -38,6 +42,16 @@ public class HzllmInteractiveServiceImpl implements IHznlmInteractiveService {
}
}
@Override
public ResolveResultVO resolve(ModelFunctionReq req) {
IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName());
try {
return resolveService.resolve(req);
} catch (Exception e) {
return ResolveResultVO.error();
}
}
public List<AuthDataVO> getDeptAuthData(String userId) {
List<DeptStationDTO> deptStationDTOs = authenticationService.getStationPermissionsById(userId);
return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList());

120
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java

@ -0,0 +1,120 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.manager.SessionRedisManager;
import com.hnac.hzims.bigmodel.utils.RequestClientUtil;
import com.xxl.job.core.log.XxlJobLogger;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
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.StringUtil;
import org.springblade.system.dto.DeptStationDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/06/21 17:20
* @Describe HZN_LM大模型接口调用服务层
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
private final AuthenticationService authenticationService;
private final BigModelInvokeUrl bigModelInvokeUrl;
private final BladeLogger logger;
private final SessionRedisManager sessionRedisManager;
@Value("${fdp.host}")
private String fdpHost;
@Override
public void ask(String question, String sessionId, String userId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("query",question);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
params.putAll(authDataIds);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), params);
sessionRedisManager.addSessionId(sessionId);
}
@Override
public void specialAsk(String sessionId, String userId, Map<String, Object> extra) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("extra",extra);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
params.putAll(authDataIds);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params);
sessionRedisManager.addSessionId(sessionId);
}
@Override
public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) {
Map<String,Object> params = new HashMap<>();
params.put("id", sessionId);
params.put("userid", userId);
params.put("query", question);
params.put("knowledge", knowledge);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
params.putAll(authDataIds);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params);
sessionRedisManager.addSessionId(sessionId);
}
@Override
public void removeSessionId(String sessionId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params);
sessionRedisManager.removeSessionId(sessionId);
}
@Override
public List hotQuestions() {
return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getHotQuestion(), null, List.class);
}
@Override
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,Object> params = new HashMap<>();
params.put("ids",Func.toStrList(",",sessionIds).toArray());
List<AnswerVO> answerVOList = RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, List.class);
//TODO 解析答案
return answerVOList;
}
private Map<String,String[]> getAuthDataIds(String userId) {
List<DeptStationDTO> authDatas = authenticationService.getStationPermissionsById(userId);
Map<String, String[]> result = new HashMap<>(2);
String[] stationIds = authDatas.stream().map(DeptStationDTO::getStationId)
.filter(StringUtil::isNotBlank).toArray(String[]::new);
String[] projectIds = authDatas.stream().map(DeptStationDTO::getDeptId)
.filter(Func::isNotEmpty).toArray(String[]::new);
result.put("stationids", stationIds);
result.put("projectids", projectIds);
return result;
}
}

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

@ -70,6 +70,7 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMO
@Service
@Slf4j
@RequiredArgsConstructor
@Deprecated
public class InteractiveServiceImpl implements IInteractiveService {
private final BladeLogger logger;

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java

@ -26,6 +26,7 @@ import java.util.Set;
@Service
@AllArgsConstructor
@Slf4j
@Deprecated
public class JumpPageServiceImpl implements IJumpPageService {
private final IFuncParamService paramService;

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java

@ -25,6 +25,7 @@ import java.util.stream.IntStream;
*/
@Component
@RequiredArgsConstructor
@Deprecated
public class JumpRouteJoinStrategy {
private final IStationClient stationClient;

23
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java

@ -0,0 +1,23 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory;
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @Author: huangxing
* @Date: 2024/06/21 19:02
*/
@Service(AnswerResolveFactory.PARAM_ANSWER_SERVICE)
@Slf4j
@AllArgsConstructor
public class ParamAnswerResolveServiceImpl implements IAnswerResolveService {
@Override
public AnswerVO resolve(AnswerVO answer) {
return null;
}
}

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java

@ -23,6 +23,7 @@ import java.util.Map;
@Component
@Slf4j
@AllArgsConstructor
@Deprecated
public class ParamStrategy {
private final IStationVideoTypeClient videoClient;

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java

@ -22,6 +22,7 @@ import java.util.Optional;
@Service
@Slf4j
@AllArgsConstructor
@Deprecated
public class ParamsServiceImpl implements IParamsService {
private final ParamStrategy strategy;

23
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java

@ -0,0 +1,23 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory;
import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @Author: huangxing
* @Date: 2024/06/21 19:02
*/
@Service(AnswerResolveFactory.REMOTE_ANSWER_SERVICE)
@Slf4j
@AllArgsConstructor
public class RemoteAnswerResolveServiceImpl implements IAnswerResolveService {
@Override
public AnswerVO resolve(AnswerVO answer) {
return null;
}
}

73
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java

@ -0,0 +1,73 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/06/21 16:17
*/
@Service(ResolveFactory.VIDEO_RESOLVE_SERVICE)
@AllArgsConstructor
@Slf4j
public class VideoResolveServiceImpl implements IResolveService {
private final IStationVideoTypeClient videoClient;
private final BladeLogger logger;
@Override
public ResolveResultVO resolve(ModelFunctionReq req) {
Map<String, String> args = req.getFunctionArgs();
String id = args.get("id");
String name = args.get("name");
Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> {
logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req));
throw new ServiceException("解析传参错误,缺少必要参数video_id");
});
ExtraVO extra = this.resolve(Long.valueOf(id));
String message = "已成功打开" + name + ";";
return new ResolveResultVO(message,extra);
}
@Override
public ExtraVO resolve(Long id) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
R<StationVideoTypeEntity> videoR = videoClient.getById(Long.valueOf(id));
if(videoR.isSuccess()) {
StationVideoTypeEntity video = videoR.getData();
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType());
extraVO.setImmediatelyJump(true);
extraVO.setFuncCode(FuncRouteEnum.OPEN_VIDEO.getFuncCode());
Map<String,Object> params = new HashMap<>();
params.put("name", video.getName());
params.put("videoHost", video.getVideoHost());
params.put("pointCode", video.getPointCode());
params.put("appKey", video.getAppKey());
params.put("appSecret", video.getAppSecret());
params.put("liveSourceAddress",video.getLiveSourceAddress());
extraVO.setParams(params);
}
return extraVO;
}
}

7
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java

@ -1,8 +1,10 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tool.utils.BeanUtil;
@ -16,6 +18,7 @@ import java.io.Serializable;
@Data
@ApiModel("HZLLM答案VO对象")
@EqualsAndHashCode
@AllArgsConstructor
public class AnswerVO implements Serializable {
@ApiModelProperty("发起问答时的随机ID")
@ -56,6 +59,10 @@ public class AnswerVO implements Serializable {
@JSONField(name = "voice_answer")
private String[] voiceAnswer;
public static AnswerVO error(String sessionId,String userId,String query) {
return new AnswerVO(sessionId,userId,0,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE});
}
public static void error(AnswerVO usualVO) {
usualVO.setRunning(0);
usualVO.setStatus(-2);

29
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java

@ -0,0 +1,29 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/06/21 16:31
*/
@EqualsAndHashCode
@Data
@AllArgsConstructor
@ApiModel(value = "解析结果",description = "解析结果")
public class ResolveResultVO implements Serializable {
private String content;
private ExtraVO extraVO;
public static ResolveResultVO error() {
return new ResolveResultVO(InfoMessageConstant.ERROR_MESSAGE,null);
}
}

28
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java

@ -0,0 +1,28 @@
package com.hnac.hzims.bigmodel.manager;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY;
/**
* @Author: huangxing
* @Date: 2024/06/21 18:23
*/
@Component
public class SessionRedisManager {
@Autowired
private RedisTemplate redisTemplate;
public void addSessionId(String sessionId) {
redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId);
}
public void removeSessionId(String sessionId) {
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId);
}
}

48
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java

@ -0,0 +1,48 @@
package com.hnac.hzims.bigmodel.utils;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import groovy.util.logging.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.util.Assert;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/06/21 17:12
*/
public class RequestClientUtil {
/**
* 无返回结果远程调用http接口
* @param url 接口url
* @param body 传参body
*/
public static void postCall(String url, Map body) {
HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型接口" + url + "失败!");
});
}
/**
* 远程调用http接口
* @param url 接口url
* @param body 传参
* @param resultT 结果解析对象
* @return 结果
* @param <T> 结果解析对象类型
*/
public static <T> T postCall(String url, Map body, Class<T> resultT) {
HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型接口" + url + "失败!");
});
return JSONObject.parseObject(response.body(), resultT);
}
}
Loading…
Cancel
Save