Extract Dialogue Data with LLM Gateway and JSON
In this guide, we’ll show you how to use AssemblyAI’s LLM Gateway framework to process several audio files, and then format your results in JSON (JavaScript Object Notation) format.
JSON allows you to programmatically format, parse, and transfer responses from LLM Gateway, which is useful for implementing LLM Gateway with a wide range of other applications.
In this example, we will leverage the JSON formatting to create a .csv file from a directory of files that must be transcribed and submitted to LLM Gateway. However, you can use the same concepts in this guide to generate a JSON-formatted response, which you can then use to update a database table or interact with other APIs.
Quickstart
Get Started
Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for an AssemblyAI account and get your API key from your dashboard.
Step-by-Step Instructions
In this guide, we will ask the same questions to LLM Gateway about multiple files. Then, we will collate the answers in a .csv file.
Import the necessary libraries for making an HTTP request and set your API key, headers, and base URL.
Define a function to extract the JSON text from the response from LLM Gateway.
Define functions to upload and transcribe each file using AssemblyAI’s Async API.
Define a function to process each transcript text with LLM Gateway.
Define your LLM Gateway request prompt.
Retrieve and process each file in the interviews folder and create a .csv file with the results.
For context, this is the response from LLM Gateway with our prompt.
You can now run your Python script and you should see that a profiles.csv file is generated.