Skip to content

Commit c3ce707

Browse files
committed
fix(examples): update examples for v5.5 regenerated SDK types and methods
Update examples to use renamed methods (send_settings, send_media, send_text, send_flush, send_close) and new response shapes (stt/tts model split, nested usage results, wrapped request response).
1 parent 3a25e65 commit c3ce707

File tree

6 files changed

+85
-64
lines changed

6 files changed

+85
-64
lines changed

examples/09-voice-agent.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212

1313
from deepgram import DeepgramClient
1414
from deepgram.agent.v1.types import (
15-
AgentV1Agent,
16-
AgentV1AudioConfig,
17-
AgentV1AudioInput,
18-
AgentV1DeepgramSpeakProvider,
19-
AgentV1Listen,
20-
AgentV1ListenProvider,
21-
AgentV1OpenAiThinkProvider,
2215
AgentV1Settings,
23-
AgentV1SpeakProviderConfig,
24-
AgentV1Think,
16+
AgentV1SettingsAgent,
17+
AgentV1SettingsAgentListen,
18+
AgentV1SettingsAgentListenProvider_V1,
19+
AgentV1SettingsAudio,
20+
AgentV1SettingsAudioInput,
2521
)
2622
from deepgram.core.events import EventType
23+
from deepgram.types.speak_settings_v1 import SpeakSettingsV1
24+
from deepgram.types.speak_settings_v1provider import SpeakSettingsV1Provider_Deepgram
25+
from deepgram.types.think_settings_v1 import ThinkSettingsV1
26+
from deepgram.types.think_settings_v1provider import ThinkSettingsV1Provider_OpenAi
2727

2828
AgentV1SocketClientResponse = Union[str, bytes]
2929

