Skip to content

Commit 44e548c

Browse files
committed
Update the prompts
1 parent 7e594f5 commit 44e548c

File tree

5 files changed

+89
-34
lines changed

5 files changed

+89
-34
lines changed

text_2_sql/autogen/Iteration 5 - Agentic Vector Based Text2SQL.ipynb

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,38 @@
9797
},
9898
{
9999
"cell_type": "code",
100-
"execution_count": null,
101-
"metadata": {},
102-
"outputs": [],
100+
"execution_count": 6,
101+
"metadata": {},
102+
"outputs": [
103+
{
104+
"name": "stderr",
105+
"output_type": "stream",
106+
"text": [
107+
"INFO:httpx:HTTP Request: POST https://aoai-text2sql-adi.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-08-01-preview \"HTTP/1.1 200 OK\"\n",
108+
"INFO:autogen_core.events:{\"prompt_tokens\": 62569, \"completion_tokens\": 191, \"type\": \"LLMCall\"}\n",
109+
"INFO:autogen_core:Publishing message of type GroupChatMessage to all subscribers: {'message': TextMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191), content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\", type='TextMessage')}\n",
110+
"INFO:autogen_core:Publishing message of type GroupChatAgentResponse to all subscribers: {'agent_response': Response(chat_message=TextMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191), content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\", type='TextMessage'), inner_messages=[ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=61958, completion_tokens=109), content=[FunctionCall(id='call_qK7sS44z4Q8sv1mkIDUKK3m4', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_execution_with_limit')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='Error: (\\'42000\\', \"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open server \\'text2sql-adventure-works\\' requested by the login. Client with IP address \\'82.132.236.64\\' is not allowed to access the server. To enable access, use the Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect. (40615) (SQLDriverConnect)\")', call_id='call_qK7sS44z4Q8sv1mkIDUKK3m4')], type='ToolCallResultMessage'), ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62203, completion_tokens=107), content=[FunctionCall(id='call_devGqBMptvn1ciEIOC85IDkx', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_validation')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='True', call_id='call_devGqBMptvn1ciEIOC85IDkx')], type='ToolCallResultMessage'), ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62324, completion_tokens=109), content=[FunctionCall(id='call_WJlHhiupbeHR452PktbpgVpJ', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_execution_with_limit')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='Error: (\\'42000\\', \"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open server \\'text2sql-adventure-works\\' requested by the login. Client with IP address \\'82.132.236.64\\' is not allowed to access the server. To enable access, use the Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect. (40615) (SQLDriverConnect)\")', call_id='call_WJlHhiupbeHR452PktbpgVpJ')], type='ToolCallResultMessage')])}\n",
111+
"INFO:autogen_core:Calling message handler for collect_output_messages with message type GroupChatMessage published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
112+
"INFO:autogen_agentchat.events:source='sql_query_generation_agent' models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191) content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\" type='TextMessage'\n",
113+
"INFO:autogen_core:Calling message handler for sql_schema_selection_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
114+
"INFO:autogen_core.events:{\"prompt_tokens\": 62569, \"completion_tokens\": 191, \"type\": \"LLMCall\"}\n",
115+
"INFO:autogen_core:Publishing message of type GroupChatMessage to all subscribers: {'message': TextMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191), content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\", type='TextMessage')}\n",
116+
"INFO:autogen_core:Publishing message of type GroupChatAgentResponse to all subscribers: {'agent_response': Response(chat_message=TextMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191), content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\", type='TextMessage'), inner_messages=[ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=61958, completion_tokens=109), content=[FunctionCall(id='call_qK7sS44z4Q8sv1mkIDUKK3m4', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_execution_with_limit')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='Error: (\\'42000\\', \"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open server \\'text2sql-adventure-works\\' requested by the login. Client with IP address \\'82.132.236.64\\' is not allowed to access the server. To enable access, use the Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect. (40615) (SQLDriverConnect)\")', call_id='call_qK7sS44z4Q8sv1mkIDUKK3m4')], type='ToolCallResultMessage'), ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62203, completion_tokens=107), content=[FunctionCall(id='call_devGqBMptvn1ciEIOC85IDkx', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_validation')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='True', call_id='call_devGqBMptvn1ciEIOC85IDkx')], type='ToolCallResultMessage'), ToolCallMessage(source='sql_query_generation_agent', models_usage=RequestUsage(prompt_tokens=62324, completion_tokens=109), content=[FunctionCall(id='call_WJlHhiupbeHR452PktbpgVpJ', arguments='{\"sql_query\":\"SELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\\\nFROM SalesLT.SalesOrderHeader so\\\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\\\nWHERE so.OrderDate >= \\'2008-06-01\\' AND so.OrderDate < \\'2008-07-01\\'\\\\nGROUP BY a.CountryRegion\\\\nORDER BY TotalSales DESC\\\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\"}', name='query_execution_with_limit')], type='ToolCallMessage'), ToolCallResultMessage(source='sql_query_generation_agent', models_usage=None, content=[FunctionExecutionResult(content='Error: (\\'42000\\', \"[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot open server \\'text2sql-adventure-works\\' requested by the login. Client with IP address \\'82.132.236.64\\' is not allowed to access the server. To enable access, use the Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect. (40615) (SQLDriverConnect)\")', call_id='call_WJlHhiupbeHR452PktbpgVpJ')], type='ToolCallResultMessage')])}\n",
117+
"INFO:autogen_core:Calling message handler for collect_output_messages with message type GroupChatMessage published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
118+
"INFO:autogen_agentchat.events:source='sql_query_generation_agent' models_usage=RequestUsage(prompt_tokens=62569, completion_tokens=191) content=\"I am currently unable to access the database to execute the SQL query due to a firewall restriction. However, I can provide you with the SQL query that you can run in your own environment to find out which country had the highest sales in June 2008.\\n\\nHere is the SQL query:\\n\\n```sql\\nSELECT a.CountryRegion, SUM(so.TotalDue) AS TotalSales\\nFROM SalesLT.SalesOrderHeader so\\nJOIN SalesLT.Address a ON so.ShipToAddressID = a.AddressID\\nWHERE so.OrderDate >= '2008-06-01' AND so.OrderDate < '2008-07-01'\\nGROUP BY a.CountryRegion\\nORDER BY TotalSales DESC\\nOFFSET 0 ROWS FETCH NEXT 25 ROWS ONLY;\\n```\\n\\nThis query will give you the total sales by country for June 2008, ordered by the highest sales. You can run this in your SQL environment to get the results.\" type='TextMessage'\n",
119+
"INFO:autogen_core:Calling message handler for sql_schema_selection_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
120+
"INFO:autogen_core:Calling message handler for sql_query_correction_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
121+
"INFO:autogen_core:Calling message handler for answer_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
122+
"INFO:autogen_core:Calling message handler for question_decomposition_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
123+
"INFO:autogen_core:Calling message handler for sql_disambiguation_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
124+
"INFO:autogen_core:Calling message handler for sql_query_cache_agent with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
125+
"INFO:autogen_core:Calling message handler for group_chat_manager with message type GroupChatAgentResponse published by sql_query_generation_agent/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
126+
"INFO:autogen_core:Publishing message of type GroupChatTermination to all subscribers: {'message': StopMessage(source='MaxMessageTermination', models_usage=None, content='Maximum number of messages 20 reached, current message count: 24', type='StopMessage')}\n",
127+
"INFO:autogen_core:Calling message handler for collect_output_messages with message type GroupChatTermination published by group_chat_manager/5fafbcbf-719b-4ce1-9896-33d3ad567f2d\n",
128+
"INFO:autogen_agentchat.events:source='MaxMessageTermination' models_usage=None content='Maximum number of messages 20 reached, current message count: 24' type='StopMessage'\n"
129+
]
130+
}
131+
],
103132
"source": [
104133
"result = agentic_text_2_sql.run_stream(task=\"What country did we sell the most to in June 2008?\")\n",
105134
"await Console(result)"

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/ai_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def get_column_values(
148148
"AIService__AzureSearchOptions__Text2SqlColumnValueStore__Index"
149149
],
150150
semantic_config=None,
151-
top=10,
151+
top=15,
152152
include_scores=False,
153153
minimum_score=5,
154154
)

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
13
import os
24
from text_2_sql_core.connectors.ai_search import AISearchConnector
35
from text_2_sql_core.connectors.open_ai import OpenAIConnector

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/open_ai.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License
13
from openai import AsyncAzureOpenAI
24
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
35
import os

0 commit comments

Comments
 (0)