Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Use RealtimeAPI not RealtimeClient for relay server #475

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions relay-server/lib/relay.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebSocketServer } from 'ws';
import { RealtimeClient } from '@openai/realtime-api-beta';
import { RealtimeAPI } from '@openai/realtime-api-beta';

export class RealtimeRelay {
constructor(apiKey) {
Expand Down Expand Up @@ -32,14 +32,14 @@ export class RealtimeRelay {

// Instantiate new client
this.log(`Connecting with key "${this.apiKey.slice(0, 3)}..."`);
const client = new RealtimeClient({ apiKey: this.apiKey });
const client = new RealtimeAPI({ apiKey: this.apiKey });

// Relay: OpenAI Realtime API Event -> Browser Event
client.realtime.on('server.*', (event) => {
client.on('server.*', (event) => {
this.log(`Relaying "${event.type}" to Client`);
ws.send(JSON.stringify(event));
});
client.realtime.on('close', () => ws.close());
client.on('close', () => ws.close());

// Relay: Browser Event -> OpenAI Realtime API Event
// We need to queue data waiting for the OpenAI connection
Expand All @@ -48,7 +48,7 @@ export class RealtimeRelay {
try {
const event = JSON.parse(data);
this.log(`Relaying "${event.type}" to OpenAI`);
client.realtime.send(event.type, event);
client.send(event.type, event);
} catch (e) {
console.error(e.message);
this.log(`Error parsing event from client: ${data}`);
Expand Down