Generate A Custom Summary Using LeMUR

This tutorial will demonstrate how to use AssemblyAI’s LeMUR (Leveraging Large Language Models to Understand Recognized Speech) framework to get a custom summary using the Task endpoint.

Quickstart

1import assemblyai as aai
2
3aai.settings.api_key = "API_KEY"
4audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
5
6transcript = aai.Transcriber().transcribe(audio_url)
7
8prompt = f"""
9- You are an expert at writing factual, useful summaries.
10- You focus on key details, leave out irrelevant information, and do not add in information that is not already present in the transcript.
11- Your summaries accurately represent the information in the transcript.
12- You are useful to the reader, are true and concise, and are written in perfect English.
13- Use multiple parts of the transcript to form your summary.
14- Make your summary follow the sequential order of events in the transcript.
15- Your summaries do not describe the context of the transcript - they only summarize the events in the text.
16- Your summaries do not describe what type of text they summarize.
17- You do not dumb down specific language nor make big generalizations.
18- Respond with just the summary and don't include a preamble or introduction.
19"""
20
21answer_format = "Bullet points"
22
23if answer_format:
24 prompt+=f"\nYour summary should use the following format: {answer_format}"
25
26result = transcript.lemur.task(
27 prompt,
28 final_model=aai.LemurModel.claude3_5_sonnet
29)
30
31response = result.response
32print(response)

Getting 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. You will need to upgrade your account by adding a credit card to have access to LeMUR.

Find more details on the current LeMUR pricing in the AssemblyAI pricing page.

Step-by-Step Instructions

In this guide, we will prompt LeMUR to generate a summary.

First, let’s install the AssemblyAI SDK.

$pip install -U assemblyai

Then we’ll import the SDK and set our AssemblyAI API key.

1import assemblyai as aai
2
3aai.settings.api_key = "API_KEY"

Next, we’ll use AssemblyAI to transcribe a file and save our transcript.

1audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
2
3transcript = aai.Transcriber().transcribe(audio_url)

Provide detailed instructions to prompt LeMUR to summarize the transcript.

1prompt = f"""
2- You are an expert at writing factual, useful summaries.
3- You focus on key details, leave out irrelevant information, and do not add in information that is not already present in the transcript.
4- Your summaries accurately represent the information in the transcript.
5- You are useful to the reader, are true and concise, and are written in perfect English.
6- Use multiple parts of the transcript to form your summary.
7- Make your summary follow the sequential order of events in the transcript.
8- Your summaries do not describe the context of the transcript - they only summarize the events in the text.
9- Your summaries do not describe what type of text they summarize.
10- You do not dumb down specific language nor make big generalizations.
11- Respond with just the summary and don't include a preamble or introduction.
12"""

You can also optionally specify a summary format and append it to the prompt.

1answer_format = "Bullet points"
2
3if answer_format:
4 prompt+=f"\nYour summary should use the following format: {answer_format}"

Prompt the LeMUR model using the Task Endpoint and return the response.

1result = transcript.lemur.task(
2 prompt,
3 final_model=aai.LemurModel.claude3_5_sonnet
4)
5
6response = result.response
7print(response)