-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
223 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
querybook/server/lib/ai_assistant/prompts/sql_edit_prompt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from langchain.prompts import PromptTemplate | ||
|
||
prompt_template = """ | ||
You are a {dialect} expert. | ||
Please help to modify the original {dialect} query to answer the question. Your response should ONLY be based on the given context and follow the response guidelines and format instructions. | ||
===Tables | ||
{table_schemas} | ||
===Original Query | ||
{original_query} | ||
===Response Guidelines | ||
1. If the provided context is sufficient, please modify and generate a valid query without any explanations for the question. The query should start with a comment containing the question being asked. | ||
2. If the provided context is insufficient, please explain why it can't be generated. | ||
3. The original query may start with a comment containing a previously asked question. If you find such a comment, please use both the original question and the new question to modify the query, and update the comment accordingly. | ||
4. Please use the most relevant table(s). | ||
5. Please format the query before responding. | ||
6. Please always respond with a valid well-formed JSON object with the following format | ||
===Response Format | ||
{{ | ||
"query": "A generated SQL query when context is sufficient.", | ||
"explanation": "An explanation of failing to generate the query." | ||
}} | ||
===Question | ||
{question} | ||
""" | ||
|
||
SQL_EDIT_PROMPT = PromptTemplate.from_template(prompt_template) |
57 changes: 26 additions & 31 deletions
57
querybook/server/lib/ai_assistant/prompts/sql_fix_prompt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
from langchain import PromptTemplate | ||
|
||
|
||
prompt_template = ( | ||
"You are a SQL expert that can help fix SQL query errors.\n\n" | ||
"Please help fix the query below based on the given error message and table schemas. \n\n" | ||
"===SQL dialect\n" | ||
"{dialect}\n\n" | ||
"===Query\n" | ||
"{query}\n\n" | ||
"===Error\n" | ||
"{error}\n\n" | ||
"===Table Schemas\n" | ||
"{table_schemas}\n\n" | ||
"===Response Format\n" | ||
"<@key-1@>\n" | ||
"value-1\n\n" | ||
"<@key-2@>\n" | ||
"value-2\n\n" | ||
"===Example response:\n" | ||
"<@explanation@>\n" | ||
"This is an explanation about the error\n\n" | ||
"<@fix_suggestion@>\n" | ||
"This is a recommended fix for the error\n\n" | ||
"<@fixed_query@>\n" | ||
"The fixed SQL query\n\n" | ||
"===Response Guidelines\n" | ||
"1. For the <@fixed_query@> section, it can only be a valid SQL query without any explanation.\n" | ||
"2. If there is insufficient context to address the query error, you may leave the fixed_query section blank and provide a general suggestion instead.\n" | ||
"3. Maintain the original query format and case in the fixed_query section, including comments, except when correcting the erroneous part.\n" | ||
) | ||
from langchain.prompts import PromptTemplate | ||
|
||
|
||
prompt_template = """You are a {dialect} expert that can help fix SQL query errors. | ||
Please help fix below {dialect} query based on the given error message and table schemas. | ||
===Query | ||
{query} | ||
===Error | ||
{error} | ||
===Table Schemas | ||
{table_schemas} | ||
===Response Guidelines | ||
1. If there is insufficient context to address the query error, please leave fixed_query blank and provide a general suggestion instead. | ||
2. Maintain the original query format and case for the fixed_query, including comments, except when correcting the erroneous part. | ||
===Response Format | ||
{{ | ||
"explanation": "An explanation about the error", | ||
"fix_suggestion": "A recommended fix for the error"", | ||
"fixed_query": "A valid and well formatted fixed query" | ||
}} | ||
""" | ||
|
||
SQL_FIX_PROMPT = PromptTemplate.from_template(prompt_template) |
2 changes: 1 addition & 1 deletion
2
querybook/server/lib/ai_assistant/prompts/sql_summary_prompt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from langchain import PromptTemplate | ||
from langchain.prompts import PromptTemplate | ||
|
||
|
||
prompt_template = """ | ||
|
Oops, something went wrong.