Commit c90bc2be authored by alex yao's avatar alex yao

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

parent 4c803b86
...@@ -34,11 +34,12 @@ public interface AgentApplicationInfoService { ...@@ -34,11 +34,12 @@ public interface AgentApplicationInfoService {
/** /**
* 开场白AI生成 * 开场白AI生成
* *
* @param agentTitle 应用标题 * @param agentTitle 应用标题
* @param agentDesc 应用描述 * @param agentDesc 应用描述
* @param agentSystem 应用角色指令
* @return * @return
*/ */
String createPreamble(String agentTitle, String agentDesc); String createPreamble(String agentTitle, String agentDesc, String agentSystem);
/** /**
......
...@@ -138,7 +138,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -138,7 +138,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
@Override @Override
public String createPreamble(String agentTitle, String agentDesc) { public String createPreamble(String agentTitle, String agentDesc, String agentSystem) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_PREAMBLE); BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_PREAMBLE);
if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) { if (null == configEntity || StringUtils.isBlank(configEntity.getConfigSystem())) {
throw new BusinessException("创建[开场白]配置不存在"); throw new BusinessException("创建[开场白]配置不存在");
...@@ -147,12 +147,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -147,12 +147,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
List<MultiContent> multiContents = new ArrayList<>(); List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{ multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem(); String configSystem = configEntity.getConfigSystem();
if (StringUtils.isNotBlank(agentTitle)) { configSystem = buildPreambleConfigSystem(configSystem, agentTitle, agentDesc, agentSystem);
configSystem = configSystem.replace("${agent_title}", agentTitle);
}
if (StringUtils.isNotBlank(agentDesc)) {
configSystem = configSystem.replace("${agent_desc}", agentDesc);
}
setText(configSystem); setText(configSystem);
setType("text"); setType("text");
}}); }});
...@@ -178,6 +174,23 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -178,6 +174,23 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return largeModelDemandResult.getMessage(); 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 @Override
public List<String> createFeaturedQuestions(String agentTitle, String agentDesc) { public List<String> createFeaturedQuestions(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_FEATURED_QUESTIONS); BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_FEATURED_QUESTIONS);
...@@ -361,7 +374,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -361,7 +374,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param bufferedReader * @param bufferedReader
* @throws IOException * @throws IOException
*/ */
private String textOutput(HttpServletResponse httpServletResponse, BufferedReader bufferedReader) throws IOException { private String textOutput(HttpServletResponse httpServletResponse, BufferedReader bufferedReader) throws
IOException {
String res = ""; String res = "";
httpServletResponse.setContentType(TEXT_EVENT_STREAM_CHARSET_UTF_8); httpServletResponse.setContentType(TEXT_EVENT_STREAM_CHARSET_UTF_8);
PrintWriter writer = httpServletResponse.getWriter(); PrintWriter writer = httpServletResponse.getWriter();
...@@ -396,7 +410,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -396,7 +410,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param promptTemplate * @param promptTemplate
* @return * @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 messLength = messages.size() - 1;
int skip = communicationTurn * 2; int skip = communicationTurn * 2;
if (skip < messLength) { if (skip < messLength) {
......
...@@ -10,6 +10,8 @@ public class AgentApplicationGCDto implements Serializable { ...@@ -10,6 +10,8 @@ public class AgentApplicationGCDto implements Serializable {
private String agentDesc; private String agentDesc;
private String agentSystem;
public String getInput() { public String getInput() {
return input; return input;
} }
...@@ -34,4 +36,12 @@ public class AgentApplicationGCDto implements Serializable { ...@@ -34,4 +36,12 @@ public class AgentApplicationGCDto implements Serializable {
public void setAgentDesc(String agentDesc) { public void setAgentDesc(String agentDesc) {
this.agentDesc = 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 { ...@@ -159,7 +159,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
@Override @Override
public String createPreamble(AgentApplicationGCDto dto) throws Exception { public String createPreamble(AgentApplicationGCDto dto) throws Exception {
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc()); return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc(),dto.getAgentSystem());
} }
@Override @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