Код: Выделить всё
class QuerySQLTablesPlugin:
@kernel_function(
description="Get the schema of the table to create the query the user needs")
async def fetch_schema_async(self, table_name: str):
table_name = table_name.split(".")[-1]
return await sync_to_async(self.fetch_schema_sync)(table_name)
@kernel_function(
description="Takes in a query to be executed in the database")
async def execute_query(self, query_to_execute: str):
return await sync_to_async(self.fetch_query_sync)(query_to_execute)
def fetch_schema_sync(self, table_name):
with connections['default'].cursor() as cursor:
cursor.execute(
f"SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{table_name}'"
)
schema = cursor.fetchall()
print(f"Fetched schema: {schema}")
return schema
def fetch_query_sync(self, query_to_execute: str):
with connections['default'].cursor() as cursor:
cursor.execute(query_to_execute)
result = cursor.fetchall()
results = [dict(row) for row in result]
print(f"Query results: {results}")
return json.dumps(results)
Код: Выделить всё
QuerySQLTables-execute_query: Function Call arguments are not valid JSON.. Trying tool call again.Код: Выделить всё
{'name': 'QuerySQLTables-execute_query', 'arguments': '{\n "query_to_execute": "SELECT is_staff FROM dbo.user WHERE username = \'Bob\'"\n }'}}]}, {'role': 'tool', 'content': 'The tool call arguments are malformed. Arguments must be in JSON format. Please try again.', 'tool_call_id': 'call_1BcXUS4WUdozITfhWmY1BuGB'},Подробнее здесь: https://stackoverflow.com/questions/793 ... son-format
Мобильная версия