[improvement][chat]Expose default prompt template to facilitate customization.

This commit is contained in:
jerryjzhang
2024-09-20 16:46:49 +08:00
parent 2c7758d0ca
commit c045b34328
3 changed files with 20 additions and 6 deletions

View File

@@ -52,11 +52,6 @@ public class AgentController {
return true;
}
@PostMapping("/testLLMConn")
public boolean testLLMConn(@RequestBody ChatModelConfig modelConfig) {
return LLMConnHelper.testConnection(modelConfig);
}
@RequestMapping("/getAgentList")
public List<Agent> getAgentList() {
return agentService.getAgents();
@@ -66,4 +61,9 @@ public class AgentController {
public Map<AgentToolType, String> getToolTypes() {
return AgentToolType.getToolTypes();
}
@PostMapping("/testLLMConn")
public boolean testLLMConn(@RequestBody ChatModelConfig modelConfig) {
return LLMConnHelper.testConnection(modelConfig);
}
}

View File

@@ -16,6 +16,7 @@ import com.tencent.supersonic.common.config.PromptConfig;
import com.tencent.supersonic.common.config.VisualConfig;
import com.tencent.supersonic.common.pojo.ChatModelConfig;
import com.tencent.supersonic.common.util.JsonUtil;
import com.tencent.supersonic.headless.chat.parser.llm.OnePassSCSqlGenStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@@ -44,6 +46,12 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO> implem
@Override
public Agent createAgent(Agent agent, User user) {
if (Objects.isNull(agent.getPromptConfig())
|| Objects.isNull(agent.getPromptConfig().getPromptTemplate())) {
PromptConfig promptConfig = new PromptConfig();
promptConfig.setPromptTemplate(OnePassSCSqlGenStrategy.INSTRUCTION.trim());
agent.setPromptConfig(promptConfig);
}
agent.createdBy(user.getName());
AgentDO agentDO = convert(agent);
save(agentDO);
@@ -54,6 +62,12 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO> implem
@Override
public Agent updateAgent(Agent agent, User user) {
if (Objects.isNull(agent.getPromptConfig())
|| Objects.isNull(agent.getPromptConfig().getPromptTemplate())) {
PromptConfig promptConfig = new PromptConfig();
promptConfig.setPromptTemplate(OnePassSCSqlGenStrategy.INSTRUCTION.trim());
agent.setPromptConfig(promptConfig);
}
agent.updatedBy(user.getName());
updateById(convert(agent));
executeAgentExamplesAsync(agent);

View File

@@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class OnePassSCSqlGenStrategy extends SqlGenStrategy {
private static final String INSTRUCTION =
public static final String INSTRUCTION =
""
+ "\n#Role: You are a data analyst experienced in SQL languages."
+ "\n#Task: You will be provided with a natural language question asked by users,"