|
|
|
@ -4,20 +4,17 @@ import cn.hutool.http.HttpRequest;
|
|
|
|
|
import cn.hutool.http.HttpResponse; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; |
|
|
|
|
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.service.IInteractiveService; |
|
|
|
|
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 lombok.AllArgsConstructor; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
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.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
@ -29,15 +26,10 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; |
|
|
|
|
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; |
|
|
|
|
/** |
|
|
|
|
* @Author: huangxing |
|
|
|
|
* @Date: 2024/04/26 14:51 |
|
|
|
@ -47,31 +39,39 @@ import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*;
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
|
|
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
|
|
private final IJumpPageService jumpPageService; |
|
|
|
|
|
|
|
|
|
private final IFunctionService functionService; |
|
|
|
|
|
|
|
|
|
private final BigModelInvokeUrl bigModelInvokeUrl; |
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
|
|
|
|
|
private final IDeptClient deptClient; |
|
|
|
|
|
|
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
@Value("${fdp.host}") |
|
|
|
|
private String fdpHost; |
|
|
|
|
|
|
|
|
|
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R resolve(ModelFunctionReq req) { |
|
|
|
|
logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); |
|
|
|
|
FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); |
|
|
|
|
TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); |
|
|
|
|
switch (typeEnum) { |
|
|
|
|
// 页面跳转
|
|
|
|
|
case JUMP: |
|
|
|
|
if (Objects.requireNonNull(typeEnum) == TypeEnum.JUMP) { |
|
|
|
|
String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); |
|
|
|
|
Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { |
|
|
|
|
throw new ServiceException("解析" + function.getName() + "函数失败!"); |
|
|
|
|
}); |
|
|
|
|
return R.data(extra); |
|
|
|
|
default: |
|
|
|
|
throw new ServiceException("函数解析失败!"); |
|
|
|
|
} |
|
|
|
|
throw new ServiceException("函数解析失败!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -79,7 +79,7 @@ public class InteractiveServiceImpl implements IInteractiveService {
|
|
|
|
|
//TODO 保存问题
|
|
|
|
|
Map<String,String> params = new HashMap<>(); |
|
|
|
|
params.put("id",sessionId); |
|
|
|
|
params.put("userid",userId.toString()); |
|
|
|
|
params.put("userid", userId); |
|
|
|
|
params.put("query",question); |
|
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) |
|
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
@ -87,6 +87,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
|
|
|
|
|
log.error("远程调用大模型【发起问答】接口失败!"); |
|
|
|
|
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("消息发送成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|