Commit bef92269 authored by alex yao's avatar alex yao

feat:Agent应用 追问接口调整

parent b6c4341e
...@@ -50,13 +50,6 @@ public interface AgentApplicationInfoService { ...@@ -50,13 +50,6 @@ public interface AgentApplicationInfoService {
*/ */
List<String> createFeaturedQuestions(String agentTitle, String agentDesc); List<String> createFeaturedQuestions(String agentTitle, String agentDesc);
/**
* 追问AI生成
*
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List<String> createContinueQuestions(String input, String agentId);
} }
...@@ -207,53 +207,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -207,53 +207,6 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}.getType()); }.getType());
} }
@Override
public List<String> createContinueQuestions(String input, String agentId) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_CONTINUE_QUESTIONS);
if (null == configEntity) {
throw new BusinessException("创建[开场白]配置不存在");
}
BizAgentApplicationInfoEntity infoEntity = bizAgentApplicationInfoService.getByAgentId(agentId);
String continuousQuestionStatus = infoEntity.getContinuousQuestionStatus();
if (AgentApplicationConstants.CONTINUOUS_QUESTION_STATUS.CLOSE.equals(continuousQuestionStatus)) {
logger.warn("continue question is close ,agent_info:{}", infoEntity);
return null;
}
String configSystem = configEntity.getConfigSystem();
configSystem = configSystem.replace("${input}", input);
MultiContent systemMultiContent = new MultiContent();
systemMultiContent.setText(configSystem);
systemMultiContent.setType("text");
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(systemMultiContent);
Message message = new Message();
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(new ArrayList<Message>() {{
add(message);
}}.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CONTINUE-QUESTIONS");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
if (largeModelDemandResult == null || !"0".equals(largeModelDemandResult.getCode())) {
logger.error("continue question error ,largeModelDemandResult:{} , largeModelResponse:{}", largeModelDemandResult != null ? largeModelDemandResult.toString() : StringUtils.EMPTY
, largeModelResponse);
// throw new BusinessException("追问失败");
return null;
}
String res = largeModelDemandResult.getMessage();
int start = res.lastIndexOf("[");
int end = res.lastIndexOf("]");
return JsonUtils.deSerialize(res.substring(start, end + 1), new TypeReference<List<String>>() {
}.getType());
}
private String buildDialogsPrompt(List<Message> messages, String agentSystem, String[] knowledgeIds) { private String buildDialogsPrompt(List<Message> messages, String agentSystem, String[] knowledgeIds) {
// todo 获取提示词模板 // todo 获取提示词模板
......
...@@ -72,8 +72,5 @@ public interface AgentApplicationInfoRest extends BaseRest { ...@@ -72,8 +72,5 @@ public interface AgentApplicationInfoRest extends BaseRest {
*/ */
String createPreamble(@RequestBody AgentApplicationGCDto dto) throws Exception; String createPreamble(@RequestBody AgentApplicationGCDto dto) throws Exception;
/**
* 追问
*/
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto) throws Exception;
} }
\ No newline at end of file
...@@ -160,10 +160,5 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -160,10 +160,5 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc()); return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc());
} }
@Override
public List<String> createContinueQuestions(AgentApplicationCreateContinueQuesDto dto) throws Exception {
cn.com.poc.common.utils.Assert.notNull(dto.getInput(), "agentId不能为空");
cn.com.poc.common.utils.Assert.notNull(dto.getAgentId(), "input不能为空");
return agentApplicationInfoService.createContinueQuestions(dto.getInput(), dto.getAgentId());
}
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package cn.com.poc.expose.aggregate; ...@@ -3,6 +3,7 @@ package cn.com.poc.expose.aggregate;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface AgentApplicationService { public interface AgentApplicationService {
...@@ -11,4 +12,13 @@ public interface AgentApplicationService { ...@@ -11,4 +12,13 @@ public interface AgentApplicationService {
*/ */
void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception; void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception;
/**
* 追问AI生成
*
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List<String> createContinueQuestions(String input, String agentId);
} }
...@@ -3,9 +3,13 @@ package cn.com.poc.expose.aggregate.impl; ...@@ -3,9 +3,13 @@ package cn.com.poc.expose.aggregate.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.constant.AgentApplicationConstants; import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants; import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants;
import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService; import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService;
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
...@@ -15,8 +19,13 @@ import cn.com.poc.expose.rest.AgentApplicationRest; ...@@ -15,8 +19,13 @@ import cn.com.poc.expose.rest.AgentApplicationRest;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse;
import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -40,6 +49,12 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -40,6 +49,12 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Resource @Resource
private AgentApplicationInfoService agentApplicationInfoService; private AgentApplicationInfoService agentApplicationInfoService;
@Resource
private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
@Resource
private LLMService llmService;
@Override @Override
public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception { public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception {
...@@ -92,6 +107,48 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -92,6 +107,48 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
bizAgentApplicationDialoguesRecordService.save(outputRecord); bizAgentApplicationDialoguesRecordService.save(outputRecord);
} }
@Override
public List<String> createContinueQuestions(String input, String agentId) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_CONTINUE_QUESTIONS);
if (null == configEntity) {
throw new BusinessException("创建[开场白]配置不存在");
}
String configSystem = configEntity.getConfigSystem();
configSystem = configSystem.replace("${input}", input);
MultiContent systemMultiContent = new MultiContent();
systemMultiContent.setText(configSystem);
systemMultiContent.setType("text");
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(systemMultiContent);
Message message = new Message();
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(new ArrayList<Message>() {{
add(message);
}}.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CONTINUE-QUESTIONS");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
if (largeModelDemandResult == null || !"0".equals(largeModelDemandResult.getCode())) {
logger.error("continue question error ,largeModelDemandResult:{} , largeModelResponse:{}", largeModelDemandResult != null ? largeModelDemandResult.toString() : StringUtils.EMPTY
, largeModelResponse);
// throw new BusinessException("追问失败");
return null;
}
String res = largeModelDemandResult.getMessage();
int start = res.lastIndexOf("[");
int end = res.lastIndexOf("]");
return JsonUtils.deSerialize(res.substring(start, end + 1), new TypeReference<List<String>>() {
}.getType());
}
private void buildMessages(String dialogsId, String agentId, Long userId, List<Message> messages, String input) throws Exception { private void buildMessages(String dialogsId, String agentId, Long userId, List<Message> messages, String input) throws Exception {
BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity(); BizAgentApplicationDialoguesRecordEntity recordEntity = new BizAgentApplicationDialoguesRecordEntity();
recordEntity.setDialogsId(dialogsId); recordEntity.setDialogsId(dialogsId);
......
package cn.com.poc.expose.rest; package cn.com.poc.expose.rest;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
...@@ -36,4 +37,10 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -36,4 +37,10 @@ public interface AgentApplicationRest extends BaseRest {
*/ */
@Permission(value = Access.Anonymous) @Permission(value = Access.Anonymous)
BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception; BizAgentApplicationPublishDto getInfo(@RequestParam String agentId) throws Exception;
/**
* 追问
*/
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto) throws Exception;
} }
...@@ -2,6 +2,7 @@ package cn.com.poc.expose.rest.impl; ...@@ -2,6 +2,7 @@ package cn.com.poc.expose.rest.impl;
import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert; import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert; import cn.com.poc.agent_application.convert.BizAgentApplicationPublishConvert;
import cn.com.poc.agent_application.dto.AgentApplicationCreateContinueQuesDto;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
...@@ -66,4 +67,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest { ...@@ -66,4 +67,11 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
} }
return BizAgentApplicationPublishConvert.entityToDto(entity); return BizAgentApplicationPublishConvert.entityToDto(entity);
} }
@Override
public List<String> createContinueQuestions(AgentApplicationCreateContinueQuesDto dto) throws Exception {
cn.com.poc.common.utils.Assert.notNull(dto.getInput(), "agentId不能为空");
cn.com.poc.common.utils.Assert.notNull(dto.getAgentId(), "input不能为空");
return agentApplicationService.createContinueQuestions(dto.getInput(), dto.getAgentId());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment