- How we can use JSON mode and structured generation with open models like Llama 3 70b to extract a script for the Podcast given text from the PDF.
- How we can use TTS models to bring this script to life as a conversation.
Define Dialogue Schema with Pydantic
We need a way of telling the LLM what the structure of the podcast script between the guest and host will look like. We will do this usingpydantic
models.
Below we define the required classes:
- The overall conversation consists of lines said by either the host or the guest. The
DialogueItem
class specifies the structure of these lines. - The full script is a combination of multiple lines performed by the speakers, here we also include a
scratchpad
field to allow the LLM to ideate and brainstorm the overall flow of the script prior to actually generating the lines. TheDialogue
class specifies this.
Python
System Prompt for Script Generation
Next we need to define a detailed prompt template engineered to guide the LLM through the generation of the script. Feel free to modify and update the prompt below.Python
Download PDF and Extract Contents
Here we will load in an academic paper that proposes the use of many open source language models in a collaborative manner together to outperform proprietary models that are much larger! We will use the text in the PDF as content to generate the podcast with!
Shell
Python
Generate Podcast Script using JSON Mode
Below we call Llama3.1 70B with JSON mode to generate a script for our podcast. JSON mode makes it so that the LLM will only generate responses in the format specified by theScript
class. We will also be able to read it’s scratchpad and see how it structured the overall conversation.
Python
Script
class.
Now we can have a look at the script that is generated:
Generate Podcast Using TTS
Below we read through the script and parse choose the TTS voice depending on the speaker. We define a speaker and guest voice id.Python
Python
podcast.wav
file saved on disk that can be played!
If you’re ready to create your own PDF to podcast app like above sign up for Together AI today and make your first query in minutes!