How to call functions with chat models - Execute SQL Queries
Executing SQL queries Now let's implement the function that will actually excute queries against the database. def ask_database(conn, query): 'Function to query SQLite database with a provided SQL query.' try: results = str(conn.execute(query).fetchall()) except Exception as e: results = f'query failed with error: {e}' return results def execute_function_call(message): if message['function_call']['name'] == 'ask_database': query = json.loads(message['function_call']['arguments'])['query'] results = ask_database(conn, query) else: results = f'Error: function {message['function_call']['name']} does not exist' return results