|
7 | 7 | import tempfile
|
8 | 8 | import webbrowser
|
9 | 9 | from pathlib import Path
|
| 10 | +from urllib.parse import urljoin |
10 | 11 |
|
11 | 12 | # New imports for template rendering and serving
|
12 | 13 | import jinja2
|
@@ -108,14 +109,7 @@ def webrtc(
|
108 | 109 | ),
|
109 | 110 | host: str = typer.Option("0.0.0.0", "--host", "-h"),
|
110 | 111 | port: int = typer.Option(8080, "--port", "-p"),
|
111 |
| - web_rtc_url: str = typer.Option( |
112 |
| - "https://eastus2.realtimeapi-preview.ai.azure.com/v1/realtimertc", "--webrtc-url", help="WebRTC endpoint URL" |
113 |
| - ), |
114 |
| - sessions_url: str = typer.Option( |
115 |
| - "https://YourAzureOpenAIResourceName.openai.azure.com/openai/realtimeapi/sessions?api-version=2025-04-01-preview", |
116 |
| - "--sessions-url", |
117 |
| - help="Sessions API URL", |
118 |
| - ), |
| 112 | + location: str = typer.Option("eastus2", "--location", help="location for Azure OpenAI"), |
119 | 113 | deployment: str = typer.Option("gpt-realtime", "--deployment", help="Deployment name"),
|
120 | 114 | voice: str = typer.Option("verse", "--voice", help="Voice name"),
|
121 | 115 | instructions: str = typer.Option(
|
@@ -147,8 +141,10 @@ def webrtc(
|
147 | 141 |
|
148 | 142 | # Use json.dumps to safely embed JS string literals in the template
|
149 | 143 | rendered = jinja2.Template(tpl_text).render(
|
150 |
| - WEBRTC_URL=json.dumps(web_rtc_url), |
151 |
| - SESSIONS_URL=json.dumps(sessions_url), |
| 144 | + WEBRTC_URL=json.dumps(f"https://{location}.realtimeapi-preview.ai.azure.com/v1/realtimertc"), |
| 145 | + SESSIONS_URL=json.dumps( |
| 146 | + urljoin(settings.azure_openai_endpoint, "/openai/realtimeapi/sessions?api-version=2025-04-01-preview") |
| 147 | + ), |
152 | 148 | API_KEY=json.dumps(api_key),
|
153 | 149 | DEPLOYMENT=json.dumps(deployment),
|
154 | 150 | VOICE=json.dumps(voice),
|
|
0 commit comments