|
|
@ -7,20 +7,16 @@ import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; |
|
|
|
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; |
|
|
|
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
|
|
|
import com.hnac.hzims.bigmodel.entity.FunctionEntity; |
|
|
|
|
|
|
|
import com.hnac.hzims.bigmodel.function.service.IFunctionService; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; |
|
|
|
import com.hnac.hzims.bigmodel.function.service.IFunctionService; |
|
|
|
|
|
|
|
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
|
|
|
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; |
|
|
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
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.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
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.ObjectUtil; |
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
@ -35,14 +31,11 @@ import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; |
|
|
|
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; |
|
|
|
import java.util.HashMap; |
|
|
|
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @Author: huangxing |
|
|
|
* @Author: huangxing |
|
|
|
* @Date: 2024/04/26 14:51 |
|
|
|
* @Date: 2024/04/26 14:51 |
|
|
@ -71,8 +64,6 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
@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)); |
|
|
@ -131,7 +122,7 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
}); |
|
|
|
}); |
|
|
|
JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { |
|
|
|
JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { |
|
|
|
String[] extras = answerVO.getExtra(); |
|
|
|
String[] extras = answerVO.getExtra(); |
|
|
|
List<String> extraList = Arrays.stream(extras).map(extra -> extraResolveStrategyService.resolve(extra)).map(JSON::toJSONString).collect(Collectors.toList()); |
|
|
|
List<String> extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); |
|
|
|
answerVO.setExtra(extraList.toArray(new String[extraList.size()])); |
|
|
|
answerVO.setExtra(extraList.toArray(new String[extraList.size()])); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return JSONArray.parseArray(response.body(),AnswerVO.class); |
|
|
|
return JSONArray.parseArray(response.body(),AnswerVO.class); |
|
|
@ -161,6 +152,33 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Boolean removeSessionId(String sessionId) { |
|
|
|
|
|
|
|
// 调用大模型删除对话
|
|
|
|
|
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
|
|
|
|
params.put("id",sessionId); |
|
|
|
|
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) |
|
|
|
|
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
|
|
|
|
if(response.getStatus() != HttpServletResponse.SC_OK) { |
|
|
|
|
|
|
|
log.error("远程调用大模型【删除对话】接口失败!"); |
|
|
|
|
|
|
|
throw new ServiceException("远程调用大模型【删除对话】接口失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 移除对应reids中问题标记
|
|
|
|
|
|
|
|
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); |
|
|
|
|
|
|
|
if(ObjectUtil.isEmpty(json)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> sessionIds = JSONObject.parseArray(json.toString(),String.class); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(sessionIds)){ |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(sessionIds.contains(sessionId)){ |
|
|
|
|
|
|
|
sessionIds.remove(sessionId); |
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(sessionIds)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<DeptStationDTO> getStationPermissionsById(String userId) { |
|
|
|
private List<DeptStationDTO> getStationPermissionsById(String userId) { |
|
|
|
R<List<DeptStationDTO>> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); |
|
|
|
R<List<DeptStationDTO>> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); |
|
|
|
Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { |
|
|
|
Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { |
|
|
|