Skip to content

Commit bd4603f

Browse files
committed
feat: Update default model to gemini-3.1-flash-audio-eap and refactor tool calling and response handling to support multiple function calls.
1 parent 21949a5 commit bd4603f

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

gemini-live-ephemeral-tokens-websocket/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class MyTool extends FunctionCallDefinition {
9292

9393
## Configuration Options
9494

95-
- **Model**: `gemini-2.5-flash-native-audio-preview-12-2025` (default)
95+
- **Model**: `gemini-3.1-flash-audio-eap` (default)
9696
- **Voice**: Puck, Charon, Kore, Fenrir, Aoede
9797
- **Response**: Audio, text, or both
9898
- **Tools**: Custom functions or Google Search grounding

gemini-live-ephemeral-tokens-websocket/frontend/geminilive.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class FunctionCallDefinition {
128128
parameters
129129
)}`
130130
);
131-
this.functionToCall(parameters);
131+
return this.functionToCall(parameters);
132132
}
133133
}
134134

@@ -246,7 +246,7 @@ class GeminiLiveAPI {
246246

247247
callFunction(functionName, parameters) {
248248
const functionToCall = this.functionsMap[functionName];
249-
functionToCall.runFunction(parameters);
249+
return functionToCall.runFunction(parameters);
250250
}
251251

252252
connect() {
@@ -345,7 +345,7 @@ class GeminiLiveAPI {
345345
},
346346
},
347347
systemInstruction: { parts: [{ text: this.systemInstructions }] },
348-
tools: { functionDeclarations: tools },
348+
tools: [{ functionDeclarations: tools }],
349349
// proactivity: this.proactivity,
350350

351351
// realtimeInputConfig: {
@@ -370,12 +370,11 @@ class GeminiLiveAPI {
370370
}
371371

372372
if (this.googleGrounding) {
373-
sessionSetupMessage.setup.tools.googleSearch = {};
374373
// Currently can't have both Google Search with custom tools.
375374
console.log(
376375
"Google Grounding enabled, removing custom function calls if any."
377376
);
378-
delete sessionSetupMessage.setup.tools.functionDeclarations;
377+
sessionSetupMessage.setup.tools = [{ googleSearch: {} }];
379378
}
380379

381380
// Add affective dialog if enabled
@@ -399,11 +398,10 @@ class GeminiLiveAPI {
399398
this.sendMessage(message);
400399
}
401400

402-
sendToolResponse(toolCallId, response) {
401+
sendToolResponse(functionResponses) {
403402
const message = {
404403
toolResponse: {
405-
id: toolCallId,
406-
response: response,
404+
functionResponses: functionResponses,
407405
},
408406
};
409407
console.log("🔧 Sending tool response:", message);

gemini-live-ephemeral-tokens-websocket/frontend/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ <h2>API Configuration</h2>
8585

8686
<div>
8787
<label for="model">Model ID:</label><br />
88-
<input type="text" id="model" value="gemini-2.5-flash-native-audio-preview-12-2025"
89-
placeholder="Enter model ID" />
88+
<input type="text" id="model" value="gemini-3.1-flash-audio-eap" placeholder="Enter model ID" />
9089
</div>
9190
</details>
9291

gemini-live-ephemeral-tokens-websocket/frontend/script.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,36 @@ function handleMessage(message) {
279279
case MultimodalLiveResponseType.TOOL_CALL:
280280
console.log("🛠️ Tool call received: ", message.data);
281281
const functionCalls = message.data.functionCalls;
282+
const functionResponses = [];
282283
for (let index = 0; index < functionCalls.length; index++) {
283284
const functionCall = functionCalls[index];
284285
const functionName = functionCall.name;
286+
const functionCallId = functionCall.id;
285287
const parameters = functionCall.args;
286288
console.log(
287289
`Calling function ${functionName} with parameters: ${JSON.stringify(
288290
parameters
289291
)}`
290292
);
291-
state.client.callFunction(functionName, parameters);
293+
let result;
294+
try {
295+
result = state.client.callFunction(functionName, parameters);
296+
functionResponses.push({
297+
id: functionCallId,
298+
name: functionName,
299+
response: { result: result ?? "ok" },
300+
});
301+
} catch (err) {
302+
console.error(`Error calling function ${functionName}:`, err);
303+
functionResponses.push({
304+
id: functionCallId,
305+
name: functionName,
306+
response: { error: err.message },
307+
});
308+
}
292309
}
310+
// Send all function responses back to the API
311+
state.client.sendToolResponse(functionResponses);
293312
break;
294313

295314
case MultimodalLiveResponseType.TURN_COMPLETE:

0 commit comments

Comments
 (0)