|
|
|
@ -4,8 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import com.hnac.hzims.bigmodel.business.feign.IAuthClient; |
|
|
|
|
import com.hnac.hzims.bigmodel.business.service.AuthenticationService; |
|
|
|
|
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; |
|
|
|
|
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; |
|
|
|
|
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; |
|
|
|
|
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; |
|
|
|
|
import com.hnac.hzims.bigmodel.manager.SessionRedisManager; |
|
|
|
@ -15,10 +14,7 @@ import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManage
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
@ -36,12 +32,12 @@ import java.util.Map;
|
|
|
|
|
@Slf4j |
|
|
|
|
public class HznlmInvokeServiceImpl implements IHznlmInvokeService { |
|
|
|
|
|
|
|
|
|
private final BigModelInvokeUrl bigModelInvokeUrl; |
|
|
|
|
private final BigModelInvokeApi bigModelInvokeApi; |
|
|
|
|
private final SessionRedisManager sessionRedisManager; |
|
|
|
|
private final IAuthClient authClient; |
|
|
|
|
|
|
|
|
|
@Value("${gglm.host}") |
|
|
|
|
private String gglmHost; |
|
|
|
|
@Value("${gglm.url}") |
|
|
|
|
private String gglmUrl; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void ask(String question, String sessionId, String userId) { |
|
|
|
@ -51,13 +47,13 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
|
|
|
|
|
params.put("query",question); |
|
|
|
|
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
|
|
|
|
params.putAll(authDataIds); |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantAsk(), params); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantAsk(), params); |
|
|
|
|
sessionRedisManager.addSessionId(sessionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void ask(QuestionDTO question) { |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantAsk(), JSON.toJSONString(question)); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantAsk(), JSON.toJSONString(question)); |
|
|
|
|
sessionRedisManager.addSessionId(question.getChatId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -69,14 +65,14 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
|
|
|
|
|
params.put("extra",extra); |
|
|
|
|
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
|
|
|
|
params.putAll(authDataIds); |
|
|
|
|
log.info("调用大模型接口:{},传参为:{}",gglmHost + bigModelInvokeUrl.getAssistantSpecialAsk(),JSON.toJSONString(params)); |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params); |
|
|
|
|
log.info("调用大模型接口:{},传参为:{}",gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(),JSON.toJSONString(params)); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), params); |
|
|
|
|
sessionRedisManager.addSessionId(sessionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void specialAsk(QuestionDTO question) { |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantSpecialAsk(), JSON.toJSONString(question)); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantSpecialAsk(), JSON.toJSONString(question)); |
|
|
|
|
sessionRedisManager.addSessionId(question.getChatId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -89,13 +85,13 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
|
|
|
|
|
params.put("knowledge", knowledge); |
|
|
|
|
Map<String, String[]> authDataIds = this.getAuthDataIds(userId); |
|
|
|
|
params.putAll(authDataIds); |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantKnowledgeAsk(), params); |
|
|
|
|
sessionRedisManager.addSessionId(sessionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void knowledgeAsk(QuestionDTO question) { |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), JSON.toJSONString(question)); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantKnowledgeAsk(), JSON.toJSONString(question)); |
|
|
|
|
sessionRedisManager.addSessionId(question.getChatId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -111,14 +107,14 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
|
|
|
|
|
public void askAbort(String sessionId) { |
|
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
|
params.put("chat_id",sessionId); |
|
|
|
|
RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAskAbort(), params); |
|
|
|
|
RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAskAbort(), params); |
|
|
|
|
sessionRedisManager.removeSessionId(sessionId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List hotQuestions() { |
|
|
|
|
try { |
|
|
|
|
return RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getHotQuestion(), null, new TypeReference<List<String>>(){}); |
|
|
|
|
return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference<List<String>>(){}); |
|
|
|
|
} |
|
|
|
|
catch (Exception e) { |
|
|
|
|
log.error("An error occurred",e); |
|
|
|
@ -130,7 +126,7 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
|
|
|
|
|
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) { |
|
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
|
params.put("chat_ids",Func.toStrList(",",sessionIds).toArray()); |
|
|
|
|
return RequestClientUtil.postCall(gglmHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference<List<AnswerVO>>(){}); |
|
|
|
|
return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getAssistantStatus(), params, new TypeReference<List<AnswerVO>>(){}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String,String[]> getAuthDataIds(String userId) { |
|
|
|
|