From 1a95c94324cf50a6489729ffce16f975a87c1ac5 Mon Sep 17 00:00:00 2001 From: Ovidijus Parsiunas Date: Sun, 26 Jan 2025 20:00:33 +0900 Subject: [PATCH] OpenAI Realtime API - fixing unsupported style and double init bugs --- .../services/openAI/realtime/openAIRealtimeButton.ts | 10 +++++++--- .../src/services/openAI/realtime/openAIRealtimeIO.ts | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/component/src/services/openAI/realtime/openAIRealtimeButton.ts b/component/src/services/openAI/realtime/openAIRealtimeButton.ts index 9092f316..aefa7d79 100644 --- a/component/src/services/openAI/realtime/openAIRealtimeButton.ts +++ b/component/src/services/openAI/realtime/openAIRealtimeButton.ts @@ -45,19 +45,23 @@ export class OpenAIRealtimeButton extends InputButton { public changeToActive() { this.elementRef.replaceChildren(this._innerElements.active); - this.reapplyStateStyle('active', ['default']); + this.reapplyStateStyle('active', ['unavailable', 'default']); this.isActive = true; } public changeToDefault() { this.elementRef.replaceChildren(this._innerElements.default); if (this._customStyles?.active) ButtonCSS.unsetAllCSS(this.elementRef, this._customStyles?.active); - this.reapplyStateStyle('default', ['active']); + if (this._customStyles?.unavailable) ButtonCSS.unsetAllCSS(this.elementRef, this._customStyles?.unavailable); + this.reapplyStateStyle('default', ['active', 'unavailable']); this.isActive = false; } public changeToUnavailable() { this.elementRef.replaceChildren(this._innerElements.unavailable); - this.reapplyStateStyle('unavailable', ['active']); + if (this._customStyles?.active) ButtonCSS.unsetAllCSS(this.elementRef, this._customStyles?.active); + if (this._customStyles?.default) ButtonCSS.unsetAllCSS(this.elementRef, this._customStyles?.default); + this.reapplyStateStyle('unavailable', ['default', 'active']); + this.isActive = false; } } diff --git a/component/src/services/openAI/realtime/openAIRealtimeIO.ts b/component/src/services/openAI/realtime/openAIRealtimeIO.ts index 5123957f..b3b28ec3 100644 --- a/component/src/services/openAI/realtime/openAIRealtimeIO.ts +++ b/component/src/services/openAI/realtime/openAIRealtimeIO.ts @@ -51,7 +51,6 @@ export class OpenAIRealtimeIO extends DirectServiceIO { this._avatarEl = OpenAIRealtimeIO.createAvatar(this._avatarConfig); this._containerEl = this.createContainer(); this._deepChat = deepChat; - this.setup(); } private static getKey(deepChat: DeepChat) { @@ -304,7 +303,7 @@ export class OpenAIRealtimeIO extends DirectServiceIO { // Start the session using the Session Description Protocol (SDP) const offer = await this._pc.createOffer(); await this._pc.setLocalDescription(offer); - const sdpResponse = await fetch(`https://api.openai.com/v1/realtime?model=${this.rawBody.model}`, { + const sdpResponse = await fetch('https://api.openai.com/v1/realtime', { method: 'POST', body: offer.sdp, headers: {