Skip to content

Commit 2b2f050

Browse files
committed
gen: #file:realtime_webrtc.html の instructions で指定しているプロンプトを #file:realtime_operator.py CLI から動的に設定できるようにして
1 parent 9101996 commit 2b2f050

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

scripts/realtime_operator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,18 @@ def webrtc(
118118
),
119119
deployment: str = typer.Option("gpt-realtime", "--deployment", help="Deployment name"),
120120
voice: str = typer.Option("verse", "--voice", help="Voice name"),
121+
instructions: str = typer.Option(
122+
"You are a helpful AI assistant responding in natural, engaging language.",
123+
"--instructions",
124+
"-i",
125+
help="Initial assistant instructions for the realtime session",
126+
),
121127
):
122128
"""
123129
Render the realtime_webrtc HTML template with provided parameters and serve it as a static site.
124130
125131
The template is a Jinja2 template and will receive the following variables:
126-
- WEBRTC_URL, SESSIONS_URL, API_KEY, DEPLOYMENT, VOICE
132+
- WEBRTC_URL, SESSIONS_URL, API_KEY, DEPLOYMENT, VOICE, INSTRUCTIONS
127133
"""
128134
settings = Settings()
129135
api_key = settings.azure_openai_api_key
@@ -146,6 +152,7 @@ def webrtc(
146152
API_KEY=json.dumps(api_key),
147153
DEPLOYMENT=json.dumps(deployment),
148154
VOICE=json.dumps(voice),
155+
INSTRUCTIONS=json.dumps(instructions),
149156
)
150157

151158
tempdir = tempfile.TemporaryDirectory()

scripts/realtime_webrtc.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ <h1>Azure OpenAI Realtime Session</h1>
3434
// The deployment name might not be the same as the model name.
3535
const DEPLOYMENT = {{ DEPLOYMENT }};
3636
const VOICE = {{ VOICE }};
37+
// Injected initial assistant instructions (JSON-encoded string)
38+
const INSTRUCTIONS = {{ INSTRUCTIONS }};
3739

3840
async function StartSession() {
3941
try {
@@ -151,8 +153,8 @@ <h1>Azure OpenAI Realtime Session</h1>
151153
const event = {
152154
type: "session.update",
153155
session: {
154-
instructions:
155-
"You are a helpful AI assistant responding in natural, engaging language.",
156+
// Use the injected INSTRUCTIONS value so the CLI can control the prompt
157+
instructions: INSTRUCTIONS,
156158
},
157159
};
158160
dataChannel.send(JSON.stringify(event));

0 commit comments

Comments
 (0)