@livekit/agents-plugin-openai 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/index.cjs +0 -19
- package/dist/realtime/index.cjs.map +1 -1
- package/dist/realtime/index.d.cts +0 -1
- package/dist/realtime/index.d.ts +0 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +0 -4
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/realtime_model.cjs +67 -23
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.cts +1 -1
- package/dist/realtime/realtime_model.d.ts +1 -1
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +67 -23
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/responses/llm.cjs +3 -1
- package/dist/responses/llm.cjs.map +1 -1
- package/dist/responses/llm.d.cts +2 -0
- package/dist/responses/llm.d.ts +2 -0
- package/dist/responses/llm.d.ts.map +1 -1
- package/dist/responses/llm.js +3 -1
- package/dist/responses/llm.js.map +1 -1
- package/dist/ws/llm.cjs +3 -0
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.cts +2 -0
- package/dist/ws/llm.d.ts +2 -0
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +3 -0
- package/dist/ws/llm.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/index.ts +0 -1
- package/src/realtime/realtime_model.ts +89 -30
- package/src/responses/llm.ts +6 -1
- package/src/ws/llm.ts +6 -0
- package/dist/realtime/realtime_model_beta.cjs +0 -1300
- package/dist/realtime/realtime_model_beta.cjs.map +0 -1
- package/dist/realtime/realtime_model_beta.d.cts +0 -164
- package/dist/realtime/realtime_model_beta.d.ts +0 -164
- package/dist/realtime/realtime_model_beta.d.ts.map +0 -1
- package/dist/realtime/realtime_model_beta.js +0 -1281
- package/dist/realtime/realtime_model_beta.js.map +0 -1
- package/src/realtime/realtime_model_beta.ts +0 -1663
|
@@ -234,7 +234,7 @@ export class RealtimeModel extends llm.RealtimeModel {
|
|
|
234
234
|
*
|
|
235
235
|
* @param azureDeployment - The name of your Azure OpenAI deployment.
|
|
236
236
|
* @param azureEndpoint - The endpoint URL for your Azure OpenAI resource. If undefined, will attempt to read from the environment variable AZURE_OPENAI_ENDPOINT.
|
|
237
|
-
* @param apiVersion - API version
|
|
237
|
+
* @param apiVersion - **Deprecated.** API version for legacy Azure OpenAI preview models. Will be removed on April 30, 2026. Omit for GA models.
|
|
238
238
|
* @param apiKey - Azure OpenAI API key. If undefined, will attempt to read from the environment variable AZURE_OPENAI_API_KEY.
|
|
239
239
|
* @param entraToken - Azure Entra authentication token. Required if not using API key authentication.
|
|
240
240
|
* @param baseURL - Base URL for the API endpoint. If undefined, constructed from the azure_endpoint.
|
|
@@ -287,9 +287,10 @@ export class RealtimeModel extends llm.RealtimeModel {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
apiVersion = apiVersion || process.env.OPENAI_API_VERSION;
|
|
290
|
-
if (
|
|
291
|
-
|
|
292
|
-
'
|
|
290
|
+
if (apiVersion) {
|
|
291
|
+
log().warn(
|
|
292
|
+
'The `apiVersion` parameter for Azure OpenAI Realtime is deprecated and will be removed on April 30, 2026. ' +
|
|
293
|
+
'Please use the newer Azure OpenAI Realtime API without specifying an API version.',
|
|
293
294
|
);
|
|
294
295
|
}
|
|
295
296
|
|
|
@@ -327,6 +328,24 @@ export class RealtimeModel extends llm.RealtimeModel {
|
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
|
|
331
|
+
/**
|
|
332
|
+
* In-place normalization of client event dicts for legacy Azure compatibility.
|
|
333
|
+
*
|
|
334
|
+
* The legacy Azure Realtime API uses "text" for assistant content parts,
|
|
335
|
+
* while the newer OpenAI API uses "output_text".
|
|
336
|
+
*/
|
|
337
|
+
function normalizeAzureClientEvent(event: Record<string, unknown>): void {
|
|
338
|
+
const item = event['item'] as Record<string, unknown> | undefined;
|
|
339
|
+
if (!item) return;
|
|
340
|
+
const content = item['content'] as Record<string, unknown>[] | undefined;
|
|
341
|
+
if (!content) return;
|
|
342
|
+
for (const contentPart of content) {
|
|
343
|
+
if (contentPart['type'] === 'output_text') {
|
|
344
|
+
contentPart['type'] = 'text';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
330
349
|
function processBaseURL({
|
|
331
350
|
baseURL,
|
|
332
351
|
model,
|
|
@@ -340,7 +359,9 @@ function processBaseURL({
|
|
|
340
359
|
azureDeployment?: string;
|
|
341
360
|
apiVersion?: string;
|
|
342
361
|
}): string {
|
|
343
|
-
|
|
362
|
+
// Azure GA (no apiVersion) uses /v1/realtime; legacy preview uses /realtime
|
|
363
|
+
const realtimePath = isAzure && !apiVersion ? 'v1/realtime' : 'realtime';
|
|
364
|
+
const url = new URL([baseURL, realtimePath].join('/'));
|
|
344
365
|
|
|
345
366
|
if (url.protocol === 'https:') {
|
|
346
367
|
url.protocol = 'wss:';
|
|
@@ -354,14 +375,19 @@ function processBaseURL({
|
|
|
354
375
|
}
|
|
355
376
|
|
|
356
377
|
const queryParams: Record<string, string> = {};
|
|
357
|
-
if (isAzure) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
378
|
+
if (isAzure && apiVersion) {
|
|
379
|
+
// Legacy Azure preview: /realtime?api-version=<v>&deployment=<d>
|
|
380
|
+
queryParams['api-version'] = apiVersion;
|
|
361
381
|
if (azureDeployment) {
|
|
362
382
|
queryParams['deployment'] = azureDeployment;
|
|
363
383
|
}
|
|
384
|
+
} else if (isAzure) {
|
|
385
|
+
// GA Azure: /v1/realtime?model=<deployment>
|
|
386
|
+
if (azureDeployment) {
|
|
387
|
+
queryParams['model'] = azureDeployment;
|
|
388
|
+
}
|
|
364
389
|
} else {
|
|
390
|
+
// Standard OpenAI: /realtime?model=<model>
|
|
365
391
|
queryParams['model'] = model;
|
|
366
392
|
}
|
|
367
393
|
|
|
@@ -434,37 +460,58 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
434
460
|
}
|
|
435
461
|
|
|
436
462
|
private createSessionUpdateEvent(): api_proto.SessionUpdateEvent {
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
463
|
+
const opts = this.oaiRealtimeModel._options;
|
|
464
|
+
const maxOutputTokens =
|
|
465
|
+
opts.maxResponseOutputTokens === Infinity ? 'inf' : opts.maxResponseOutputTokens;
|
|
466
|
+
|
|
467
|
+
if (opts.isAzure && opts.apiVersion) {
|
|
468
|
+
// Legacy Azure preview API: flat format
|
|
469
|
+
const modalities: Modality[] = opts.modalities.includes('audio')
|
|
470
|
+
? ['text', 'audio']
|
|
471
|
+
: ['text'];
|
|
472
|
+
return {
|
|
473
|
+
type: 'session.update',
|
|
474
|
+
session: {
|
|
475
|
+
model: opts.model,
|
|
476
|
+
voice: opts.voice,
|
|
477
|
+
input_audio_format: 'pcm16',
|
|
478
|
+
output_audio_format: 'pcm16',
|
|
479
|
+
modalities,
|
|
480
|
+
turn_detection: opts.turnDetection,
|
|
481
|
+
input_audio_transcription: opts.inputAudioTranscription,
|
|
482
|
+
tool_choice: toOaiToolChoice(opts.toolChoice),
|
|
483
|
+
max_response_output_tokens: maxOutputTokens,
|
|
484
|
+
speed: opts.speed,
|
|
485
|
+
instructions: this.instructions,
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
}
|
|
442
489
|
|
|
490
|
+
// GA format (OpenAI or Azure GA)
|
|
491
|
+
const audioFormat: api_proto.AudioFormat = { type: 'audio/pcm', rate: SAMPLE_RATE };
|
|
492
|
+
const modality: Modality = opts.modalities.includes('audio') ? 'audio' : 'text';
|
|
443
493
|
return {
|
|
444
494
|
type: 'session.update',
|
|
445
495
|
session: {
|
|
446
496
|
type: 'realtime',
|
|
447
|
-
model:
|
|
497
|
+
model: opts.model,
|
|
448
498
|
output_modalities: [modality],
|
|
449
499
|
audio: {
|
|
450
500
|
input: {
|
|
451
501
|
format: audioFormat,
|
|
452
|
-
noise_reduction:
|
|
453
|
-
transcription:
|
|
454
|
-
turn_detection:
|
|
502
|
+
noise_reduction: opts.inputAudioNoiseReduction,
|
|
503
|
+
transcription: opts.inputAudioTranscription,
|
|
504
|
+
turn_detection: opts.turnDetection,
|
|
455
505
|
},
|
|
456
506
|
output: {
|
|
457
507
|
format: audioFormat,
|
|
458
|
-
speed:
|
|
459
|
-
voice:
|
|
508
|
+
speed: opts.speed,
|
|
509
|
+
voice: opts.voice,
|
|
460
510
|
},
|
|
461
511
|
},
|
|
462
|
-
max_output_tokens:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
: this.oaiRealtimeModel._options.maxResponseOutputTokens,
|
|
466
|
-
tool_choice: toOaiToolChoice(this.oaiRealtimeModel._options.toolChoice),
|
|
467
|
-
tracing: this.oaiRealtimeModel._options.tracing,
|
|
512
|
+
max_output_tokens: maxOutputTokens,
|
|
513
|
+
tool_choice: toOaiToolChoice(opts.toolChoice),
|
|
514
|
+
tracing: opts.tracing,
|
|
468
515
|
instructions: this.instructions,
|
|
469
516
|
},
|
|
470
517
|
};
|
|
@@ -675,10 +722,12 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
675
722
|
}
|
|
676
723
|
}
|
|
677
724
|
|
|
725
|
+
const isLegacyAzure =
|
|
726
|
+
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
678
727
|
return {
|
|
679
728
|
type: 'session.update',
|
|
680
729
|
session: {
|
|
681
|
-
type: 'realtime',
|
|
730
|
+
...(!isLegacyAzure && { type: 'realtime' }),
|
|
682
731
|
model: this.oaiRealtimeModel._options.model,
|
|
683
732
|
tools: oaiTools,
|
|
684
733
|
},
|
|
@@ -687,11 +736,13 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
687
736
|
}
|
|
688
737
|
|
|
689
738
|
async updateInstructions(_instructions: string): Promise<void> {
|
|
739
|
+
const isLegacyAzure =
|
|
740
|
+
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
690
741
|
const eventId = shortuuid('instructions_update_');
|
|
691
742
|
this.sendEvent({
|
|
692
743
|
type: 'session.update',
|
|
693
744
|
session: {
|
|
694
|
-
type: 'realtime',
|
|
745
|
+
...(!isLegacyAzure && { type: 'realtime' }),
|
|
695
746
|
instructions: _instructions,
|
|
696
747
|
},
|
|
697
748
|
event_id: eventId,
|
|
@@ -707,8 +758,10 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
707
758
|
return;
|
|
708
759
|
}
|
|
709
760
|
|
|
761
|
+
const isLegacyAzure =
|
|
762
|
+
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
710
763
|
const options: api_proto.SessionUpdateEvent['session'] = {
|
|
711
|
-
type: 'realtime',
|
|
764
|
+
...(!isLegacyAzure && { type: 'realtime' }),
|
|
712
765
|
};
|
|
713
766
|
|
|
714
767
|
this.oaiRealtimeModel._options.toolChoice = toolChoice;
|
|
@@ -952,6 +1005,9 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
952
1005
|
try {
|
|
953
1006
|
for (const ev of events) {
|
|
954
1007
|
this.emit('openai_client_event_queued', ev);
|
|
1008
|
+
if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
|
|
1009
|
+
normalizeAzureClientEvent(ev as unknown as Record<string, unknown>);
|
|
1010
|
+
}
|
|
955
1011
|
wsConn!.send(JSON.stringify(ev));
|
|
956
1012
|
}
|
|
957
1013
|
} catch (error) {
|
|
@@ -1042,6 +1098,9 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1042
1098
|
}
|
|
1043
1099
|
|
|
1044
1100
|
this.emit('openai_client_event_queued', event);
|
|
1101
|
+
if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
|
|
1102
|
+
normalizeAzureClientEvent(event as unknown as Record<string, unknown>);
|
|
1103
|
+
}
|
|
1045
1104
|
wsConn.send(JSON.stringify(event));
|
|
1046
1105
|
} catch (error) {
|
|
1047
1106
|
break;
|
|
@@ -1823,7 +1882,7 @@ function openAIItemToLivekitItem(item: api_proto.ItemResource): llm.ChatItem {
|
|
|
1823
1882
|
// item.content can be a single object or an array; normalize to array
|
|
1824
1883
|
const contents = Array.isArray(item.content) ? item.content : [item.content];
|
|
1825
1884
|
for (const c of contents) {
|
|
1826
|
-
if (c.type === 'text' || c.type === 'input_text') {
|
|
1885
|
+
if (c.type === 'text' || c.type === 'input_text' || c.type === 'output_text') {
|
|
1827
1886
|
content.push(c.text);
|
|
1828
1887
|
} else if (c.type === 'input_image' && (c as api_proto.InputImageContent).image_url) {
|
|
1829
1888
|
content.push(
|
package/src/responses/llm.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface LLMOptions {
|
|
|
28
28
|
strictToolSchema?: boolean;
|
|
29
29
|
/** Specifies the processing tier (e.g. 'auto', 'default', 'priority', 'flex'). */
|
|
30
30
|
serviceTier?: string;
|
|
31
|
+
/** Upper bound for the number of tokens that can be generated for a response. */
|
|
32
|
+
maxOutputTokens?: number;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Whether to use the WebSocket API.
|
|
@@ -120,6 +122,10 @@ class ResponsesHttpLLM extends llm.LLM {
|
|
|
120
122
|
modelOptions.service_tier = this.#opts.serviceTier;
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
if (this.#opts.maxOutputTokens !== undefined) {
|
|
126
|
+
modelOptions.max_output_tokens = this.#opts.maxOutputTokens;
|
|
127
|
+
}
|
|
128
|
+
|
|
123
129
|
return new ResponsesHttpLLMStream(this, {
|
|
124
130
|
model: this.#opts.model,
|
|
125
131
|
client: this.#client,
|
|
@@ -394,7 +400,6 @@ export class LLM extends llm.LLM {
|
|
|
394
400
|
this.#llm.prewarm();
|
|
395
401
|
}
|
|
396
402
|
|
|
397
|
-
// Ref: python livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/responses/llm.py - 229-233 lines
|
|
398
403
|
override async aclose(): Promise<void> {
|
|
399
404
|
await this.#llm.aclose();
|
|
400
405
|
}
|
package/src/ws/llm.ts
CHANGED
|
@@ -143,6 +143,8 @@ export interface WSLLMOptions {
|
|
|
143
143
|
strictToolSchema?: boolean;
|
|
144
144
|
/** Specifies the processing tier (e.g. 'auto', 'default', 'priority', 'flex'). */
|
|
145
145
|
serviceTier?: string;
|
|
146
|
+
/** Upper bound for the number of tokens that can be generated for a response. */
|
|
147
|
+
maxOutputTokens?: number;
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
const defaultLLMOptions: WSLLMOptions = {
|
|
@@ -272,6 +274,10 @@ export class WSLLM extends llm.LLM {
|
|
|
272
274
|
modelOptions.service_tier = this.#opts.serviceTier;
|
|
273
275
|
}
|
|
274
276
|
|
|
277
|
+
if (this.#opts.maxOutputTokens !== undefined) {
|
|
278
|
+
modelOptions.max_output_tokens = this.#opts.maxOutputTokens;
|
|
279
|
+
}
|
|
280
|
+
|
|
275
281
|
let inputChatCtx = chatCtx;
|
|
276
282
|
let prevResponseId: string | undefined;
|
|
277
283
|
const canUseStoredResponse = modelOptions.store !== false;
|