Skip to content

Commit cbc154e

Browse files
authored
chore(wren-ai-service): improve text2sql (#1846)
1 parent 385e91d commit cbc154e

File tree

1 file changed

+14
-12
lines changed
  • wren-ai-service/src/pipelines/generation/utils

1 file changed

+14
-12
lines changed

wren-ai-service/src/pipelines/generation/utils/sql.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,18 @@ async def _classify_generation_result(
185185
2. Explicitly state the following information in the reasoning plan:
186186
if the user puts any specific timeframe(e.g. YYYY-MM-DD) in the user's question, you will put the absolute time frame in the SQL query;
187187
Otherwise, you will put the relative timeframe in the SQL query.
188-
3. For the ranking problem, you should use the ranking function, `DENSE_RANK()` to rank the results and then use `WHERE` clause to filter the results.
189-
4. If USER INSTRUCTIONS section is provided, make sure to consider them in the reasoning plan.
190-
5. If SQL SAMPLES section is provided, make sure to consider them in the reasoning plan.
191-
6. Give a step by step reasoning plan in order to answer user's question.
192-
7. The reasoning plan should be in the language same as the language user provided in the input.
193-
8. Don't include SQL in the reasoning plan.
194-
9. Each step in the reasoning plan must start with a number, a title(in bold format in markdown), and a reasoning for the step.
195-
10. Do not include ```markdown or ``` in the answer.
196-
11. A table name in the reasoning plan must be in this format: `table: <table_name>`.
197-
12. A column name in the reasoning plan must be in this format: `column: <table_name>.<column_name>`.
198-
13. ONLY SHOWING the reasoning plan in bullet points.
188+
3. For the ranking problem, you must use the ranking function, `DENSE_RANK()` to rank the results and then use `WHERE` clause to filter the results.
189+
4. For the ranking problem, you must add the ranking column to the final SELECT clause.
190+
5. If USER INSTRUCTIONS section is provided, make sure to consider them in the reasoning plan.
191+
6. If SQL SAMPLES section is provided, make sure to consider them in the reasoning plan.
192+
7. Give a step by step reasoning plan in order to answer user's question.
193+
8. The reasoning plan should be in the language same as the language user provided in the input.
194+
9. Don't include SQL in the reasoning plan.
195+
10. Each step in the reasoning plan must start with a number, a title(in bold format in markdown), and a reasoning for the step.
196+
11. Do not include ```markdown or ``` in the answer.
197+
12. A table name in the reasoning plan must be in this format: `table: <table_name>`.
198+
13. A column name in the reasoning plan must be in this format: `column: <table_name>.<column_name>`.
199+
14. ONLY SHOWING the reasoning plan in bullet points.
199200
200201
### FINAL ANSWER FORMAT ###
201202
The final answer must be a reasoning plan in plain Markdown string format
@@ -251,7 +252,8 @@ async def _classify_generation_result(
251252
- DON'T USE INTERVAL or generate INTERVAL-like expression in the generated SQL query.
252253
- Aggregate functions are not allowed in the WHERE clause. Instead, they belong in the HAVING clause, which is used to filter after aggregation.
253254
- You can only add "ORDER BY" and "LIMIT" to the final "UNION" result.
254-
- For the ranking problem, use `DENSE_RANK()` to rank the results and then use `WHERE` clause to filter the results.
255+
- For the ranking problem, you must use the ranking function, `DENSE_RANK()` to rank the results and then use `WHERE` clause to filter the results.
256+
- For the ranking problem, you must add the ranking column to the final SELECT clause.
255257
"""
256258

257259
sql_generation_system_prompt = f"""

0 commit comments

Comments
 (0)