|
|
@ -16,6 +16,7 @@ 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.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.Func; |
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
@ -46,11 +47,13 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
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; |
|
|
|
@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)); |
|
|
|
//TODO 数据鉴权
|
|
|
|
//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()); |
|
|
@ -68,8 +71,7 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R ask(String question,String sessionId) { |
|
|
|
public R ask(String question,String sessionId,String userId) { |
|
|
|
Long userId = AuthUtil.getUserId(); |
|
|
|
|
|
|
|
//TODO 保存问题
|
|
|
|
//TODO 保存问题
|
|
|
|
Map<String,String> params = new HashMap<>(); |
|
|
|
Map<String,String> params = new HashMap<>(); |
|
|
|
params.put("id",sessionId); |
|
|
|
params.put("id",sessionId); |
|
|
@ -77,10 +79,11 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
params.put("query",question); |
|
|
|
params.put("query",question); |
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) |
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) |
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { |
|
|
|
if(response.getStatus() != HttpServletResponse.SC_OK) { |
|
|
|
throw new ServiceException("远程调用大模型【发起问答】接口失败!"); |
|
|
|
log.error("远程调用大模型【发起问答】接口失败!"); |
|
|
|
}); |
|
|
|
return R.fail("远程调用大模型【发起问答】接口失败!"); |
|
|
|
return R.data(JSONObject.parseObject(response.body()).getString("data")); |
|
|
|
} |
|
|
|
|
|
|
|
return R.success("消息发送成功"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -89,11 +92,11 @@ public class InteractiveServiceImpl implements IInteractiveService { |
|
|
|
params.put("ids",sessionIds); |
|
|
|
params.put("ids",sessionIds); |
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) |
|
|
|
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) |
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
.body(JSON.toJSONString(params)).execute(); |
|
|
|
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { |
|
|
|
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); |
|
|
|
|
|
|
|
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { |
|
|
|
throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); |
|
|
|
throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
String data = JSONObject.parseObject(response.body()).getString("data"); |
|
|
|
return JSONArray.parseArray(response.body(),AnswerVO.class); |
|
|
|
return JSONArray.parseArray(data,AnswerVO.class); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|