@@ -33,30 +33,29 @@
3333
with client.agent.v1.connect() as agent:
3434
# Configure the agent settings
3535
settings = AgentV1Settings(
36-
audio=AgentV1AudioConfig(
37-
input=AgentV1AudioInput(
36+
audio=AgentV1SettingsAudio(
37+
input=AgentV1SettingsAudioInput(
3838
encoding="linear16",
39-
sample_rate=44100,
39+
sample_rate=24000,
4040
)
4141
),
42-
agent=AgentV1Agent(
43-
listen=AgentV1Listen(
44-
provider=AgentV1ListenProvider(
42+
agent=AgentV1SettingsAgent(
43+
listen=AgentV1SettingsAgentListen(
44+
provider=AgentV1SettingsAgentListenProvider_V1(
4545
type="deepgram",
4646
model="nova-3",
47-
smart_format=True,
4847
)
4948
),
50-
think=AgentV1Think(
51-
provider=AgentV1OpenAiThinkProvider(
49+
think=ThinkSettingsV1(
50+
provider=ThinkSettingsV1Provider_OpenAi(
5251
type="open_ai",
5352
model="gpt-4o-mini",
5453
temperature=0.7,
5554
),
5655
prompt="You are a helpful AI assistant.",
5756
),
58-
speak=AgentV1SpeakProviderConfig(
59-
provider=AgentV1DeepgramSpeakProvider(
57+
speak=SpeakSettingsV1(
58+
provider=SpeakSettingsV1Provider_Deepgram(
6059
type="deepgram",
6160
model="aura-2-asteria-en",
6261
)
@@ -65,7 +64,7 @@
6564
)
6665

6766
print("Sending agent settings...")
68-
agent.send_agent_v_1_settings(settings)
67+
agent.send_settings(settings)
6968

7069
def on_message(message: AgentV1SocketClientResponse) -> None:
7170
if isinstance(message, bytes):
@@ -84,15 +83,15 @@ def on_message(message: AgentV1SocketClientResponse) -> None:
8483
# In production, you would send audio from your microphone or audio source:
8584
# with open("audio.wav", "rb") as audio_file:
8685
# audio_data = audio_file.read()
87-
# agent.send_agent_v_1_media(audio_data)
86+
# agent.send_media(audio_data)
8887

8988
agent.start_listening()
9089

9190
# For async version:
9291
# from deepgram import AsyncDeepgramClient
9392
# async with client.agent.v1.connect() as agent:
9493
# # ... same configuration ...
95-
# await agent.send_agent_v_1_settings(settings)
94+
# await agent.send_settings(settings)
9695
# await agent.start_listening()
9796

9897
except Exception as e:

examples/11-text-to-speech-streaming.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from deepgram import DeepgramClient
1414
from deepgram.core.events import EventType
15-
from deepgram.speak.v1.types import SpeakV1Close, SpeakV1Flush, SpeakV1Text
15+
from deepgram.speak.v1.types import SpeakV1Text
1616

1717
SpeakV1SocketClientResponse = Union[str, bytes]
1818

@@ -40,15 +40,13 @@ def on_message(message: SpeakV1SocketClientResponse) -> None:
4040
# Note: start_listening() blocks, so send all messages first
4141
# For better control with bidirectional communication, use the async version
4242
text_message = SpeakV1Text(text="Hello, this is a text to speech example.")
43-
connection.send_speak_v_1_text(text_message)
43+
connection.send_text(text_message)
4444

4545
# Flush to ensure all text is processed
46-
flush_message = SpeakV1Flush()
47-
connection.send_speak_v_1_flush(flush_message)
46+
connection.send_flush()
4847

4948
# Close the connection when done
50-
close_message = SpeakV1Close()
51-
connection.send_speak_v_1_close(close_message)
49+
connection.send_close()
5250

5351
# Start listening - this blocks until the connection closes
5452
# All messages should be sent before calling this in sync mode
@@ -58,9 +56,9 @@ def on_message(message: SpeakV1SocketClientResponse) -> None:
5856
# from deepgram import AsyncDeepgramClient
5957
# async with client.speak.v1.connect(...) as connection:
6058
# listen_task = asyncio.create_task(connection.start_listening())
61-
# await connection.send_speak_v_1_text(SpeakV1Text(text="..."))
62-
# await connection.send_speak_v_1_flush(SpeakV1Flush())
63-
# await connection.send_speak_v_1_close(SpeakV1Close())
59+
# await connection.send_text(SpeakV1Text(text="..."))
60+
# await connection.send_flush()
61+
# await connection.send_close()
6462
# await listen_task
6563

6664
except Exception as e:

examples/12-text-intelligence.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
)
2525

2626
print("Analysis received:")
27-
print(f"Sentiment: {response.sentiment}")
28-
if response.summary:
29-
print(f"Summary: {response.summary}")
30-
if response.topics:
31-
print(f"Topics: {response.topics}")
32-
if response.intents:
33-
print(f"Intents: {response.intents}")
27+
if response.results.sentiments:
28+
print(f"Sentiment: {response.results.sentiments.average}")
29+
if response.results.summary:
30+
print(f"Summary: {response.results.summary.text}")
31+
if response.results.topics:
32+
print(f"Topics: {response.results.topics.segments}")
33+
if response.results.intents:
34+
print(f"Intents: {response.results.intents.segments}")
3435

3536
# For async version:
3637
# from deepgram import AsyncDeepgramClient

examples/17-management-usage.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@
2525
# Get usage summary
2626
print("\nGetting usage summary...")
2727
usage = client.manage.v1.projects.usage.get(project_id=project_id)
28-
print(f"Total requests: {usage.total_requests}")
29-
print(f"Total hours: {usage.total_hours}")
28+
print(f"Start: {usage.start}")
29+
print(f"End: {usage.end}")
30+
if usage.resolution:
31+
print(f"Resolution: {usage.resolution.amount} {usage.resolution.units}")
3032

3133
# Get usage breakdown
3234
print("\nGetting usage breakdown...")
3335
breakdown = client.manage.v1.projects.usage.breakdown.get(project_id=project_id)
34-
print(f"Breakdown entries: {len(breakdown.entries) if breakdown.entries else 0}")
36+
print(f"Breakdown results: {len(breakdown.results) if breakdown.results else 0}")
37+
if breakdown.results:
38+
for result in breakdown.results:
39+
print(f" Requests: {result.requests}, Hours: {result.hours}")
3540

3641
# Get usage fields
3742
print("\nGetting usage fields...")
3843
fields = client.manage.v1.projects.usage.fields.list(project_id=project_id)
39-
print(f"Available fields: {len(fields.fields) if fields.fields else 0}")
44+
print(f"Available models: {len(fields.models) if fields.models else 0}")
45+
print(f"Available features: {len(fields.features) if fields.features else 0}")
4046

4147
# List usage requests
4248
print("\nListing usage requests...")
@@ -48,8 +54,9 @@
4854
request_id = requests.requests[0].request_id
4955
print(f"\nGetting request details: {request_id}")
5056
request = client.manage.v1.projects.requests.get(project_id=project_id, request_id=request_id)
51-
print(f"Request method: {request.method}")
52-
print(f"Request endpoint: {request.endpoint}")
57+
if request.request:
58+
print(f"Request path: {request.request.path}")
59+
print(f"Request code: {request.request.code}")
5360

5461
# For async version:
5562
# from deepgram import AsyncDeepgramClient

examples/19-management-models.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,55 @@
1616
# List all public models
1717
print("Listing all public models...")
1818
models = client.manage.v1.models.list()
19-
print(f"Found {len(models.models) if models.models else 0} models")
2019

21-
for model in models.models or []:
22-
print(f" - {model.name} (ID: {model.model_id})")
23-
if hasattr(model, "language") and model.language:
24-
print(f" Language: {model.language}")
20+
stt_count = len(models.stt) if models.stt else 0
21+
tts_count = len(models.tts) if models.tts else 0
22+
print(f"Found {stt_count} STT models and {tts_count} TTS models")
23+
24+
print("\nSTT Models:")
25+
for model in models.stt or []:
26+
print(f" - {model.name} (UUID: {model.uuid_})")
27+
if model.languages:
28+
print(f" Languages: {', '.join(model.languages)}")
29+
30+
print("\nTTS Models:")
31+
for model in models.tts or []:
32+
print(f" - {model.name} (UUID: {model.uuid_})")
33+
if model.languages:
34+
print(f" Languages: {', '.join(model.languages)}")
2535

2636
# List including outdated models
2737
print("\nListing all models (including outdated)...")
2838
all_models = client.manage.v1.models.list(include_outdated=True)
29-
print(f"Found {len(all_models.models) if all_models.models else 0} total models")
39+
all_stt = len(all_models.stt) if all_models.stt else 0
40+
all_tts = len(all_models.tts) if all_models.tts else 0
41+
print(f"Found {all_stt} STT and {all_tts} TTS total models")
3042

3143
# Get a specific model
32-
if models.models:
33-
model_id = models.models[0].model_id
34-
print(f"\nGetting model details: {model_id}")
35-
model = client.manage.v1.models.get(model_id=model_id)
44+
if models.stt:
45+
model_uuid = models.stt[0].uuid_
46+
print(f"\nGetting model details: {model_uuid}")
47+
model = client.manage.v1.models.get(model_id=model_uuid)
3648
print(f"Model name: {model.name}")
37-
if hasattr(model, "language") and model.language:
38-
print(f"Language: {model.language}")
49+
if model.languages:
50+
print(f"Languages: {', '.join(model.languages)}")
3951

4052
# Get project-specific models
4153
projects = client.manage.v1.projects.list()
4254
if projects.projects:
4355
project_id = projects.projects[0].project_id
4456
print(f"\nGetting models for project: {project_id}")
4557
project_models = client.manage.v1.projects.models.list(project_id=project_id)
46-
print(f"Found {len(project_models.models) if project_models.models else 0} project models")
58+
p_stt = len(project_models.stt) if project_models.stt else 0
59+
p_tts = len(project_models.tts) if project_models.tts else 0
60+
print(f"Found {p_stt} STT and {p_tts} TTS project models")
4761

48-
if project_models.models:
49-
project_model_id = project_models.models[0].model_id
50-
print(f"\nGetting project model details: {project_model_id}")
51-
project_model = client.manage.v1.projects.models.get(project_id=project_id, model_id=project_model_id)
62+
if project_models.stt:
63+
project_model_uuid = project_models.stt[0].uuid_
64+
print(f"\nGetting project model details: {project_model_uuid}")
65+
project_model = client.manage.v1.projects.models.get(
66+
project_id=project_id, model_id=project_model_uuid
67+
)
5268
print(f"Model name: {project_model.name}")
5369

5470
# For async version:

examples/26-transcription-live-websocket-v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
client = DeepgramClient()
2525

2626
try:
27-
with client.listen.v2.connect(model="flux-general-en", encoding="linear16", sample_rate="16000") as connection:
27+
with client.listen.v2.connect(model="flux-general-en", encoding="linear16", sample_rate=16000) as connection:
2828

2929
def on_message(message: ListenV2SocketClientResponse) -> None:
3030
msg_type = getattr(message, "type", "Unknown")
@@ -42,7 +42,7 @@ def on_message(message: ListenV2SocketClientResponse) -> None:
4242
connection.on(EventType.ERROR, lambda error: print(f"Error: {error}"))
4343

4444
# Start listening - this blocks until the connection closes
45-
# In production, you would send audio data here using connection.send_listen_v_2_media()
45+
# In production, you would send audio data here using connection.send_media()
4646
connection.start_listening()
4747

4848
# For async version:

0 commit comments

Comments
 (0)