Commit b6c4341e authored by alex yao's avatar alex yao

feat:Agent应用 追问接口调整

parent 7cfa6685
......@@ -53,8 +53,10 @@ public interface AgentApplicationInfoService {
/**
* 追问AI生成
*
* @param messages@return
* @param input 问题输入
* @param agentId 应用id
* @return
*/
List<String> createContinueQuestions(List<Message> messages, String agentId);
List<String> createContinueQuestions(String input, String agentId);
}
......@@ -71,6 +71,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
bizAgentApplicationInfoEntity.setAgentPublishStatus(AgentApplicationConstants.AGENT_PUBLISH_STATUS.PUBLISH);
bizAgentApplicationInfoEntity.setPublishTime(new Date());
if (null == bizAgentApplicationInfoService.update(bizAgentApplicationInfoEntity)) {
logger.error("update and publish agent error , bizAgentApplicationInfoEntity:{}", bizAgentApplicationInfoEntity);
throw new BusinessException("发布失败");
}
......@@ -102,7 +103,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public void createAgentSystem(String input, HttpServletResponse httpServletResponse) throws Exception {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_SYSTEM);
if (null == configEntity) {
if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) {
throw new BusinessException("创建[角色指令]配置不存在");
}
......@@ -133,15 +134,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public String createPreamble(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_PREAMBLE);
if (null == configEntity) {
if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) {
throw new BusinessException("创建[开场白]配置不存在");
}
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem();
if (StringUtils.isNotBlank(agentTitle)) {
configSystem = configSystem.replace("${agent_title}", agentTitle);
}
if (StringUtils.isNotBlank(agentDesc)) {
configSystem = configSystem.replace("${agent_desc}", agentDesc);
}
setText(configSystem);
setType("text");
}});
......@@ -165,15 +170,19 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
@Override
public List<String> createFeaturedQuestions(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_FEATURED_QUESTIONS);
if (null == configEntity) {
if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) {
throw new BusinessException("创建[开场白]配置不存在");
}
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem();
if (StringUtils.isNotEmpty(agentTitle)) {
configSystem = configSystem.replace("${agent_title}", agentTitle);
}
if (StringUtils.isNotEmpty(agentDesc)) {
configSystem = configSystem.replace("${agent_desc}", agentDesc);
}
setText(configSystem);
setType("text");
}});
......@@ -199,72 +208,46 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}
@Override
public List<String> createContinueQuestions(List<Message> messages, String agentId) {
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("连续问题已关闭");
logger.warn("continue question is close ,agent_info:{}", infoEntity);
return null;
}
String configSystem = configEntity.getConfigSystem();
int turn = 3;
if (AgentApplicationConstants.CONTINUOUS_QUESTION_STATUS.CUSTOMIZABLE.equals(continuousQuestionStatus)) {
configSystem = configSystem.replace("${input}", infoEntity.getContinuousQuestionSystem());
turn = infoEntity.getContinuousQuestionTurn();
}
configSystem = configSystem.replace("${input}", input);
MultiContent systemMultiContent = new MultiContent();
systemMultiContent.setText(configSystem);
systemMultiContent.setType("text");
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(systemMultiContent);
Message systemMessage = new Message();
systemMessage.setContent(multiContents);
systemMessage.setRole(AgentApplicationDialoguesRecordConstants.ROLE.SYSTEM);
int messLength = messages.size() - 1;
int skip = turn * 2;
if (skip < messLength) {
messages = messages.subList(messLength - skip, messages.size());
}
StringBuilder userBuilder = new StringBuilder();
for (Message message : messages) {
userBuilder.append(message.getRole()).append(":").append(message.getContent().get(0).getText()).append(StringUtils.LF);
}
MultiContent multiContent = new MultiContent();
multiContent.setText(userBuilder.toString());
multiContent.setType("text");
List<MultiContent> userMultiContent = new ArrayList<>();
userMultiContent.add(multiContent);
Message message = new Message();
message.setContent(userMultiContent);
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(new ArrayList<Message>() {{
add(systemMessage);
add(message);
}}.toArray(new Message[2]));
}}.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("]");
......
package cn.com.poc.agent_application.dto;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import java.io.Serializable;
import java.util.List;
public class AgentApplicationCreateContinueQuesDto implements Serializable {
private List<Message> messages;
/**
* 问题输入
*/
private String input;
/**
* 应用ID
*/
private String agentId;
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public List<Message> getMessages() {
return messages;
public String getAgentId() {
return agentId;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
public void setAgentId(String agentId) {
this.agentId = agentId;
}
}
package cn.com.poc.agent_application.entity;
import java.util.Arrays;
public class BizAgentApplicationInfoEntity {
private static final long serialVersionUID = 1L;
......@@ -304,4 +306,35 @@ public class BizAgentApplicationInfoEntity {
public void setSysVersion(java.lang.Integer sysVersion){
this.sysVersion = sysVersion;
}
@Override
public String toString() {
return "BizAgentApplicationInfoEntity{" +
"id=" + id +
", memberId=" + memberId +
", agentId='" + agentId + '\'' +
", agentAvatar='" + agentAvatar + '\'' +
", agentTitle='" + agentTitle + '\'' +
", agentDesc='" + agentDesc + '\'' +
", agentSystem='" + agentSystem + '\'' +
", agentPublishStatus='" + agentPublishStatus + '\'' +
", publishTime=" + publishTime +
", preamble='" + preamble + '\'' +
", featuredQuestions=" + Arrays.toString(featuredQuestions) +
", communicationTurn=" + communicationTurn +
", continuousQuestionStatus='" + continuousQuestionStatus + '\'' +
", continuousQuestionSystem='" + continuousQuestionSystem + '\'' +
", continuousQuestionTurn=" + continuousQuestionTurn +
", knowledgeIds=" + Arrays.toString(knowledgeIds) +
", largeModel='" + largeModel + '\'' +
", topP=" + topP +
", unitIds=" + Arrays.toString(unitIds) +
", isDeleted='" + isDeleted + '\'' +
", creator='" + creator + '\'' +
", createdTime=" + createdTime +
", modifier='" + modifier + '\'' +
", modifiedTime=" + modifiedTime +
", sysVersion=" + sysVersion +
'}';
}
}
\ No newline at end of file
......@@ -75,5 +75,5 @@ public interface AgentApplicationInfoRest extends BaseRest {
/**
* 追问
*/
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto, @RequestParam String agentId) throws Exception;
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto) throws Exception;
}
\ No newline at end of file
......@@ -161,7 +161,9 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
@Override
public List<String> createContinueQuestions(AgentApplicationCreateContinueQuesDto dto, String agentId) throws Exception {
return agentApplicationInfoService.createContinueQuestions(dto.getMessages(), agentId);
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
......@@ -25,4 +25,12 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "LargeModelDemandResult{" +
"code='" + code + '\'' +
", message='" + message + '\'' +
'}';
}
}
......@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
/**
......@@ -140,4 +141,22 @@ public class LargeModelResponse implements Serializable {
public void setUser(String user) {
this.user = user;
}
@Override
public String toString() {
return "LargeModelResponse{" +
"model='" + model + '\'' +
", messages=" + Arrays.toString(messages) +
", temperature=" + temperature +
", topP=" + topP +
", n=" + n +
", stream=" + stream +
", stop=" + Arrays.toString(stop) +
", maxTokens=" + maxTokens +
", presencePenalty=" + presencePenalty +
", frequencyPenalty=" + frequencyPenalty +
", logit_bias=" + logit_bias +
", user='" + user + '\'' +
'}';
}
}
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