Skip to content

Commit 8762b2e

Browse files
xitzhangXiting Zhang
andauthored
Standardize model names to gpt-realtime and add telemetry enablement sample (#46552)
- Update all sample code and configuration to use 'gpt-realtime' instead of 'gpt-4o-realtime-preview' - Add sample_voicelive_with_telemetry_enablement.py demonstrating minimal code changes for OpenTelemetry integration - Updated files: .env.template, BASIC_VOICE_ASSISTANT.md, README.md, async samples, and telemetry samples - Reflects latest model naming and simplified telemetry integration pattern Co-authored-by: Xiting Zhang <xitzhang@microsoft.com>
1 parent 3c9162c commit 8762b2e

10 files changed

Lines changed: 126 additions & 15 deletions

sdk/voicelive/azure-ai-voicelive/.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AZURE_VOICELIVE_API_KEY=your-voicelive-api-key
66
AZURE_VOICELIVE_ENDPOINT=wss://api.voicelive.com/v1
77

88
# Optional configuration
9-
AZURE_VOICELIVE_MODEL=gpt-4o-realtime-preview
9+
AZURE_VOICELIVE_MODEL=gpt-realtime
1010
AZURE_VOICELIVE_VOICE=alloy
1111
AZURE_VOICELIVE_INSTRUCTIONS=You are a helpful assistant. Keep your responses concise.
1212

sdk/voicelive/azure-ai-voicelive/samples/BASIC_VOICE_ASSISTANT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Create a `.env` file with your credentials:
5151
```bash
5252
AZURE_VOICELIVE_API_KEY=your-api-key
5353
AZURE_VOICELIVE_ENDPOINT=your-endpoint
54-
AZURE_VOICELIVE_MODEL=gpt-4o-realtime-preview
54+
AZURE_VOICELIVE_MODEL=gpt-realtime
5555
AZURE_VOICELIVE_VOICE=en-US-AvaNeural
5656
AZURE_VOICELIVE_INSTRUCTIONS=You are a helpful AI assistant. Respond naturally and conversationally.
5757
```
@@ -66,7 +66,7 @@ Optional command-line arguments:
6666

6767
```bash
6868
python basic_voice_assistant_async.py \
69-
--model gpt-4o-realtime-preview \
69+
--model gpt-realtime \
7070
--voice en-US-AvaNeural \
7171
--instructions "You are a helpful assistant" \
7272
--verbose

sdk/voicelive/azure-ai-voicelive/samples/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This directory contains sample applications demonstrating various capabilities o
4444
```ini
4545
AZURE_VOICELIVE_API_KEY=your-voicelive-api-key
4646
AZURE_VOICELIVE_ENDPOINT=wss://api.voicelive.com/v1
47-
AZURE_VOICELIVE_MODEL=gpt-4o-realtime-preview
47+
AZURE_VOICELIVE_MODEL=gpt-realtime
4848
AZURE_VOICELIVE_VOICE=alloy
4949
AZURE_VOICELIVE_INSTRUCTIONS=You are a helpful assistant. Keep your responses concise.
5050
```
@@ -93,7 +93,7 @@ python basic_voice_assistant_async.py
9393
Most samples support additional command-line arguments. For example:
9494

9595
```bash
96-
python basic_voice_assistant_async.py --model gpt-4o-realtime-preview --voice alloy
96+
python basic_voice_assistant_async.py --model gpt-realtime --voice alloy
9797
9898
# With telemetry tracing
9999
python basic_voice_assistant_async.py --enable-tracing
@@ -117,6 +117,7 @@ These samples are in the `telemetry/` folder and demonstrate OpenTelemetry-based
117117

118118
| Sample | Description |
119119
|---|---|
120+
| `sample_voicelive_with_telemetry_enablement.py` | Minimal telemetry setup on top of existing VoiceLive code. Shows the smallest practical code delta to emit spans to console. |
120121
| `sample_voicelive_with_console_tracing.py` | Basic tracing with console output. All connection, send, and receive operations produce OpenTelemetry spans printed to stdout. |
121122
| `sample_voicelive_with_azure_monitor_tracing.py` | Traces exported to Azure Monitor / Application Insights. View results in the "Tracing" tab. |
122123
| `sample_voicelive_with_console_tracing_custom_attributes.py` | Adds custom `SpanProcessor` to inject application-specific attributes (session ID, etc.) into every span. |

sdk/voicelive/azure-ai-voicelive/samples/async_function_calling_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ async def main():
727727
client = AsyncFunctionCallingClient(
728728
endpoint=endpoint,
729729
credential=credential,
730-
model="gpt-4o-realtime-preview",
730+
model="gpt-realtime",
731731
voice="en-US-AvaNeural",
732732
instructions="You are a helpful AI assistant with access to functions. "
733733
"Use the functions when appropriate to provide accurate, real-time information. "

sdk/voicelive/azure-ai-voicelive/samples/async_mcp_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ async def main():
668668
client = AsyncMCPCallClient(
669669
endpoint=endpoint,
670670
credential=credential,
671-
model="gpt-4o-realtime-preview",
671+
model="gpt-realtime",
672672
voice="en-US-AvaNeural",
673673
instructions="You are a helpful AI assistant with access to some mcp server. ",
674674
)

sdk/voicelive/azure-ai-voicelive/samples/telemetry/sample_voicelive_with_azure_monitor_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Set these environment variables with your own values:
2121
1) AZURE_VOICELIVE_ENDPOINT - The Azure VoiceLive endpoint URL.
2222
2) AZURE_VOICELIVE_API_KEY - The Azure VoiceLive API key.
23-
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-4o-realtime-preview).
23+
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-realtime).
2424
4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to "true" to enable tracing.
2525
5) APPLICATIONINSIGHTS_CONNECTION_STRING - The connection string for your Application Insights resource.
2626
6) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to "true" to trace the content of
@@ -67,7 +67,7 @@
6767
async def main() -> None:
6868
endpoint = os.environ["AZURE_VOICELIVE_ENDPOINT"]
6969
api_key = os.environ["AZURE_VOICELIVE_API_KEY"]
70-
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-4o-realtime-preview")
70+
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-realtime")
7171

