admin管理员组

文章数量:1125760

I'm using semantic kernel and azure open ai as my search. I have this plugin I created:

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)

The fetch_schema_async function gets called successfully, however, for the execute_query function, it gives me the following error:

QuerySQLTables-execute_query: Function Call arguments are not valid JSON.. Trying tool call again.

Even though, I'm able to see the query_to_execute, it looks like this: {'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'},

Why am I getting this error? The function is not executing at all.

本文标签: pythonSemantic Kernel Plugin Function Arguments must be in JSON formatStack Overflow