Skip to content

Commit e51b39d

Browse files
authored
Merge pull request #1 from mandryllo/patches
Patches
2 parents a5cb948 + de2f722 commit e51b39d

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

dist/lib/api.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
export class RealtimeAPI extends RealtimeEventHandler {
22
/**
33
* Create a new RealtimeAPI instance
4-
* @param {{url?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
4+
* @param {{url?: string, model?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
55
* @returns {RealtimeAPI}
66
*/
7-
constructor({ url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug }?: {
7+
constructor({ url, apiKey, model, dangerouslyAllowAPIKeyInBrowser, debug }?: {
88
url?: string;
9+
model?: string;
910
apiKey?: string;
1011
dangerouslyAllowAPIKeyInBrowser?: boolean;
1112
debug?: boolean;
1213
});
1314
defaultUrl: string;
15+
defaultModel: string;
1416
url: string;
1517
apiKey: string;
18+
model: string;
1619
debug: boolean;
1720
ws: any;
1821
/**

dist/lib/api.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/client.d.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
/**
66
* @typedef {Object} AudioTranscriptionType
77
* @property {"whisper-1"} model
8+
* @property {string} [language]
9+
* @property {string} [prompt]
810
*/
911
/**
1012
* @typedef {Object} TurnDetectionServerVadType
1113
* @property {"server_vad"} type
1214
* @property {number} [threshold]
1315
* @property {number} [prefix_padding_ms]
1416
* @property {number} [silence_duration_ms]
17+
* @property {boolean} [create_response]
1518
*/
1619
/**
1720
* Tool definitions
@@ -160,10 +163,11 @@
160163
export class RealtimeClient extends RealtimeEventHandler {
161164
/**
162165
* Create a new RealtimeClient instance
163-
* @param {{url?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
166+
* @param {{url?: string, model?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
164167
*/
165-
constructor({ url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug }?: {
168+
constructor({ url, apiKey, model, dangerouslyAllowAPIKeyInBrowser, debug }?: {
166169
url?: string;
170+
model?: string;
167171
apiKey?: string;
168172
dangerouslyAllowAPIKeyInBrowser?: boolean;
169173
debug?: boolean;
@@ -223,7 +227,7 @@ export class RealtimeClient extends RealtimeEventHandler {
223227
* Updates session config and conversation config
224228
* @returns {Promise<true>}
225229
*/
226-
connect(): Promise<true>;
230+
connect({ model }?: {}): Promise<true>;
227231
/**
228232
* Waits for a session.created event to be executed before proceeding
229233
* @returns {Promise<true>}
@@ -314,12 +318,15 @@ export class RealtimeClient extends RealtimeEventHandler {
314318
export type AudioFormatType = "pcm16" | "g711_ulaw" | "g711_alaw";
315319
export type AudioTranscriptionType = {
316320
model: "whisper-1";
321+
language?: string;
322+
prompt?: string;
317323
};
318324
export type TurnDetectionServerVadType = {
319325
type: "server_vad";
320326
threshold?: number;
321327
prefix_padding_ms?: number;
322328
silence_duration_ms?: number;
329+
create_response?: boolean;
323330
};
324331
/**
325332
* Tool definitions
@@ -336,8 +343,7 @@ export type SessionResourceType = {
336343
model?: string;
337344
modalities?: string[];
338345
instructions?: string;
339-
voice?: "alloy"|"ash"|"ballad"|"coral"|"echo"|"sage"|"shimmer"|"verse";
340-
346+
voice?: "alloy" | "ash" | "ballad" | "coral" | "echo" | "sage" | "shimmer" | "verse";
341347
input_audio_format?: AudioFormatType;
342348
output_audio_format?: AudioFormatType;
343349
input_audio_transcription?: AudioTranscriptionType | null;
@@ -457,4 +463,4 @@ export type ResponseResourceType = {
457463
import { RealtimeEventHandler } from './event_handler.js';
458464
import { RealtimeAPI } from './api.js';
459465
import { RealtimeConversation } from './conversation.js';
460-
//# sourceMappingURL=client.d.ts.map
466+
//# sourceMappingURL=client.d.ts.map

dist/lib/client.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { RealtimeUtils } from './utils.js';
44
export class RealtimeAPI extends RealtimeEventHandler {
55
/**
66
* Create a new RealtimeAPI instance
7-
* @param {{url?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
7+
* @param {{url?: string, model?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
88
* @returns {RealtimeAPI}
99
*/
10-
constructor({ url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug } = {}) {
10+
constructor({ url, apiKey, model, dangerouslyAllowAPIKeyInBrowser, debug } = {}) {
1111
super();
1212
this.defaultUrl = 'wss://api.openai.com/v1/realtime';
13+
this.defaultModel = 'gpt-4o-realtime-preview-2024-10-01';
1314
this.url = url || this.defaultUrl;
1415
this.apiKey = apiKey || null;
16+
this.model = model || this.defaultModel;
1517
this.debug = !!debug;
1618
this.ws = null;
1719
if (globalThis.document && this.apiKey) {
@@ -56,7 +58,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
5658
* @param {{model?: string}} [settings]
5759
* @returns {Promise<true>}
5860
*/
59-
async connect({ model } = { model: 'gpt-4o-realtime-preview-2024-10-01' }) {
61+
async connect({ model = this.model } = {}) {
6062
if (!this.apiKey && this.url === this.defaultUrl) {
6163
console.warn(`No apiKey provided for connection to "${this.url}"`);
6264
}
@@ -73,7 +75,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
7375
);
7476
}
7577
const WebSocket = globalThis.WebSocket;
76-
const ws = new WebSocket(`${this.url}${model ? `?model=${model}` : ''}`, [
78+
const ws = new WebSocket(`${this.url}?model=${model}`, [
7779
'realtime',
7880
`openai-insecure-api-key.${this.apiKey}`,
7981
'openai-beta.realtime-v1',
@@ -113,7 +115,7 @@ export class RealtimeAPI extends RealtimeEventHandler {
113115
const wsModule = await import(/* webpackIgnore: true */ moduleName);
114116
const WebSocket = wsModule.default;
115117
const ws = new WebSocket(
116-
'wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01',
118+
`wss://api.openai.com/v1/realtime?model=${model}`,
117119
[],
118120
{
119121
finishRequest: (request) => {

lib/client.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { RealtimeUtils } from './utils.js';
1111
/**
1212
* @typedef {Object} AudioTranscriptionType
1313
* @property {"whisper-1"} model
14+
* @property {string} [language]
15+
* @property {string} [prompt]
1416
*/
1517

1618
/**
@@ -19,6 +21,7 @@ import { RealtimeUtils } from './utils.js';
1921
* @property {number} [threshold]
2022
* @property {number} [prefix_padding_ms]
2123
* @property {number} [silence_duration_ms]
24+
* @property {boolean} [create_response]
2225
*/
2326

2427
/**
@@ -189,9 +192,9 @@ import { RealtimeUtils } from './utils.js';
189192
export class RealtimeClient extends RealtimeEventHandler {
190193
/**
191194
* Create a new RealtimeClient instance
192-
* @param {{url?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
195+
* @param {{url?: string, model?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings]
193196
*/
194-
constructor({ url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug } = {}) {
197+
constructor({ url, apiKey, model, dangerouslyAllowAPIKeyInBrowser, debug } = {}) {
195198
super();
196199
this.defaultSessionConfig = {
197200
modalities: ['text', 'audio'],
@@ -221,6 +224,7 @@ export class RealtimeClient extends RealtimeEventHandler {
221224
this.realtime = new RealtimeAPI({
222225
url,
223226
apiKey,
227+
model,
224228
dangerouslyAllowAPIKeyInBrowser,
225229
debug,
226230
});
@@ -389,11 +393,11 @@ export class RealtimeClient extends RealtimeEventHandler {
389393
* Updates session config and conversation config
390394
* @returns {Promise<true>}
391395
*/
392-
async connect() {
396+
async connect({ model } = {}) {
393397
if (this.isConnected()) {
394398
throw new Error(`Already connected, use .disconnect() first`);
395399
}
396-
await this.realtime.connect();
400+
await this.realtime.connect({ model });
397401
this.updateSession();
398402
return true;
399403
}

0 commit comments

Comments
 (0)