Skip to content

Commit a5499eb

Browse files
committed
Update the prompts
1 parent 03b5f0d commit a5499eb

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

text_2_sql/autogen/agentic_text_2_sql.ipynb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,25 @@
3535
"metadata": {},
3636
"outputs": [],
3737
"source": [
38-
"await SELECTOR.run(task=\"What are the top sales this month?\")"
38+
"result = await SELECTOR.run(task=\"What are the total number of sales within 2008?\")"
3939
]
4040
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"print(result.messages[-1].content)"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": []
56+
},
4157
{
4258
"cell_type": "code",
4359
"execution_count": null,

text_2_sql/autogen/prompts/sql_query_generation_agent.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ description:
33
system_message:
44
"You are a helpful AI Assistant that specialises in writing and executing SQL Queries to answer a given user's question.
55
6+
If you need more information from the user to generate the SQL query, ask the user for the information you need with a question and end your answer with 'TERMINATE'.
7+
68
Only use schema / column information provided when constructing a SQL query. Do not use any other entities and columns in your SQL query, other than those defined above.
79
Do not makeup or guess column names.
810

text_2_sql/autogen/prompts/sql_schema_selection_agent.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
description:
22
An agent that can take a user's question and extract the schema of a view or table in the SQL Database by selecting the most relevant entity based on the search term.
3+
4+
Call this in parallel if needed multiple times. Limit the use of this agent where possible.
35
system_message:
46
You are a helpful AI Assistant that specialises in selecting relevant SQL schemas to answer a given user's question.
57

text_2_sql/autogen/utils/sql_utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ async def get_entity_schemas(
1818
str,
1919
"The text to run a semantic search against. Relevant entities will be returned.",
2020
],
21+
excluded_entities: Annotated[
22+
list[str],
23+
"The entities to exclude from the search results. Pass the entity property of entities (e.g. 'SalesLT.Address') you already have the schemas for to avoid getting repeated entities.",
24+
] = [],
2125
) -> str:
2226
"""Gets the schema of a view or table in the SQL Database by selecting the most relevant entity based on the search term. Several entities may be returned.
2327
@@ -50,6 +54,13 @@ async def get_entity_schemas(
5054
database = os.environ["Text2Sql__DatabaseName"]
5155
schema["SelectFromEntity"] = f"{database}.{entity}"
5256

57+
filtered_schemas = []
58+
for excluded_entity in excluded_entities:
59+
if excluded_entity.lower() == entity.lower():
60+
logging.info("Excluded entity: %s", excluded_entity)
61+
else:
62+
filtered_schemas.append(schema)
63+
5364
return json.dumps(schemas, default=str)
5465

5566

@@ -92,7 +103,7 @@ async def fetch_queries_from_cache(question: str) -> str:
92103
cached_schemas = await run_ai_search_query(
93104
question,
94105
["QuestionEmbedding"],
95-
["Question", "SqlQueryDecomposition", "Schemas"],
106+
["Question", "SqlQueryDecomposition"],
96107
os.environ["AIService__AzureSearchOptions__Text2SqlQueryCache__Index"],
97108
os.environ["AIService__AzureSearchOptions__Text2SqlQueryCache__SemanticConfig"],
98109
top=1,
@@ -101,7 +112,7 @@ async def fetch_queries_from_cache(question: str) -> str:
101112
)
102113

103114
if len(cached_schemas) == 0:
104-
return None
115+
return {"cached_questions": None}
105116

106117
logging.info("Cached schemas: %s", cached_schemas)
107118
if PRE_RUN_QUERY_CACHE and len(cached_schemas) > 0:

0 commit comments

Comments
 (0)