Skip to content

Commit

Permalink
[improvement][chat]Expose default prompt template to facilitate custo…
Browse files Browse the repository at this point in the history
…mization.
  • Loading branch information
jerryjzhang committed Sep 20, 2024
1 parent c547a27 commit 67b809c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.util.LLMConnHelper;
import com.tencent.supersonic.common.pojo.ChatModelConfig;
import com.tencent.supersonic.headless.chat.parser.llm.OnePassSCSqlGenStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -67,9 +66,4 @@ public Map<AgentToolType, String> getToolTypes() {
public boolean testLLMConn(@RequestBody ChatModelConfig modelConfig) {
return LLMConnHelper.testConnection(modelConfig);
}

@RequestMapping("/promptTemplate")
public String getPromptTemplate() {
return OnePassSCSqlGenStrategy.INSTRUCTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
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;
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;
Expand All @@ -44,6 +46,12 @@ public List<Agent> getAgents() {

@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);
Expand All @@ -54,6 +62,12 @@ public Agent createAgent(Agent agent, User user) {

@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);
Expand Down

0 comments on commit 67b809c

Please sign in to comment.