From a0f53359ef5f88b296b8d1caa03bbda1258ce618 Mon Sep 17 00:00:00 2001 From: jerryjzhang Date: Sun, 17 Nov 2024 09:06:42 +0800 Subject: [PATCH] [improvement][chat]Iterate LLM prompts of parsing and correction. --- .../headless/chat/corrector/LLMSqlCorrector.java | 4 ++-- .../chat/parser/llm/OnePassSCSqlGenStrategy.java | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/corrector/LLMSqlCorrector.java b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/corrector/LLMSqlCorrector.java index 5f8335cc8..a8ebb910a 100644 --- a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/corrector/LLMSqlCorrector.java +++ b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/corrector/LLMSqlCorrector.java @@ -36,8 +36,8 @@ public class LLMSqlCorrector extends BaseSemanticCorrector { + "\n2.NO NEED to check date filters as the junior engineer seldom makes mistakes in this regard." + "\n3.DO NOT miss the AGGREGATE operator of metrics, always add it as needed." + "\n4.ALWAYS use `with` statement if nested aggregation is needed." - + "\n5.ALWAYS enclose alias created by `AS` command in underscores." - + "\n6.ALWAYS translate alias created by `AS` command to the same language as the `#Question`." + + "\n5.ALWAYS enclose alias declared by `AS` command in underscores." + + "\n6.Alias created by `AS` command must be in the same language ast the `Question`." + "\n#Question:{{question}} #InputSQL:{{sql}} #Response:"; public LLMSqlCorrector() { diff --git a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/parser/llm/OnePassSCSqlGenStrategy.java b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/parser/llm/OnePassSCSqlGenStrategy.java index fd5f176e3..a41be00ab 100644 --- a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/parser/llm/OnePassSCSqlGenStrategy.java +++ b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/parser/llm/OnePassSCSqlGenStrategy.java @@ -36,15 +36,13 @@ public class OnePassSCSqlGenStrategy extends SqlGenStrategy { + "\n#Task: You will be provided with a natural language question asked by users," + "please convert it to a SQL query so that relevant data could be returned " + "by executing the SQL query against underlying database." + "\n#Rules:" - + "\n1.ALWAYS generate columns and values specified in the `Schema`, DO NOT hallucinate." - + "\n2.ALWAYS be cautious, word in the `Schema` does not mean it must appear in the SQL." - + "\n3.ALWAYS specify date filter using `>`,`<`,`>=`,`<=` operator." - + "\n4.DO NOT include date filter in the where clause if not explicitly expressed in the `Question`." - + "\n5.DO NOT calculate date range using functions." - + "\n6.DO NOT miss the AGGREGATE operator of metrics, always add it as needed." - + "\n7.ALWAYS use `with` statement if nested aggregation is needed." - + "\n8.ALWAYS enclose alias created by `AS` command in underscores." - + "\n9.ALWAYS translate alias created by `AS` command to the same language as the `#Question`." + + "\n1.SQL columns and values must be mentioned in the `Schema`, DO NOT hallucinate." + + "\n2.ALWAYS specify date filter using `>`,`<`,`>=`,`<=` operator." + + "\n3.DO NOT include date filter in the where clause if not explicitly expressed in the `Question`." + + "\n4.DO NOT calculate date range using functions." + + "\n5.ALWAYS use `with` statement if nested aggregation is needed." + + "\n6.ALWAYS enclose alias declared by `AS` command in underscores." + + "\n7.Alias created by `AS` command must be in the same language ast the `Question`." + "\n#Exemplars: {{exemplar}}" + "\n#Query: Question:{{question}},Schema:{{schema}},SideInfo:{{information}}";