Browse Source

add:大模型管理

zhongwei
haungxing 7 months ago
parent
commit
b5578a378b
  1. 33
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  2. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

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

@ -19,8 +19,11 @@ import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.secure.utils.AuthUtil; 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.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.feign.IDeptClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -48,13 +51,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
private final IFunctionService functionService; private final IFunctionService functionService;
private final BigModelInvokeUrl bigModelInvokeUrl; private final BigModelInvokeUrl bigModelInvokeUrl;
private final BladeLogger logger; private final BladeLogger logger;
private final IDeptClient deptClient;
private final IUserClient userClient;
@Value("${fdp.host}") @Value("${fdp.host}")
private String fdpHost; private String fdpHost;
@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));
//TODO 数据鉴权
FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName());
TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType());
switch (typeEnum) { switch (typeEnum) {
@ -88,8 +92,8 @@ public class InteractiveServiceImpl implements IInteractiveService {
@Override @Override
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) { public List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,String> params = new HashMap<>(); Map<String,Object> params = new HashMap<>();
params.put("ids",sessionIds); params.put("ids",Func.toStrList(",",sessionIds).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
@ -101,7 +105,28 @@ public class InteractiveServiceImpl implements IInteractiveService {
@Override @Override
public Boolean authentication(String stationId, String userId, String funcCode) { public Boolean authentication(String stationId, String userId, String funcCode) {
//TODO 鉴权逻辑完善 // 站点鉴权
if(StringUtil.isNotBlank(stationId)) {
R<List<String>> stationsR = deptClient.getStationPermissionsById(Long.valueOf(userId));
Assert.isTrue(stationsR.isSuccess() && CollectionUtil.isNotEmpty(stationsR.getData()),() -> {
throw new ServiceException("获取人员站点权限失败!");
});
List<String> stations = stationsR.getData();
Assert.isTrue(stations.contains(stationId),() -> {
throw new ServiceException("人员站点鉴权失败!");
});
}
// 菜单鉴权
if(StringUtil.isNotBlank(funcCode)) {
FunctionEntity function = functionService.getFunctionByCode(funcCode);
Assert.isTrue(Func.isNotEmpty(function) && StringUtil.isNotBlank(function.getRoute()),() -> {
throw new ServiceException("传入函数未获取到菜单,鉴权失败!");
});
R<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute());
Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> {
throw new ServiceException("人员菜单鉴权失败!");
});
}
return true; return true;
} }

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

@ -44,4 +44,7 @@ public class AnswerVO implements Serializable {
@ApiModelProperty("query对应的答案") @ApiModelProperty("query对应的答案")
private String answer; private String answer;
@ApiModelProperty("其它调用的参数")
private String[] extra;
} }

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

@ -68,7 +68,7 @@ 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); XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(",")));
List<AnswerVO> AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); List<AnswerVO> AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(",")));
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList));
AnswerList.parallelStream().forEach(answerVO -> { AnswerList.parallelStream().forEach(answerVO -> {

Loading…
Cancel
Save