Commit c90bc2be authored by alex yao's avatar alex yao

feat:修改开场白AI生成流程

parent 4c803b86
......@@ -36,9 +36,10 @@ public interface AgentApplicationInfoService {
*
* @param agentTitle 应用标题
* @param agentDesc 应用描述
* @param agentSystem 应用角色指令
* @return
*/
String createPreamble(String agentTitle, String agentDesc);
String createPreamble(String agentTitle, String agentDesc, String agentSystem);
/**
......
......@@ -138,7 +138,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
}
@Override
public String createPreamble(String agentTitle, String agentDesc) {
public String createPreamble(String agentTitle, String agentDesc, String agentSystem) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_PREAMBLE);
if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) {
throw new BusinessException("创建[开场白]配置不存在");
......@@ -147,12 +147,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
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);
}
configSystem = buildPreambleConfigSystem(configSystem, agentTitle, agentDesc, agentSystem);
setText(configSystem);
setType("text");
}});
......@@ -178,6 +174,23 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return largeModelDemandResult.getMessage();
}
private static String buildPreambleConfigSystem(String configSystem, String agentTitle, String agentDesc, String agentSystem) {
//若 name desc prompt 都为空,传入默认参数 name 入参 智能问答机器人 desc 随时为你解答问题
if (StringUtils.isBlank(configSystem) && StringUtils.isBlank(agentTitle) && StringUtils.isBlank(agentDesc)) {
return configSystem.replace("${agent_name}", "智能问答机器人").replace("${agent_desc}", " 随时为你解答问题");
}
//若 name desc 其中一项不为空则入参 不传入prompt
if (StringUtils.isNotBlank(agentTitle) || (StringUtils.isNotBlank(agentDesc))) {
return configSystem.replace("${agent_title}", agentTitle).replace("${agent_desc}", agentDesc);
}
// 若 name desc 都空 prompt 有内容,则把prompt 传入desc
if (StringUtils.isNotBlank(agentSystem)) {
return configSystem.replace("${agent_desc}", agentSystem).replace("${agent_name}", "智能问答机器人");
}
return configSystem;
}
@Override
public List<String> createFeaturedQuestions(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_FEATURED_QUESTIONS);
......@@ -361,7 +374,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param bufferedReader
* @throws IOException
*/
private String textOutput(HttpServletResponse httpServletResponse, BufferedReader bufferedReader) throws IOException {
private String textOutput(HttpServletResponse httpServletResponse, BufferedReader bufferedReader) throws
IOException {
String res = "";
httpServletResponse.setContentType(TEXT_EVENT_STREAM_CHARSET_UTF_8);
PrintWriter writer = httpServletResponse.getWriter();
......@@ -396,7 +410,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param promptTemplate
* @return
*/
private static Message[] buildMessages(List<Message> messages, Integer communicationTurn, String promptTemplate) {
private static Message[] buildMessages(List<Message> messages, Integer communicationTurn, String
promptTemplate) {
int messLength = messages.size() - 1;
int skip = communicationTurn * 2;
if (skip < messLength) {
......
......@@ -10,6 +10,8 @@ public class AgentApplicationGCDto implements Serializable {
private String agentDesc;
private String agentSystem;
public String getInput() {
return input;
}
......@@ -34,4 +36,12 @@ public class AgentApplicationGCDto implements Serializable {
public void setAgentDesc(String agentDesc) {
this.agentDesc = agentDesc;
}
public String getAgentSystem() {
return agentSystem;
}
public void setAgentSystem(String agentSystem) {
this.agentSystem = agentSystem;
}
}
......@@ -159,7 +159,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Override
public String createPreamble(AgentApplicationGCDto dto) throws Exception {
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc());
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc(),dto.getAgentSystem());
}
@Override
......
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