From bd4e74aaa20d09a069f058eb6aaa76205871f28a Mon Sep 17 00:00:00 2001 From: Theo Gibbons Date: Mon, 21 Oct 2024 15:26:02 -0700 Subject: [PATCH] Fix: Prevent assistant from responding before function call completes (#14, #49) This checks that a tool exists before calling it. References: - https://github.com/openai/openai-realtime-api-beta/issues/14 - https://github.com/openai/openai-realtime-api-beta/issues/49 --- lib/client.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index be37288..44f288c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -355,8 +355,9 @@ export class RealtimeClient extends RealtimeEventHandler { if (item.status === 'completed') { this.dispatch('conversation.item.completed', { item }); } - if (item.formatted.tool) { - callTool(item.formatted.tool); + const tool = item.formatted.tool; + if (tool && this.tools[tool.name]?.handler) { + callTool(tool); } });