From 4f2ca2a38bf65de50fef76bbd52de5f739d8d12e Mon Sep 17 00:00:00 2001 From: Arthur Blake <247797+arthurblake@users.noreply.github.com> Date: Tue, 28 Jan 2025 10:27:09 -0500 Subject: [PATCH] include name, arguments, result & error (as applicable) in function_call_XXX events so they are much more useful --- plugins/openai/src/realtime/realtime_model.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/openai/src/realtime/realtime_model.ts b/plugins/openai/src/realtime/realtime_model.ts index 9e370153..a1cd611a 100644 --- a/plugins/openai/src/realtime/realtime_model.ts +++ b/plugins/openai/src/realtime/realtime_model.ts @@ -1101,12 +1101,14 @@ export class RealtimeSession extends multimodal.RealtimeSession { return; } + const parsedArgs = JSON.parse(item.arguments); + this.emit('function_call_started', { + name: item.name, callId: item.call_id, + arguments: parsedArgs, }); - const parsedArgs = JSON.parse(item.arguments); - this.#logger.debug( `[Function Call ${item.call_id}] Executing ${item.name} with arguments ${parsedArgs}`, ); @@ -1115,7 +1117,10 @@ export class RealtimeSession extends multimodal.RealtimeSession { (content) => { this.#logger.debug(`[Function Call ${item.call_id}] ${item.name} returned ${content}`); this.emit('function_call_completed', { + name: item.name, callId: item.call_id, + arguments: parsedArgs, + result: content, }); this.conversation.item.create( llm.ChatMessage.createToolFromFunctionResult({ @@ -1131,7 +1136,10 @@ export class RealtimeSession extends multimodal.RealtimeSession { this.#logger.error(`[Function Call ${item.call_id}] ${item.name} failed with ${error}`); // TODO: send it back up as failed? this.emit('function_call_failed', { + name: item.name, callId: item.call_id, + arguments: parsedArgs, + error: error, }); }, );