From c80dc5e0ffd6bd0cda651c30522025584d9b89e0 Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Thu, 19 Dec 2024 16:51:37 -0800 Subject: [PATCH] Fix OpenAPI endpoint usage This commit will explicitly set a model ID when calling to OpenAI Realtime, as there was a breaking change where the endpoint will no longer have a default mode, thus causing our example to stop working. --- app/durableObjects/ChatRoom.server.ts | 3 +++ app/types/Env.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/app/durableObjects/ChatRoom.server.ts b/app/durableObjects/ChatRoom.server.ts index 9381134..5baca69 100644 --- a/app/durableObjects/ChatRoom.server.ts +++ b/app/durableObjects/ChatRoom.server.ts @@ -25,6 +25,7 @@ import { } from '~/utils/openai.server' const alarmInterval = 15_000 +const defaultOpenAIModelID = 'gpt-4o-realtime-preview-2024-10-01' /** * The ChatRoom Durable Object Class @@ -415,6 +416,8 @@ export class ChatRoom extends Server { params.set('instructions', instructions) } + params.set('model', this.env.OPENAI_MODEL_ID || defaultOpenAIModelID) + // The Calls's offer is sent to OpenAI const openaiAnswer = await requestOpenAIService( openAiTracksResponse.sessionDescription || diff --git a/app/types/Env.ts b/app/types/Env.ts index 84929a1..92210d0 100644 --- a/app/types/Env.ts +++ b/app/types/Env.ts @@ -17,4 +17,5 @@ export type Env = { DB?: D1Database OPENAI_API_TOKEN?: string OPENAI_MODEL_ENDPOINT?: string + OPENAI_MODEL_ID?: string }