From ba78ba122f4a5e4f6624ed6df6a3de4fcaf60ec1 Mon Sep 17 00:00:00 2001 From: Joan Cabezas Date: Mon, 28 Oct 2024 13:15:48 -0700 Subject: [PATCH 1/2] sendUserMessageContent createResponse optional --- lib/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index be37288..0132ba0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -546,7 +546,7 @@ export class RealtimeClient extends RealtimeEventHandler { * @param {Array} content * @returns {true} */ - sendUserMessageContent(content = []) { + sendUserMessageContent(content = [], createResponse = true) { if (content.length) { for (const c of content) { if (c.type === 'input_audio') { @@ -563,7 +563,7 @@ export class RealtimeClient extends RealtimeEventHandler { }, }); } - this.createResponse(); + createResponse && this.createResponse(); return true; } From 8ca65aea32db430189a2dcdd8b74ae0dcc6e4c48 Mon Sep 17 00:00:00 2001 From: Joan Cabezas Date: Mon, 28 Oct 2024 13:16:53 -0700 Subject: [PATCH 2/2] sendAssistantMessageContent function --- lib/client.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/client.js b/lib/client.js index 0132ba0..767407d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -567,6 +567,24 @@ export class RealtimeClient extends RealtimeEventHandler { return true; } + /** + * Sends assistant message content + * @param {Array} content + * @returns {true} + */ + sendAssistantMessageContent(content = []) { + if (content.length) { + this.realtime.send('conversation.item.create', { + item: { + type: 'message', + role: 'assistant', + content, + }, + }); + } + return true; + } + /** * Appends user audio to the existing audio buffer * @param {Int16Array|ArrayBuffer} arrayBuffer