From 685bf9d38635af9b1c5b76369b772f2b845d5a0e Mon Sep 17 00:00:00 2001
From: Patrick Loeber <98830383+ploeber@users.noreply.github.com>
Date: Fri, 15 Nov 2024 15:24:46 +0100
Subject: [PATCH] chore(python/sdk): README improvements (#7163)
GitOrigin-RevId: ae5dc9accc83cca798f214f07da891769bc341a4
---
README.md | 164 +++++++++++++++++++++++++++++++++---------------------
1 file changed, 102 insertions(+), 62 deletions(-)
diff --git a/README.md b/README.md
index 4e4cf44..da61e85 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ aai.settings.api_key = f"{ASSEMBLYAI_API_KEY}"
### **Core Examples**
- Transcribe a Local Audio File
+ Transcribe a local audio file
```python
import assemblyai as aai
@@ -116,7 +116,7 @@ transcript = transcriber.transcribe(upload_url)
- Export Subtitles of an Audio File
+ Export subtitles of an audio file
```python
import assemblyai as aai
@@ -134,7 +134,7 @@ print(transcript.export_subtitles_vtt())
- List all Sentences and Paragraphs
+ List all sentences and paragraphs
```python
import assemblyai as aai
@@ -154,7 +154,7 @@ for paragraph in paragraphs:
- Search for Words in a Transcript
+ Search for words in a transcript
```python
import assemblyai as aai
@@ -171,7 +171,7 @@ for match in matches:
- Add Custom Spellings on a Transcript
+ Add custom spellings on a transcript
```python
import assemblyai as aai
@@ -265,75 +265,65 @@ while page.page_details.before_id_of_prev_url is not None:
### **LeMUR Examples**
- Use LeMUR to Summarize Multiple Transcripts
+ Use LeMUR to summarize an audio file
```python
import assemblyai as aai
+audio_file = "https://assembly.ai/sports_injuries.mp3"
+
transcriber = aai.Transcriber()
-transcript_group = transcriber.transcribe_group(
- [
- "https://example.org/customer1.mp3",
- "https://example.org/customer2.mp3",
- ],
-)
+transcript = transcriber.transcribe(audio_file)
-result = transcript_group.lemur.summarize(
- context="Customers asking for cars",
- answer_format="TLDR"
+prompt = "Provide a brief summary of the transcript."
+
+result = transcript.lemur.task(
+ prompt, final_model=aai.LemurModel.claude3_5_sonnet
)
print(result.response)
```
-
-
-
- Use LeMUR to Ask Questions on a Single Transcript
+Or use the specialized Summarization endpoint that requires no prompt engineering and facilitates more deterministic and structured outputs:
```python
import assemblyai as aai
-transcriber = aai.Transcriber()
-transcript = transcriber.transcribe("https://example.org/customer.mp3")
-
-# ask some questions
-questions = [
- aai.LemurQuestion(question="What car was the customer interested in?"),
- aai.LemurQuestion(question="What price range is the customer looking for?"),
-]
+audio_url = "https://assembly.ai/meeting.mp4"
+transcript = aai.Transcriber().transcribe(audio_url)
-result = transcript.lemur.question(questions)
+result = transcript.lemur.summarize(
+ final_model=aai.LemurModel.claude3_5_sonnet,
+ context="A GitLab meeting to discuss logistics",
+ answer_format="TLDR"
+)
-for q in result.response:
- print(f"Question: {q.question}")
- print(f"Answer: {q.answer}")
+print(result.response)
```
- Use LeMUR to Ask for Action Items from a Single Transcript
+ Use LeMUR to ask questions about your audio data
```python
import assemblyai as aai
+audio_file = "https://assembly.ai/sports_injuries.mp3"
+
transcriber = aai.Transcriber()
-transcript = transcriber.transcribe("https://example.org/customer.mp3")
+transcript = transcriber.transcribe(audio_file)
+
+prompt = "What is a runner's knee?"
-result = transcript.lemur.action_items(
- context="Customers asking for help with resolving their problem",
- answer_format="Three bullet points",
+result = transcript.lemur.task(
+ prompt, final_model=aai.LemurModel.claude3_5_sonnet
)
print(result.response)
```
-
-
-
-
- Use LeMUR to Ask Anything with a Custom Prompt
+Or use the specialized Q&A endpoint that requires no prompt engineering and facilitates more deterministic and structured outputs:
```python
import assemblyai as aai
@@ -341,20 +331,25 @@ import assemblyai as aai
transcriber = aai.Transcriber()
transcript = transcriber.transcribe("https://example.org/customer.mp3")
-result = transcript.lemur.task(
- "You are a helpful coach. Provide an analysis of the transcript "
- "and offer areas to improve with exact quotes. Include no preamble. "
- "Start with an overall summary then get into the examples with feedback.",
-)
+# ask some questions
+questions = [
+ aai.LemurQuestion(question="What car was the customer interested in?"),
+ aai.LemurQuestion(question="What price range is the customer looking for?"),
+]
-print(result.response)
+result = transcript.lemur.question(
+ final_model=aai.LemurModel.claude3_5_sonnet,
+ questions=questions)
+
+for q in result.response:
+ print(f"Question: {q.question}")
+ print(f"Answer: {q.answer}")
```
-
- Use LeMUR to with Input Text
+ Use LeMUR with customized input text
```python
import assemblyai as aai
@@ -375,7 +370,32 @@ result = aai.Lemur().task(
"You are a helpful coach. Provide an analysis of the transcript "
"and offer areas to improve with exact quotes. Include no preamble. "
"Start with an overall summary then get into the examples with feedback.",
- input_text=text
+ input_text=text,
+ final_model=aai.LemurModel.claude3_5_sonnet
+)
+
+print(result.response)
+```
+
+
+
+
+ Apply LeMUR to multiple transcripts
+
+```python
+import assemblyai as aai
+
+transcriber = aai.Transcriber()
+transcript_group = transcriber.transcribe_group(
+ [
+ "https://example.org/customer1.mp3",
+ "https://example.org/customer2.mp3",
+ ],
+)
+
+result = transcript_group.lemur.task(
+ context="These are calls of customers asking for cars. Summarize all calls and create a TLDR.",
+ final_model=aai.LemurModel.claude3_5_sonnet
)
print(result.response)
@@ -417,7 +437,7 @@ print(deletion_result)
### **Audio Intelligence Examples**
- PII Redact a Transcript
+ PII Redact a transcript
```python
import assemblyai as aai
@@ -514,7 +534,7 @@ config=aai.TranscriptionConfig(
- Detect Sensitive Content in a Transcript
+ Detect sensitive content in a transcript
```python
import assemblyai as aai
@@ -562,7 +582,7 @@ config=aai.TranscriptionConfig(
- Analyze the Sentiment of Sentences in a Transcript
+ Analyze the sentiment of sentences in a transcript
```python
import assemblyai as aai
@@ -597,7 +617,7 @@ for sentiment_result in transcript.sentiment_analysis:
- Identify Entities in a Transcript
+ Identify entities in a transcript
```python
import assemblyai as aai
@@ -618,7 +638,7 @@ for entity in transcript.entities:
- Detect Topics in a Transcript (IAB Classification)
+ Detect topics in a transcript (IAB Classification)
```python
import assemblyai as aai
@@ -646,7 +666,7 @@ for label, relevance in transcript.iab_categories.summary.items():
- Identify Important Words and Phrases in a Transcript
+ Identify important words and phrases in a transcript
```python
import assemblyai as aai
@@ -677,7 +697,7 @@ for result in transcript.auto_highlights.results:
[Read more about our Real-Time service.](https://www.assemblyai.com/docs/Guides/real-time_streaming_transcription)
- Stream your Microphone in Real-Time
+ Stream your microphone in real-time
```python
import assemblyai as aai
@@ -733,7 +753,7 @@ transcriber.close()
- Transcribe a Local Audio File in Real-Time
+ Transcribe a local audio file in real-time
```python
import assemblyai as aai
@@ -835,12 +855,32 @@ transcriber = aai.RealtimeTranscriber(
---
-## Playgrounds
+### **Change the default settings**
+
+You'll find the `Settings` class with all default values in [types.py](./assemblyai/types.py).
+
+
+ Change the default timeout and polling interval
+
+```python
+import assemblyai as aai
+
+# The HTTP timeout in seconds for general requests, default is 30.0
+aai.settings.http_timeout = 60.0
+
+# The polling interval in seconds for long-running requests, default is 3.0
+aai.settings.polling_interval = 10.0
+```
+
+
+
+---
+
+## Playground
-Visit one of our Playgrounds:
+Visit our Playground to try our all of our Speech AI models and LeMUR for free:
-- [LeMUR Playground](https://www.assemblyai.com/playground/v2/source)
-- [Transcription Playground](https://www.assemblyai.com/playground)
+- [Playground](https://www.assemblyai.com/playground)
# Advanced