Skip to content

Commit 5a82929

Browse files
committed
Update SQL query logging method
Refactor the agent utils to log SQL queries directly from chunk content instead of extracting from actions. This simplifies the process and removes redundant code related to action handling.
1 parent fbd9228 commit 5a82929

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

mindsdb_sdk/utils/agents.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,10 @@ def stream_and_parse_sql_query(self, completion_stream: Generator[Dict[str, Any]
7979
for message in chunk['messages']:
8080
if message.get('role') == 'assistant':
8181
self.logger.info(f"Assistant message: {message.get('content', '')}")
82+
if chunk.get('type') == 'sql':
83+
sql_query = chunk['content']
84+
self.logger.info(f"Generated SQL: {sql_query}")
8285

83-
if 'actions' in chunk and chunk['actions']:
84-
self.logger.info(f"Chunk contains {len(chunk['actions'])} actions")
85-
for action in chunk['actions']:
86-
if 'tool' in action and 'sql_db_query' in action['tool']:
87-
match = re.search(r'tool_input="(.*?)"', action['tool'])
88-
if match and not sql_query_found:
89-
sql_query = match.group(1).replace("\\'", "'")
90-
sql_query_found = True
91-
self.logger.info(f"SQL query found: {sql_query}")
92-
break
9386
elif isinstance(chunk, str):
9487
output = chunk
9588
self.logger.info(f"String chunk received: {chunk}")

0 commit comments

Comments
 (0)