Skip to content

Commit

Permalink
Changing prompts to work like cache
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadrezaPourreza committed Mar 27, 2024
1 parent 7ea0148 commit 9c99fae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dataherald/sql_generator/dataherald_sqlagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class GetFewShotExamples(BaseSQLDatabaseTool, BaseTool):
Output: List of similar Question/SQL pairs related to the given question.
Use this tool to fetch previously asked Question/SQL pairs as examples for improving SQL query generation.
For complex questions, request more examples to gain a better understanding of tables and columns and the SQL keywords to use.
If the given question is very similar to one of the retrieved examples, it is recommended to use the same SQL query and modify it slightly to fit the given question.
If the given question is very similar to one of the retrieved examples, just return the SQL query from the example and avoid generating a new one.
Always use this tool first and before any other tool!
""" # noqa: E501
few_shot_examples: List[dict]
Expand All @@ -516,9 +516,9 @@ def _run(
else:
return "Action input for the fewshot_examples_retriever tool should be an integer"
returned_output = ""
for example in self.few_shot_examples[:number_of_samples]:
for example in reversed(self.few_shot_examples[:number_of_samples]):
returned_output += (
f"Question: {example['prompt_text']} -> SQL: {example['sql']}\n"
f"Question: {example['prompt_text']}\nSQL: {example['sql']}\n###\n"
)
if returned_output == "":
returned_output = "No previously asked Question/SQL pairs are available"
Expand Down
6 changes: 3 additions & 3 deletions dataherald/utils/agent_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#
Using `current_date()` or `current_datetime()` in SQL queries is banned, use SystemTime tool to get the exact time of the query execution.
If the question does not seem related to the database, return an empty string.
If the there is a very similar question among the fewshot examples, directly use the SQL query from the example and modify it to fit the given question and execute the query to make sure it is correct.
If the there is a very similar question among the fewshot examples, directly use the SQL query from the example.
The SQL query MUST have in-line comments to explain what each clause does.
""" # noqa: E501

PLAN_WITH_FEWSHOT_EXAMPLES_AND_INSTRUCTIONS = """1) Use the FewshotExamplesRetriever tool to retrieve samples of Question/SQL pairs that are similar to the given question, if there is a similar question among the examples, use the SQL query from the example and modify it to fit the given question.
PLAN_WITH_FEWSHOT_EXAMPLES_AND_INSTRUCTIONS = """1) Use the FewshotExamplesRetriever tool to retrieve samples of Question/SQL pairs that are similar to the given question, if there is a similar question among the examples, use the SQL query from the example.
2) Use the GetAdminInstructions tool to retrieve the DB admin instructions before calling other tools, to make sure you follow the instructions when writing the SQL query.
3) Use the DbTablesWithRelevanceScores tool to find relevant tables.
4) Use the DbRelevantTablesSchema tool to obtain the schema of possibly relevant tables to identify the possibly relevant columns.
Expand Down Expand Up @@ -50,7 +50,7 @@
tip6) If DBEntityChecker tool returns no entity values, you should still write a SQL query. But add a comment in the SQL query that the entity values were not found.
""" # noqa: E501

PLAN_WITH_FEWSHOT_EXAMPLES = """1) Use the FewshotExamplesRetriever tool to retrieve samples of Question/SQL pairs that are similar to the given question, if there is a similar question among the examples, use the SQL query from the example and modify it to fit the given question.
PLAN_WITH_FEWSHOT_EXAMPLES = """1) Use the FewshotExamplesRetriever tool to retrieve samples of Question/SQL pairs that are similar to the given question, if there is a similar question among the examples, use the SQL query from the example.
2) Use the DbTablesWithRelevanceScores tool to find relevant tables.
3) Use the DbRelevantTablesSchema tool to obtain the schema of possibly relevant tables to identify the possibly relevant columns.
4) Use the DbRelevantColumnsInfo tool to gather more information about the possibly relevant columns, filtering them to find the relevant ones.
Expand Down

0 comments on commit 9c99fae

Please sign in to comment.