Spaces:
Running
Running
Sync voice tool prompting
Browse files
main.js
CHANGED
|
@@ -23,18 +23,7 @@ import { ChatView } from "./ui/chat.js";
|
|
| 23 |
import { Account } from "./ui/account.js";
|
| 24 |
|
| 25 |
const DEFAULT_VOICE = "Aiden";
|
| 26 |
-
const DEFAULT_INSTRUCTIONS =
|
| 27 |
-
"You are a friendly voice assistant. " +
|
| 28 |
-
"Keep replies short, warm, and spoken. Avoid long monologues.";
|
| 29 |
-
|
| 30 |
-
// Appended to the user's instructions whenever at least one tool is enabled.
|
| 31 |
-
// Stops the model from announcing capabilities ("Yes, I can search") and then
|
| 32 |
-
// idling for the next turn β it should act immediately in the same response.
|
| 33 |
-
const TOOL_USE_HINT =
|
| 34 |
-
" When the user's request calls for one of your tools, do not describe your " +
|
| 35 |
-
"capabilities or say you can do it and wait for another turn. Instead, say " +
|
| 36 |
-
'a brief acknowledgement like "Let me search for that..." and call the tool ' +
|
| 37 |
-
"right away in the same response.";
|
| 38 |
|
| 39 |
const STORAGE_KEYS = {
|
| 40 |
// Direct s2s server URL, used only when the deploy has no LOAD_BALANCER_URL
|
|
@@ -319,19 +308,10 @@ function activeToolDefs() {
|
|
| 319 |
return defs;
|
| 320 |
}
|
| 321 |
|
| 322 |
-
/** Instructions plus the hidden tool-use hint when any tool is active. */
|
| 323 |
-
function effectiveInstructions() {
|
| 324 |
-
const base = settings.instructions;
|
| 325 |
-
return activeToolDefs().length ? base + TOOL_USE_HINT : base;
|
| 326 |
-
}
|
| 327 |
-
|
| 328 |
/** Push the active tool set to a live session so toggles apply mid-call. */
|
| 329 |
function pushToolsToSession() {
|
| 330 |
if (!client || !LIVE_STATES.has(currentState)) return;
|
| 331 |
client.setTools(activeToolDefs());
|
| 332 |
-
// The hidden tool-use hint depends on whether any tool is active, so refresh
|
| 333 |
-
// instructions alongside the tool set.
|
| 334 |
-
client.updateSession({ instructions: effectiveInstructions() });
|
| 335 |
}
|
| 336 |
|
| 337 |
// ββ Chat view βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -1010,7 +990,7 @@ settingsForm.addEventListener("submit", (event) => {
|
|
| 1010 |
// output can switch live when the browser supports AudioContext.setSinkId;
|
| 1011 |
// mic device changes need a Restart (new getUserMedia stream).
|
| 1012 |
if (client && LIVE_STATES.has(currentState)) {
|
| 1013 |
-
client.updateSession({ voice: settings.voice, instructions:
|
| 1014 |
void client.setAudioOutputDevice(settings.audioOutputId);
|
| 1015 |
}
|
| 1016 |
});
|
|
@@ -1313,7 +1293,7 @@ async function doStart(audioContext = null) {
|
|
| 1313 |
const c = new S2sWsRealtimeClient({
|
| 1314 |
...target,
|
| 1315 |
voice: settings.voice,
|
| 1316 |
-
instructions:
|
| 1317 |
startupGreeting,
|
| 1318 |
acquireMic: acquireMicStream,
|
| 1319 |
tools: activeToolDefs(),
|
|
|
|
| 23 |
import { Account } from "./ui/account.js";
|
| 24 |
|
| 25 |
const DEFAULT_VOICE = "Aiden";
|
| 26 |
+
const DEFAULT_INSTRUCTIONS = "You are a friendly voice assistant.";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
const STORAGE_KEYS = {
|
| 29 |
// Direct s2s server URL, used only when the deploy has no LOAD_BALANCER_URL
|
|
|
|
| 308 |
return defs;
|
| 309 |
}
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
/** Push the active tool set to a live session so toggles apply mid-call. */
|
| 312 |
function pushToolsToSession() {
|
| 313 |
if (!client || !LIVE_STATES.has(currentState)) return;
|
| 314 |
client.setTools(activeToolDefs());
|
|
|
|
|
|
|
|
|
|
| 315 |
}
|
| 316 |
|
| 317 |
// ββ Chat view βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 990 |
// output can switch live when the browser supports AudioContext.setSinkId;
|
| 991 |
// mic device changes need a Restart (new getUserMedia stream).
|
| 992 |
if (client && LIVE_STATES.has(currentState)) {
|
| 993 |
+
client.updateSession({ voice: settings.voice, instructions: settings.instructions });
|
| 994 |
void client.setAudioOutputDevice(settings.audioOutputId);
|
| 995 |
}
|
| 996 |
});
|
|
|
|
| 1293 |
const c = new S2sWsRealtimeClient({
|
| 1294 |
...target,
|
| 1295 |
voice: settings.voice,
|
| 1296 |
+
instructions: settings.instructions,
|
| 1297 |
startupGreeting,
|
| 1298 |
acquireMic: acquireMicStream,
|
| 1299 |
tools: activeToolDefs(),
|