7272
credential = AzureKeyCredential(api_key)
7373

sdk/voicelive/azure-ai-voicelive/samples/telemetry/sample_voicelive_with_console_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Set these environment variables with your own values:
2727
1) AZURE_VOICELIVE_ENDPOINT - The Azure VoiceLive endpoint URL.
2828
2) AZURE_VOICELIVE_API_KEY - The Azure VoiceLive API key.
29-
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-4o-realtime-preview).
29+
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-realtime).
3030
4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to "true" to enable tracing.
3131
5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to "true" to trace the content of
3232
messages, which may contain personal data. False by default.
@@ -74,7 +74,7 @@
7474
async def main() -> None:
7575
endpoint = os.environ["AZURE_VOICELIVE_ENDPOINT"]
7676
api_key = os.environ["AZURE_VOICELIVE_API_KEY"]
77-
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-4o-realtime-preview")
77+
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-realtime")
7878

7979
credential = AzureKeyCredential(api_key)
8080

sdk/voicelive/azure-ai-voicelive/samples/telemetry/sample_voicelive_with_console_tracing_custom_attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Set these environment variables with your own values:
2222
1) AZURE_VOICELIVE_ENDPOINT - The Azure VoiceLive endpoint URL.
2323
2) AZURE_VOICELIVE_API_KEY - The Azure VoiceLive API key.
24-
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-4o-realtime-preview).
24+
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-realtime).
2525
4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to "true" to enable tracing.
2626
5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to "true" to trace the content of
2727
messages, which may contain personal data. False by default.
@@ -102,7 +102,7 @@ def on_end(self, span: ReadableSpan):
102102
async def main() -> None:
103103
endpoint = os.environ["AZURE_VOICELIVE_ENDPOINT"]
104104
api_key = os.environ["AZURE_VOICELIVE_API_KEY"]
105-
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-4o-realtime-preview")
105+
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-realtime")
106106

107107
credential = AzureKeyCredential(api_key)
108108

