mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
add new chat corrector
在助理最终执行物理SQL前,加入一步LLM优化性能功能
This commit is contained in:
@@ -75,8 +75,12 @@ public class SqlExecutor implements ChatQueryExecutor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuerySqlReq sqlReq =
|
// 使用querySQL,它已经包含了所有修正(包括物理SQL修正)
|
||||||
QuerySqlReq.builder().sql(parseInfo.getSqlInfo().getCorrectedS2SQL()).build();
|
String finalSql = StringUtils.isNotBlank(parseInfo.getSqlInfo().getQuerySQL())
|
||||||
|
? parseInfo.getSqlInfo().getQuerySQL()
|
||||||
|
: parseInfo.getSqlInfo().getCorrectedS2SQL();
|
||||||
|
|
||||||
|
QuerySqlReq sqlReq = QuerySqlReq.builder().sql(finalSql).build();
|
||||||
sqlReq.setSqlInfo(parseInfo.getSqlInfo());
|
sqlReq.setSqlInfo(parseInfo.getSqlInfo());
|
||||||
sqlReq.setDataSetId(parseInfo.getDataSetId());
|
sqlReq.setDataSetId(parseInfo.getDataSetId());
|
||||||
|
|
||||||
@@ -90,7 +94,7 @@ public class SqlExecutor implements ChatQueryExecutor {
|
|||||||
queryResult.setQueryTimeCost(System.currentTimeMillis() - startTime);
|
queryResult.setQueryTimeCost(System.currentTimeMillis() - startTime);
|
||||||
if (queryResp != null) {
|
if (queryResp != null) {
|
||||||
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
||||||
queryResult.setQuerySql(queryResp.getSql());
|
queryResult.setQuerySql(finalSql);
|
||||||
queryResult.setQueryResults(queryResp.getResultList());
|
queryResult.setQueryResults(queryResp.getResultList());
|
||||||
queryResult.setQueryColumns(queryResp.getColumns());
|
queryResult.setQueryColumns(queryResp.getColumns());
|
||||||
queryResult.setQueryState(QueryState.SUCCESS);
|
queryResult.setQueryState(QueryState.SUCCESS);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO> implem
|
|||||||
private MemoryService memoryService;
|
private MemoryService memoryService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Lazy
|
||||||
private ChatQueryService chatQueryService;
|
private ChatQueryService chatQueryService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import net.sf.jsqlparser.schema.Column;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SemanticLayerService semanticLayerService;
|
private SemanticLayerService semanticLayerService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Lazy
|
||||||
private AgentService agentService;
|
private AgentService agentService;
|
||||||
|
|
||||||
private final List<ChatQueryParser> chatQueryParsers = ComponentFactory.getChatParsers();
|
private final List<ChatQueryParser> chatQueryParsers = ComponentFactory.getChatParsers();
|
||||||
|
|||||||
@@ -16,4 +16,7 @@ public class SqlInfo implements Serializable {
|
|||||||
|
|
||||||
// SQL to be executed finally
|
// SQL to be executed finally
|
||||||
private String querySQL;
|
private String querySQL;
|
||||||
|
|
||||||
|
// Physical SQL corrected by LLM for performance optimization
|
||||||
|
private String correctedQuerySQL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ public enum ChatWorkflowState {
|
|||||||
VALIDATING,
|
VALIDATING,
|
||||||
SQL_CORRECTING,
|
SQL_CORRECTING,
|
||||||
PROCESSING,
|
PROCESSING,
|
||||||
|
PHYSICAL_SQL_CORRECTING,
|
||||||
FINISHED
|
FINISHED
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package com.tencent.supersonic.headless.chat.corrector;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.common.pojo.ChatApp;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.AppModule;
|
||||||
|
import com.tencent.supersonic.common.util.ChatAppManager;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||||
|
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||||
|
import dev.langchain4j.model.input.Prompt;
|
||||||
|
import dev.langchain4j.model.input.PromptTemplate;
|
||||||
|
import dev.langchain4j.model.output.structured.Description;
|
||||||
|
import dev.langchain4j.provider.ModelProvider;
|
||||||
|
import dev.langchain4j.service.AiServices;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物理SQL修正器 - 使用LLM优化物理SQL性能
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class LLMPhysicalSqlCorrector extends BaseSemanticCorrector {
|
||||||
|
|
||||||
|
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
||||||
|
|
||||||
|
public static final String APP_KEY = "PHYSICAL_SQL_CORRECTOR";
|
||||||
|
private static final String INSTRUCTION = ""
|
||||||
|
+ "#Role: You are a senior database performance optimization expert experienced in SQL tuning."
|
||||||
|
+ "\n\n#Task: You will be provided with a user question and the corresponding physical SQL query,"
|
||||||
|
+ " please analyze and optimize this SQL to improve query performance." + "\n\n#Rules:"
|
||||||
|
+ "\n1. ALWAYS add appropriate index hints if the database supports them."
|
||||||
|
+ "\n2. Optimize JOIN order by placing smaller tables first."
|
||||||
|
+ "\n3. Add reasonable query limits to prevent large result sets if no LIMIT exists."
|
||||||
|
+ "\n4. Optimize WHERE condition order by placing high-selectivity conditions first."
|
||||||
|
+ "\n5. Ensure the optimized SQL is syntactically correct and logically equivalent."
|
||||||
|
+ "\n6. If the SQL is already well-optimized, return 'positive'."
|
||||||
|
+ "\n\n#Question: {{question}}" + "\n\n#OriginalSQL: {{sql}}" + "\n\n#Response:";
|
||||||
|
|
||||||
|
public LLMPhysicalSqlCorrector() {
|
||||||
|
ChatAppManager.register(APP_KEY, ChatApp.builder().prompt(INSTRUCTION).name("物理SQL修正")
|
||||||
|
.appModule(AppModule.CHAT).description("通过大模型对物理SQL做性能优化").enable(false).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
static class PhysicalSql {
|
||||||
|
@Description("either positive or negative")
|
||||||
|
private String opinion;
|
||||||
|
|
||||||
|
@Description("optimized sql if negative")
|
||||||
|
private String sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PhysicalSqlExtractor {
|
||||||
|
PhysicalSql generatePhysicalSql(String text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doCorrect(ChatQueryContext chatQueryContext, SemanticParseInfo semanticParseInfo) {
|
||||||
|
ChatApp chatApp = chatQueryContext.getRequest().getChatAppConfig().get(APP_KEY);
|
||||||
|
if (!chatQueryContext.getRequest().getText2SQLType().enableLLM() || Objects.isNull(chatApp)
|
||||||
|
|| !chatApp.isEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatLanguageModel chatLanguageModel =
|
||||||
|
ModelProvider.getChatModel(chatApp.getChatModelConfig());
|
||||||
|
PhysicalSqlExtractor extractor =
|
||||||
|
AiServices.create(PhysicalSqlExtractor.class, chatLanguageModel);
|
||||||
|
Prompt prompt = generatePrompt(chatQueryContext.getRequest().getQueryText(),
|
||||||
|
semanticParseInfo, chatApp.getPrompt());
|
||||||
|
PhysicalSql physicalSql =
|
||||||
|
extractor.generatePhysicalSql(prompt.toUserMessage().singleText());
|
||||||
|
keyPipelineLog.info("LLMPhysicalSqlCorrector modelReq:\n{} \nmodelResp:\n{}", prompt.text(),
|
||||||
|
physicalSql);
|
||||||
|
if ("NEGATIVE".equalsIgnoreCase(physicalSql.getOpinion())
|
||||||
|
&& StringUtils.isNotBlank(physicalSql.getSql())) {
|
||||||
|
semanticParseInfo.getSqlInfo().setCorrectedQuerySQL(physicalSql.getSql());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Prompt generatePrompt(String queryText, SemanticParseInfo semanticParseInfo,
|
||||||
|
String promptTemplate) {
|
||||||
|
Map<String, Object> variable = new HashMap<>();
|
||||||
|
variable.put("question", queryText);
|
||||||
|
variable.put("sql", semanticParseInfo.getSqlInfo().getQuerySQL());
|
||||||
|
|
||||||
|
return PromptTemplate.from(promptTemplate).apply(variable);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,7 +52,8 @@ public class PromptHelper {
|
|||||||
for (int i = 0; i < selfConsistencyNumber; i++) {
|
for (int i = 0; i < selfConsistencyNumber; i++) {
|
||||||
List<Text2SQLExemplar> shuffledList = new ArrayList<>(exemplars);
|
List<Text2SQLExemplar> shuffledList = new ArrayList<>(exemplars);
|
||||||
// only shuffle the exemplars from config
|
// only shuffle the exemplars from config
|
||||||
List<Text2SQLExemplar> subList=shuffledList.subList(llmReq.getDynamicExemplars().size(),shuffledList.size());
|
List<Text2SQLExemplar> subList =
|
||||||
|
shuffledList.subList(llmReq.getDynamicExemplars().size(), shuffledList.size());
|
||||||
Collections.shuffle(subList);
|
Collections.shuffle(subList);
|
||||||
results.add(shuffledList.subList(0, Math.min(shuffledList.size(), fewShotNumber)));
|
results.add(shuffledList.subList(0, Math.min(shuffledList.size(), fewShotNumber)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.tencent.supersonic.headless.api.pojo.request.SemanticQueryReq;
|
|||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticTranslateResp;
|
import com.tencent.supersonic.headless.api.pojo.response.SemanticTranslateResp;
|
||||||
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||||
|
import com.tencent.supersonic.headless.chat.corrector.LLMPhysicalSqlCorrector;
|
||||||
import com.tencent.supersonic.headless.chat.corrector.SemanticCorrector;
|
import com.tencent.supersonic.headless.chat.corrector.SemanticCorrector;
|
||||||
import com.tencent.supersonic.headless.chat.mapper.SchemaMapper;
|
import com.tencent.supersonic.headless.chat.mapper.SchemaMapper;
|
||||||
import com.tencent.supersonic.headless.chat.parser.SemanticParser;
|
import com.tencent.supersonic.headless.chat.parser.SemanticParser;
|
||||||
@@ -76,6 +77,10 @@ public class ChatWorkflowEngine {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
performTranslating(queryCtx, parseResult);
|
performTranslating(queryCtx, parseResult);
|
||||||
parseResult.getParseTimeCost().setSqlTime(System.currentTimeMillis() - start);
|
parseResult.getParseTimeCost().setSqlTime(System.currentTimeMillis() - start);
|
||||||
|
queryCtx.setChatWorkflowState(ChatWorkflowState.PHYSICAL_SQL_CORRECTING);
|
||||||
|
break;
|
||||||
|
case PHYSICAL_SQL_CORRECTING:
|
||||||
|
performPhysicalSqlCorrecting(queryCtx);
|
||||||
queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED);
|
queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -162,4 +167,25 @@ public class ChatWorkflowEngine {
|
|||||||
parseResult.setErrorMsg(String.join("\n", errorMsg));
|
parseResult.setErrorMsg(String.join("\n", errorMsg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void performPhysicalSqlCorrecting(ChatQueryContext queryCtx) {
|
||||||
|
List<SemanticQuery> candidateQueries = queryCtx.getCandidateQueries();
|
||||||
|
if (CollectionUtils.isNotEmpty(candidateQueries)) {
|
||||||
|
for (SemanticQuery semanticQuery : candidateQueries) {
|
||||||
|
for (SemanticCorrector corrector : semanticCorrectors) {
|
||||||
|
if (corrector instanceof LLMPhysicalSqlCorrector) {
|
||||||
|
corrector.correct(queryCtx, semanticQuery.getParseInfo());
|
||||||
|
// 如果物理SQL被修正了,更新querySQL为修正后的版本
|
||||||
|
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||||
|
if (StringUtils.isNotBlank(parseInfo.getSqlInfo().getCorrectedQuerySQL())) {
|
||||||
|
parseInfo.getSqlInfo().setQuerySQL(parseInfo.getSqlInfo().getCorrectedQuerySQL());
|
||||||
|
log.info("Physical SQL corrected and updated querySQL: {}",
|
||||||
|
parseInfo.getSqlInfo().getQuerySQL());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ com.tencent.supersonic.headless.chat.parser.SemanticParser=\
|
|||||||
|
|
||||||
com.tencent.supersonic.headless.chat.corrector.SemanticCorrector=\
|
com.tencent.supersonic.headless.chat.corrector.SemanticCorrector=\
|
||||||
com.tencent.supersonic.headless.chat.corrector.RuleSqlCorrector,\
|
com.tencent.supersonic.headless.chat.corrector.RuleSqlCorrector,\
|
||||||
com.tencent.supersonic.headless.chat.corrector.LLMSqlCorrector
|
com.tencent.supersonic.headless.chat.corrector.LLMSqlCorrector,\
|
||||||
|
com.tencent.supersonic.headless.chat.corrector.LLMPhysicalSqlCorrector
|
||||||
|
|
||||||
com.tencent.supersonic.headless.chat.knowledge.file.FileHandler=\
|
com.tencent.supersonic.headless.chat.knowledge.file.FileHandler=\
|
||||||
com.tencent.supersonic.headless.chat.knowledge.file.FileHandlerImpl
|
com.tencent.supersonic.headless.chat.knowledge.file.FileHandlerImpl
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ com.tencent.supersonic.headless.chat.parser.SemanticParser=\
|
|||||||
|
|
||||||
com.tencent.supersonic.headless.chat.corrector.SemanticCorrector=\
|
com.tencent.supersonic.headless.chat.corrector.SemanticCorrector=\
|
||||||
com.tencent.supersonic.headless.chat.corrector.RuleSqlCorrector,\
|
com.tencent.supersonic.headless.chat.corrector.RuleSqlCorrector,\
|
||||||
com.tencent.supersonic.headless.chat.corrector.LLMSqlCorrector
|
com.tencent.supersonic.headless.chat.corrector.LLMSqlCorrector,\
|
||||||
|
com.tencent.supersonic.headless.chat.corrector.LLMPhysicalSqlCorrector
|
||||||
|
|
||||||
com.tencent.supersonic.headless.chat.knowledge.file.FileHandler=\
|
com.tencent.supersonic.headless.chat.knowledge.file.FileHandler=\
|
||||||
com.tencent.supersonic.headless.chat.knowledge.file.FileHandlerImpl
|
com.tencent.supersonic.headless.chat.knowledge.file.FileHandlerImpl
|
||||||
|
|||||||
10
pom.xml
10
pom.xml
@@ -10,9 +10,9 @@
|
|||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
<module>common</module>
|
||||||
<module>auth</module>
|
<module>auth</module>
|
||||||
<module>chat</module>
|
<module>chat</module>
|
||||||
<module>common</module>
|
|
||||||
<module>launchers</module>
|
<module>launchers</module>
|
||||||
<module>headless</module>
|
<module>headless</module>
|
||||||
</modules>
|
</modules>
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
<java.target.version>21</java.target.version>
|
<java.target.version>21</java.target.version>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<maven.compiler.release>21</maven.compiler.release>
|
||||||
<file.encoding>UTF-8</file.encoding>
|
<file.encoding>UTF-8</file.encoding>
|
||||||
<jsqlparser.version>4.9</jsqlparser.version>
|
<jsqlparser.version>4.9</jsqlparser.version>
|
||||||
<pagehelper.version>6.1.0</pagehelper.version>
|
<pagehelper.version>6.1.0</pagehelper.version>
|
||||||
@@ -254,6 +255,13 @@
|
|||||||
<source>${java.source.version}</source>
|
<source>${java.source.version}</source>
|
||||||
<target>${java.target.version}</target>
|
<target>${java.target.version}</target>
|
||||||
<encoding>${file.encoding}</encoding>
|
<encoding>${file.encoding}</encoding>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
5
webapp/package.json
Normal file
5
webapp/package.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"supersonic-chat-sdk": "link:packages/chat-sdk"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,6 +79,7 @@ export type SqlInfoType = {
|
|||||||
parsedS2SQL: string;
|
parsedS2SQL: string;
|
||||||
correctedS2SQL: string;
|
correctedS2SQL: string;
|
||||||
querySQL: string;
|
querySQL: string;
|
||||||
|
correctedQuerySQL?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ChatContextType = {
|
export type ChatContextType = {
|
||||||
|
|||||||
@@ -58,32 +58,28 @@ const SqlItem: React.FC<Props> = ({
|
|||||||
const getSchemaMapText = () => {
|
const getSchemaMapText = () => {
|
||||||
return `
|
return `
|
||||||
Schema映射
|
Schema映射
|
||||||
${schema?.fieldNameList?.length > 0 ? `名称:${schema.fieldNameList.join('、')}` : ''}${
|
${schema?.fieldNameList?.length > 0 ? `名称:${schema.fieldNameList.join('、')}` : ''}${schema?.values?.length > 0
|
||||||
schema?.values?.length > 0
|
|
||||||
? `
|
? `
|
||||||
取值:${schema.values
|
取值:${schema.values
|
||||||
.map((item: any) => {
|
.map((item: any) => {
|
||||||
return `${item.fieldName}: ${item.fieldValue}`;
|
return `${item.fieldName}: ${item.fieldValue}`;
|
||||||
})
|
})
|
||||||
.join('、')}`
|
.join('、')}`
|
||||||
: ''
|
: ''
|
||||||
}${
|
}${priorExts
|
||||||
priorExts
|
|
||||||
? `
|
? `
|
||||||
附加:${priorExts}`
|
附加:${priorExts}`
|
||||||
: ''
|
: ''
|
||||||
}${
|
}${terms?.length > 0
|
||||||
terms?.length > 0
|
|
||||||
? `
|
? `
|
||||||
术语:${terms
|
术语:${terms
|
||||||
.map((item: any) => {
|
.map((item: any) => {
|
||||||
return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''}: ${
|
return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''}: ${item.description
|
||||||
item.description
|
|
||||||
}`;
|
}`;
|
||||||
})
|
})
|
||||||
.join('、')}`
|
.join('、')}`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
@@ -91,16 +87,16 @@ ${schema?.fieldNameList?.length > 0 ? `名称:${schema.fieldNameList.join('、
|
|||||||
const getFewShotText = () => {
|
const getFewShotText = () => {
|
||||||
return `
|
return `
|
||||||
Few-shot示例${fewShots
|
Few-shot示例${fewShots
|
||||||
.map((item: any, index: number) => {
|
.map((item: any, index: number) => {
|
||||||
return `
|
return `
|
||||||
|
|
||||||
示例${index + 1}:
|
示例${index + 1}:
|
||||||
问题:${item.question}
|
问题:${item.question}
|
||||||
SQL:
|
SQL:
|
||||||
${format(item.sql)}
|
${format(item.sql)}
|
||||||
`;
|
`;
|
||||||
})
|
})
|
||||||
.join('')}
|
.join('')}
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,6 +116,14 @@ ${format(sqlInfo.correctedS2SQL)}
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCorrectedQuerySQLText = () => {
|
||||||
|
return `
|
||||||
|
物理SQL修正
|
||||||
|
|
||||||
|
${format(sqlInfo.correctedQuerySQL || '')}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
const getQuerySQLText = () => {
|
const getQuerySQLText = () => {
|
||||||
return `
|
return `
|
||||||
最终执行SQL
|
最终执行SQL
|
||||||
@@ -155,6 +159,9 @@ ${executeErrorMsg}
|
|||||||
if (sqlInfo.correctedS2SQL) {
|
if (sqlInfo.correctedS2SQL) {
|
||||||
text += getCorrectedS2SQLText();
|
text += getCorrectedS2SQLText();
|
||||||
}
|
}
|
||||||
|
if (sqlInfo.correctedQuerySQL) {
|
||||||
|
text += getCorrectedQuerySQLText();
|
||||||
|
}
|
||||||
if (sqlInfo.querySQL) {
|
if (sqlInfo.querySQL) {
|
||||||
text += getQuerySQLText();
|
text += getQuerySQLText();
|
||||||
}
|
}
|
||||||
@@ -183,9 +190,8 @@ ${executeErrorMsg}
|
|||||||
<div className={`${tipPrefixCls}-content-options`}>
|
<div className={`${tipPrefixCls}-content-options`}>
|
||||||
{llmReq && (
|
{llmReq && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${sqlType === 'schemaMap' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
sqlType === 'schemaMap' ? `${tipPrefixCls}-content-option-active` : ''
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSqlType(sqlType === 'schemaMap' ? '' : 'schemaMap');
|
setSqlType(sqlType === 'schemaMap' ? '' : 'schemaMap');
|
||||||
}}
|
}}
|
||||||
@@ -195,9 +201,8 @@ ${executeErrorMsg}
|
|||||||
)}
|
)}
|
||||||
{fewShots.length > 0 && (
|
{fewShots.length > 0 && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${sqlType === 'fewShots' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
sqlType === 'fewShots' ? `${tipPrefixCls}-content-option-active` : ''
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSqlType(sqlType === 'fewShots' ? '' : 'fewShots');
|
setSqlType(sqlType === 'fewShots' ? '' : 'fewShots');
|
||||||
}}
|
}}
|
||||||
@@ -207,9 +212,8 @@ ${executeErrorMsg}
|
|||||||
)}
|
)}
|
||||||
{sqlInfo.parsedS2SQL && (
|
{sqlInfo.parsedS2SQL && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${sqlType === 'parsedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
sqlType === 'parsedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSqlType(sqlType === 'parsedS2SQL' ? '' : 'parsedS2SQL');
|
setSqlType(sqlType === 'parsedS2SQL' ? '' : 'parsedS2SQL');
|
||||||
}}
|
}}
|
||||||
@@ -219,9 +223,8 @@ ${executeErrorMsg}
|
|||||||
)}
|
)}
|
||||||
{sqlInfo.correctedS2SQL && (
|
{sqlInfo.correctedS2SQL && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${sqlType === 'correctedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
sqlType === 'correctedS2SQL' ? `${tipPrefixCls}-content-option-active` : ''
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSqlType(sqlType === 'correctedS2SQL' ? '' : 'correctedS2SQL');
|
setSqlType(sqlType === 'correctedS2SQL' ? '' : 'correctedS2SQL');
|
||||||
}}
|
}}
|
||||||
@@ -229,16 +232,26 @@ ${executeErrorMsg}
|
|||||||
修正S2SQL
|
修正S2SQL
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{sqlInfo.correctedQuerySQL && (
|
||||||
|
<div
|
||||||
|
className={`${tipPrefixCls}-content-option ${sqlType === 'correctedQuerySQL' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
|
}`}
|
||||||
|
onClick={() => {
|
||||||
|
setSqlType(sqlType === 'correctedQuerySQL' ? '' : 'correctedQuerySQL');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
物理SQL修正
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{sqlInfo.querySQL && (
|
{sqlInfo.querySQL && (
|
||||||
<div
|
<div
|
||||||
className={`${tipPrefixCls}-content-option ${
|
className={`${tipPrefixCls}-content-option ${sqlType === 'querySQL' ? `${tipPrefixCls}-content-option-active` : ''
|
||||||
sqlType === 'querySQL' ? `${tipPrefixCls}-content-option-active` : ''
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSqlType(sqlType === 'querySQL' ? '' : 'querySQL');
|
setSqlType(sqlType === 'querySQL' ? '' : 'querySQL');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
最终执行SQL
|
{sqlInfo.correctedQuerySQL ? '最终执行SQL' : '最终执行SQL'}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Button className={`${prefixCls}-export-log`} size="small" onClick={onExportLog}>
|
<Button className={`${prefixCls}-export-log`} size="small" onClick={onExportLog}>
|
||||||
@@ -248,13 +261,12 @@ ${executeErrorMsg}
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`${prefixCls} ${
|
className={`${prefixCls} ${!window.location.pathname.includes('/chat') &&
|
||||||
!window.location.pathname.includes('/chat') &&
|
|
||||||
integrateSystem &&
|
integrateSystem &&
|
||||||
integrateSystem !== 'wiki'
|
integrateSystem !== 'wiki'
|
||||||
? `${prefixCls}-copilot`
|
? `${prefixCls}-copilot`
|
||||||
: ''
|
: ''
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{sqlType === 'schemaMap' && (
|
{sqlType === 'schemaMap' && (
|
||||||
<div className={`${prefixCls}-code`}>
|
<div className={`${prefixCls}-code`}>
|
||||||
@@ -290,9 +302,8 @@ ${executeErrorMsg}
|
|||||||
<div className={`${prefixCls}-schema-content`}>
|
<div className={`${prefixCls}-schema-content`}>
|
||||||
{terms
|
{terms
|
||||||
.map((item: any) => {
|
.map((item: any) => {
|
||||||
return `${item.name}${
|
return `${item.name}${item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''
|
||||||
item.alias?.length > 0 ? `(${item.alias.join(',')})` : ''
|
}: ${item.description}`;
|
||||||
}: ${item.description}`;
|
|
||||||
})
|
})
|
||||||
.join('、')}
|
.join('、')}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user