mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 22:25:19 +00:00
# This is a combination of 2 commits.
(feature)(headless)Support custom prompt template. #1348.
This commit is contained in:
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import com.tencent.supersonic.common.config.PromptConfig;
|
||||
import com.tencent.supersonic.common.config.VisualConfig;
|
||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
||||
import lombok.Data;
|
||||
@@ -33,6 +34,7 @@ public class Agent extends RecordInfo {
|
||||
private List<String> examples;
|
||||
private String agentConfig;
|
||||
private LLMConfig llmConfig;
|
||||
private PromptConfig promptConfig;
|
||||
private MultiTurnConfig multiTurnConfig;
|
||||
private VisualConfig visualConfig;
|
||||
|
||||
|
||||
@@ -66,10 +66,10 @@ public class NL2SQLParser implements ChatParser {
|
||||
if (!chatParseContext.enableNL2SQL() || checkSkip(parseResp)) {
|
||||
return;
|
||||
}
|
||||
processMultiTurn(chatParseContext);
|
||||
|
||||
processMultiTurn(chatParseContext);
|
||||
QueryReq queryReq = QueryReqConverter.buildText2SqlQueryReq(chatParseContext);
|
||||
addExemplars(chatParseContext.getAgent().getId(), queryReq);
|
||||
addDynamicExemplars(chatParseContext.getAgent().getId(), queryReq);
|
||||
|
||||
ChatQueryService chatQueryService = ContextUtils.getBean(ChatQueryService.class);
|
||||
ParseResp text2SqlParseResp = chatQueryService.performParsing(queryReq);
|
||||
@@ -224,13 +224,13 @@ public class NL2SQLParser implements ChatParser {
|
||||
return contextualList;
|
||||
}
|
||||
|
||||
private void addExemplars(Integer agentId, QueryReq queryReq) {
|
||||
private void addDynamicExemplars(Integer agentId, QueryReq queryReq) {
|
||||
ExemplarServiceImpl exemplarManager = ContextUtils.getBean(ExemplarServiceImpl.class);
|
||||
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
||||
String memoryCollectionName = embeddingConfig.getMemoryCollectionName(agentId);
|
||||
List<SqlExemplar> exemplars = exemplarManager.recallExemplars(memoryCollectionName,
|
||||
queryReq.getQueryText(), 5);
|
||||
queryReq.getExemplars().addAll(exemplars);
|
||||
queryReq.getDynamicExemplars().addAll(exemplars);
|
||||
}
|
||||
|
||||
@Builder
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tencent.supersonic.common.config.VisualConfig;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -63,4 +62,6 @@ public class AgentDO {
|
||||
|
||||
private String visualConfig;
|
||||
|
||||
private String promptConfig;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.tencent.supersonic.chat.server.service.ChatService;
|
||||
import com.tencent.supersonic.chat.server.service.MemoryService;
|
||||
import com.tencent.supersonic.chat.server.util.LLMConnHelper;
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import com.tencent.supersonic.common.config.PromptConfig;
|
||||
import com.tencent.supersonic.common.config.VisualConfig;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -121,6 +122,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO>
|
||||
agent.setAgentConfig(agentDO.getConfig());
|
||||
agent.setExamples(JsonUtil.toList(agentDO.getExamples(), String.class));
|
||||
agent.setLlmConfig(JsonUtil.toObject(agentDO.getLlmConfig(), LLMConfig.class));
|
||||
agent.setPromptConfig(JsonUtil.toObject(agentDO.getPromptConfig(), PromptConfig.class));
|
||||
agent.setMultiTurnConfig(JsonUtil.toObject(agentDO.getMultiTurnConfig(), MultiTurnConfig.class));
|
||||
agent.setVisualConfig(JsonUtil.toObject(agentDO.getVisualConfig(), VisualConfig.class));
|
||||
return agent;
|
||||
@@ -134,6 +136,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO>
|
||||
agentDO.setLlmConfig(JsonUtil.toString(agent.getLlmConfig()));
|
||||
agentDO.setMultiTurnConfig(JsonUtil.toString(agent.getMultiTurnConfig()));
|
||||
agentDO.setVisualConfig(JsonUtil.toString(agent.getVisualConfig()));
|
||||
agentDO.setPromptConfig(JsonUtil.toString(agent.getPromptConfig()));
|
||||
if (agentDO.getStatus() == null) {
|
||||
agentDO.setStatus(1);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class QueryReqConverter {
|
||||
queryReq.setMapInfo(queryReq.getMapInfo());
|
||||
}
|
||||
queryReq.setLlmConfig(agent.getLlmConfig());
|
||||
queryReq.setPromptConfig(agent.getPromptConfig());
|
||||
return queryReq;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user