Skip to content

Commit 8593902

Browse files
committed
Update parameters
1 parent 5efa871 commit 8593902

File tree

7 files changed

+44
-26
lines changed

7 files changed

+44
-26
lines changed

text_2_sql/autogen/src/autogen_text_2_sql/autogen_text_2_sql.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
AnswerWithSources,
2323
UserInformationRequest,
2424
ProcessingUpdate,
25+
ChatHistoryItem,
2526
)
2627
from autogen_agentchat.base import Response, TaskResult
2728
from typing import AsyncGenerator
@@ -164,16 +165,16 @@ def extract_sources(self, messages: list) -> AnswerWithSources:
164165
async def process_question(
165166
self,
166167
question: str,
167-
chat_history: list[str] = None,
168-
parameters: dict = None,
168+
chat_history: list[ChatHistoryItem] = None,
169+
injected_parameters: dict = None,
169170
) -> AsyncGenerator[AnswerWithSources | UserInformationRequest, None]:
170171
"""Process the complete question through the unified system.
171172
172173
Args:
173174
----
174175
task (str): The user question to process.
175176
chat_history (list[str], optional): The chat history. Defaults to None.
176-
parameters (dict, optional): Parameters to pass to agents. Defaults to None.
177+
injected_parameters (dict, optional): Parameters to pass to agents. Defaults to None.
177178
178179
Returns:
179180
-------
@@ -185,13 +186,14 @@ async def process_question(
185186
agent_input = {
186187
"question": question,
187188
"chat_history": {},
188-
"parameters": parameters,
189+
"injected_parameters": injected_parameters,
189190
}
190191

191192
if chat_history is not None:
192193
# Update input
193194
for idx, chat in enumerate(chat_history):
194-
agent_input[f"chat_{idx}"] = chat
195+
# For now only consider the user query
196+
agent_input[f"chat_{idx}"] = chat.user_query
195197

196198
async for message in self.agentic_flow.run_stream(task=json.dumps(agent_input)):
197199
logging.debug("Message: %s", message)

text_2_sql/autogen/src/autogen_text_2_sql/custom_agents/sql_query_cache_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ async def on_messages_stream(
4343
last_response = messages[-1].content
4444
try:
4545
user_questions = json.loads(last_response)
46-
user_parameters = json.loads(parameter_input)["parameters"]
46+
injected_parameters = json.loads(parameter_input)["injected_parameters"]
4747
logging.info(f"Processing questions: {user_questions}")
48-
logging.info(f"Input Parameters: {user_parameters}")
48+
logging.info(f"Input Parameters: {injected_parameters}")
4949

5050
# Initialize results dictionary
5151
cached_results = {
@@ -58,7 +58,7 @@ async def on_messages_stream(
5858
# Fetch the queries from the cache based on the question
5959
logging.info(f"Fetching queries from cache for question: {question}")
6060
cached_query = await self.sql_connector.fetch_queries_from_cache(
61-
question, parameters=user_parameters
61+
question, injected_parameters=injected_parameters
6262
)
6363

6464
# If any question has pre-run results, set the flag

text_2_sql/autogen/src/autogen_text_2_sql/inner_autogen_text_2_sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ def agentic_flow(self):
189189
def process_question(
190190
self,
191191
question: str,
192-
parameters: dict = None,
192+
injected_parameters: dict = None,
193193
):
194194
"""Process the complete question through the unified system.
195195
196196
Args:
197197
----
198198
task (str): The user question to process.
199-
parameters (dict, optional): Parameters to pass to agents. Defaults to None.
199+
injected_parameters (dict, optional): Parameters to pass to agents. Defaults to None.
200200
201201
Returns:
202202
-------
@@ -207,7 +207,7 @@ def process_question(
207207
agent_input = {
208208
"question": question,
209209
"chat_history": {},
210-
"parameters": parameters,
210+
"injected_parameters": injected_parameters,
211211
}
212212

213213
return self.agentic_flow.run_stream(task=json.dumps(agent_input))

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/sql.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def query_validation(
153153
return True
154154

155155
async def fetch_queries_from_cache(
156-
self, question: str, parameters: dict = None
156+
self, question: str, injected_parameters: dict = None
157157
) -> str:
158158
"""Fetch the queries from the cache based on the question.
159159
@@ -166,21 +166,21 @@ async def fetch_queries_from_cache(
166166
str: The formatted string of the queries fetched from the cache. This is injected into the prompt.
167167
"""
168168

169-
if parameters is None:
170-
parameters = {}
169+
if injected_parameters is None:
170+
injected_parameters = {}
171171

172-
# Populate the parameters
173-
if "date" not in parameters:
174-
parameters["date"] = self.get_current_date()
172+
# Populate the injected_parameters
173+
if "date" not in injected_parameters:
174+
injected_parameters["date"] = self.get_current_date()
175175

176-
if "time" not in parameters:
177-
parameters["time"] = self.get_current_time()
176+
if "time" not in injected_parameters:
177+
injected_parameters["time"] = self.get_current_time()
178178

179-
if "datetime" not in parameters:
180-
parameters["datetime"] = self.get_current_datetime()
179+
if "datetime" not in injected_parameters:
180+
injected_parameters["datetime"] = self.get_current_datetime()
181181

182-
if "unix_timestamp" not in parameters:
183-
parameters["unix_timestamp"] = self.get_current_unix_timestamp()
182+
if "unix_timestamp" not in injected_parameters:
183+
injected_parameters["unix_timestamp"] = self.get_current_unix_timestamp()
184184

185185
cached_schemas = await self.ai_search_connector.run_ai_search_query(
186186
question,
@@ -204,7 +204,7 @@ async def fetch_queries_from_cache(
204204
sql_queries = schema["SqlQueryDecomposition"]
205205
for sql_query in sql_queries:
206206
sql_query["SqlQuery"] = Template(sql_query["SqlQuery"]).render(
207-
**parameters
207+
**injected_parameters
208208
)
209209

210210
logging.info("Cached schemas: %s", cached_schemas)
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
from text_2_sql_core.payloads.answer_with_sources import AnswerWithSources, Source
22
from text_2_sql_core.payloads.user_information_request import UserInformationRequest
33
from text_2_sql_core.payloads.processing_update import ProcessingUpdate
4+
from text_2_sql_core.payloads.chat_history import ChatHistoryItem
45

5-
__all__ = ["AnswerWithSources", "Source", "UserInformationRequest", "ProcessingUpdate"]
6+
__all__ = [
7+
"AnswerWithSources",
8+
"Source",
9+
"UserInformationRequest",
10+
"ProcessingUpdate",
11+
"ChatHistoryItem",
12+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pydantic import BaseModel
2+
from text_2_sql_core.payloads.answer_with_sources import AnswerWithSources
3+
4+
5+
class ChatHistoryItem(BaseModel):
6+
"""Chat history item with user message and agent response."""
7+
8+
user_query: str
9+
agent_response: AnswerWithSources

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/answer_agent.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ model: "4o-mini"
22
description: "An agent that generates a response to a user's question."
33
system_message: |
44
<role_and_objective>
5-
You are a helpful AI Assistant specializing in answering a user's question.
5+
You are a helpful AI Assistant specializing in answering a user's question about {{ use_case }}.
66
</role_and_objective>
77
88
Use the information obtained to generate a response to the user's question. The question has been broken down into a series of SQL queries and you need to generate a response based on the results of these queries.

0 commit comments

Comments
 (0)