sdk/voicelive/azure-ai-voicelive/samples/telemetry/sample_voicelive_with_content_recording.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Set these environment variables with your own values:
2525
1) AZURE_VOICELIVE_ENDPOINT - The Azure VoiceLive endpoint URL.
2626
2) AZURE_VOICELIVE_API_KEY - The Azure VoiceLive API key.
27-
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-4o-realtime-preview).
27+
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-realtime).
2828
4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to "true" to enable tracing.
2929
"""
3030

@@ -76,7 +76,7 @@
7676
async def main() -> None:
7777
endpoint = os.environ["AZURE_VOICELIVE_ENDPOINT"]
7878
api_key = os.environ["AZURE_VOICELIVE_API_KEY"]
79-
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-4o-realtime-preview")
79+
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-realtime")
8080

8181
credential = AzureKeyCredential(api_key)
8282

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# pylint: disable=line-too-long,useless-suppression
2+
# ------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT License.
5+
# ------------------------------------
6+
7+
"""
8+
DESCRIPTION:
9+
This sample shows the minimum code changes needed to enable VoiceLive telemetry
10+
on top of existing VoiceLive client code.
11+
12+
USAGE:
13+
python sample_voicelive_with_telemetry_enablement.py
14+
15+
Before running the sample:
16+
17+
pip install azure-ai-voicelive azure-identity opentelemetry-sdk azure-core-tracing-opentelemetry
18+
19+
Set these environment variables with your own values:
20+
1) AZURE_VOICELIVE_ENDPOINT - The Azure VoiceLive endpoint URL.
21+
2) AZURE_VOICELIVE_API_KEY - The Azure VoiceLive API key.
22+
3) AZURE_VOICELIVE_MODEL - The model deployment name (e.g., gpt-realtime).
23+
24+
Optional telemetry variables:
25+
4) AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING - Set to "true" to enable tracing.
26+
5) OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - Optional. Set to "true" to include
27+
message content in telemetry events. False by default.
28+
"""
29+
30+
import asyncio
31+
import os
32+
33+
from azure.core.credentials import AzureKeyCredential
34+
from azure.core.settings import settings
35+
from azure.ai.voicelive.aio import connect
36+
from azure.ai.voicelive.models import (
37+
InputTextContentPart,
38+
Modality,
39+
OutputAudioFormat,
40+
RequestSession,
41+
ServerEventType,
42+
ServerVad,
43+
UserMessageItem,
44+
)
45+
from azure.ai.voicelive.telemetry import VoiceLiveInstrumentor
46+
47+
from opentelemetry import trace
48+
from opentelemetry.sdk.trace import TracerProvider
49+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, ConsoleSpanExporter
50+
51+
52+
def enable_telemetry_minimal():
53+
"""Enable telemetry with the smallest practical setup for existing code."""
54+
# Add these lines to your existing app to enable VoiceLive telemetry.
55+
# 1) Tell azure-core to use OpenTelemetry tracing.
56+
settings.tracing_implementation = "opentelemetry"
57+
58+
# 2) Configure a tracer provider and exporter (console in this sample).
59+
provider = TracerProvider()
60+
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
61+
trace.set_tracer_provider(provider)
62+
63+
# 3) Enable the VoiceLive instrumentation gate and instrument the SDK.
64+
os.environ.setdefault("AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING", "true")
65+
VoiceLiveInstrumentor().instrument()
66+
67+
return provider
68+
69+
70+
async def main() -> None:
71+
tracer_provider = enable_telemetry_minimal()
72+
73+
endpoint = os.environ["AZURE_VOICELIVE_ENDPOINT"]
74+
api_key = os.environ["AZURE_VOICELIVE_API_KEY"]
75+
model = os.environ.get("AZURE_VOICELIVE_MODEL", "gpt-realtime")
76+
77+
credential = AzureKeyCredential(api_key)
78+
79+
async with connect(
80+
endpoint=endpoint,
81+
credential=credential,
82+
model=model,
83+
) as connection:
84+
print(f"Connected to VoiceLive at {endpoint}")
85+
86+
session_config = RequestSession(
87+
modalities=[Modality.TEXT],
88+
instructions="You are a helpful assistant. Keep the answer short.",
89+
turn_detection=ServerVad(threshold=0.5, prefix_padding_ms=300, silence_duration_ms=500),
90+
output_audio_format=OutputAudioFormat.PCM16,
91+
)
92+
await connection.session.update(session=session_config)
93+
94+
await connection.conversation.item.create(
95+
item=UserMessageItem(content=[InputTextContentPart(text="Say hello in one sentence")])
96+
)
97+
await connection.response.create()
98+
99+
async for event in connection:
100+
event_type = getattr(event, "type", None)
101+
print(f"Received event: {event_type}")
102+
if event_type == ServerEventType.RESPONSE_DONE:
103+
break
104+
105+
tracer_provider.force_flush()
106+
tracer_provider.shutdown()
107+
108+
109+
if __name__ == "__main__":
110+
asyncio.run(main())

0 commit comments

Comments
 (0)