@livekit/agents 1.0.6 → 1.1.0
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 +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inference/api_protos.cjs +104 -0
- package/dist/inference/api_protos.cjs.map +1 -0
- package/dist/inference/api_protos.d.cts +222 -0
- package/dist/inference/api_protos.d.ts +222 -0
- package/dist/inference/api_protos.d.ts.map +1 -0
- package/dist/inference/api_protos.js +70 -0
- package/dist/inference/api_protos.js.map +1 -0
- package/dist/inference/index.cjs +56 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +9 -0
- package/dist/inference/index.d.ts +9 -0
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/index.js +16 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/inference/llm.cjs +315 -0
- package/dist/inference/llm.cjs.map +1 -0
- package/dist/inference/llm.d.cts +92 -0
- package/dist/inference/llm.d.ts +92 -0
- package/dist/inference/llm.d.ts.map +1 -0
- package/dist/inference/llm.js +286 -0
- package/dist/inference/llm.js.map +1 -0
- package/dist/inference/stt.cjs +305 -0
- package/dist/inference/stt.cjs.map +1 -0
- package/dist/inference/stt.d.cts +79 -0
- package/dist/inference/stt.d.ts +79 -0
- package/dist/inference/stt.d.ts.map +1 -0
- package/dist/inference/stt.js +284 -0
- package/dist/inference/stt.js.map +1 -0
- package/dist/inference/tts.cjs +317 -0
- package/dist/inference/tts.cjs.map +1 -0
- package/dist/inference/tts.d.cts +75 -0
- package/dist/inference/tts.d.ts +75 -0
- package/dist/inference/tts.d.ts.map +1 -0
- package/dist/inference/tts.js +299 -0
- package/dist/inference/tts.js.map +1 -0
- package/dist/inference/utils.cjs +76 -0
- package/dist/inference/utils.cjs.map +1 -0
- package/dist/inference/utils.d.cts +5 -0
- package/dist/inference/utils.d.ts +5 -0
- package/dist/inference/utils.d.ts.map +1 -0
- package/dist/inference/utils.js +51 -0
- package/dist/inference/utils.js.map +1 -0
- package/dist/tts/tts.cjs +1 -1
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.js +1 -1
- package/dist/tts/tts.js.map +1 -1
- package/dist/utils.cjs +11 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -0
- package/dist/utils.js.map +1 -1
- package/dist/voice/agent.cjs +16 -3
- package/dist/voice/agent.cjs.map +1 -1
- package/dist/voice/agent.d.cts +4 -3
- package/dist/voice/agent.d.ts +4 -3
- package/dist/voice/agent.d.ts.map +1 -1
- package/dist/voice/agent.js +20 -3
- package/dist/voice/agent.js.map +1 -1
- package/dist/voice/agent_session.cjs +16 -3
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +4 -3
- package/dist/voice/agent_session.d.ts +4 -3
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +20 -3
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/room_io/_input.cjs.map +1 -1
- package/dist/voice/room_io/_input.d.ts.map +1 -1
- package/dist/voice/room_io/_input.js +1 -0
- package/dist/voice/room_io/_input.js.map +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +2 -1
- package/src/inference/api_protos.ts +82 -0
- package/src/inference/index.ts +12 -0
- package/src/inference/llm.ts +485 -0
- package/src/inference/stt.ts +414 -0
- package/src/inference/tts.ts +421 -0
- package/src/inference/utils.ts +66 -0
- package/src/tts/tts.ts +1 -1
- package/src/utils.ts +11 -0
- package/src/voice/agent.ts +30 -6
- package/src/voice/agent_session.ts +29 -6
- package/src/voice/room_io/_input.ts +1 -1
- package/src/worker.ts +2 -7
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ttsSessionCreateEventSchema = z.object({
|
|
3
|
+
type: z.literal("session.create"),
|
|
4
|
+
sample_rate: z.string(),
|
|
5
|
+
encoding: z.string(),
|
|
6
|
+
model: z.string().optional(),
|
|
7
|
+
voice: z.string().optional(),
|
|
8
|
+
language: z.string().optional(),
|
|
9
|
+
extra: z.record(z.string(), z.unknown()),
|
|
10
|
+
transcript: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
const ttsInputTranscriptEventSchema = z.object({
|
|
13
|
+
type: z.literal("input_transcript"),
|
|
14
|
+
transcript: z.string()
|
|
15
|
+
});
|
|
16
|
+
const ttsSessionFlushEventSchema = z.object({
|
|
17
|
+
type: z.literal("session.flush")
|
|
18
|
+
});
|
|
19
|
+
const ttsSessionCloseEventSchema = z.object({
|
|
20
|
+
type: z.literal("session.close")
|
|
21
|
+
});
|
|
22
|
+
const ttsSessionCreatedEventSchema = z.object({
|
|
23
|
+
type: z.literal("session.created"),
|
|
24
|
+
session_id: z.string()
|
|
25
|
+
});
|
|
26
|
+
const ttsOutputAudioEventSchema = z.object({
|
|
27
|
+
type: z.literal("output_audio"),
|
|
28
|
+
audio: z.string(),
|
|
29
|
+
session_id: z.string()
|
|
30
|
+
});
|
|
31
|
+
const ttsDoneEventSchema = z.object({
|
|
32
|
+
type: z.literal("done"),
|
|
33
|
+
session_id: z.string()
|
|
34
|
+
});
|
|
35
|
+
const ttsSessionClosedEventSchema = z.object({
|
|
36
|
+
type: z.literal("session.closed"),
|
|
37
|
+
session_id: z.string()
|
|
38
|
+
});
|
|
39
|
+
const ttsErrorEventSchema = z.object({
|
|
40
|
+
type: z.literal("error"),
|
|
41
|
+
message: z.string(),
|
|
42
|
+
session_id: z.string()
|
|
43
|
+
});
|
|
44
|
+
const ttsClientEventSchema = z.discriminatedUnion("type", [
|
|
45
|
+
ttsSessionCreateEventSchema,
|
|
46
|
+
ttsInputTranscriptEventSchema,
|
|
47
|
+
ttsSessionFlushEventSchema,
|
|
48
|
+
ttsSessionCloseEventSchema
|
|
49
|
+
]);
|
|
50
|
+
const ttsServerEventSchema = z.discriminatedUnion("type", [
|
|
51
|
+
ttsSessionCreatedEventSchema,
|
|
52
|
+
ttsOutputAudioEventSchema,
|
|
53
|
+
ttsDoneEventSchema,
|
|
54
|
+
ttsSessionClosedEventSchema,
|
|
55
|
+
ttsErrorEventSchema
|
|
56
|
+
]);
|
|
57
|
+
export {
|
|
58
|
+
ttsClientEventSchema,
|
|
59
|
+
ttsDoneEventSchema,
|
|
60
|
+
ttsErrorEventSchema,
|
|
61
|
+
ttsInputTranscriptEventSchema,
|
|
62
|
+
ttsOutputAudioEventSchema,
|
|
63
|
+
ttsServerEventSchema,
|
|
64
|
+
ttsSessionCloseEventSchema,
|
|
65
|
+
ttsSessionClosedEventSchema,
|
|
66
|
+
ttsSessionCreateEventSchema,
|
|
67
|
+
ttsSessionCreatedEventSchema,
|
|
68
|
+
ttsSessionFlushEventSchema
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=api_protos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/api_protos.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nexport const ttsSessionCreateEventSchema = z.object({\n type: z.literal('session.create'),\n sample_rate: z.string(),\n encoding: z.string(),\n model: z.string().optional(),\n voice: z.string().optional(),\n language: z.string().optional(),\n extra: z.record(z.string(), z.unknown()),\n transcript: z.string().optional(),\n});\n\nexport const ttsInputTranscriptEventSchema = z.object({\n type: z.literal('input_transcript'),\n transcript: z.string(),\n});\n\nexport const ttsSessionFlushEventSchema = z.object({\n type: z.literal('session.flush'),\n});\n\nexport const ttsSessionCloseEventSchema = z.object({\n type: z.literal('session.close'),\n});\n\nexport const ttsSessionCreatedEventSchema = z.object({\n type: z.literal('session.created'),\n session_id: z.string(),\n});\n\nexport const ttsOutputAudioEventSchema = z.object({\n type: z.literal('output_audio'),\n audio: z.string(),\n session_id: z.string(),\n});\n\nexport const ttsDoneEventSchema = z.object({\n type: z.literal('done'),\n session_id: z.string(),\n});\n\nexport const ttsSessionClosedEventSchema = z.object({\n type: z.literal('session.closed'),\n session_id: z.string(),\n});\n\nexport const ttsErrorEventSchema = z.object({\n type: z.literal('error'),\n message: z.string(),\n session_id: z.string(),\n});\n\nexport const ttsClientEventSchema = z.discriminatedUnion('type', [\n ttsSessionCreateEventSchema,\n ttsInputTranscriptEventSchema,\n ttsSessionFlushEventSchema,\n ttsSessionCloseEventSchema,\n]);\n\nexport const ttsServerEventSchema = z.discriminatedUnion('type', [\n ttsSessionCreatedEventSchema,\n ttsOutputAudioEventSchema,\n ttsDoneEventSchema,\n ttsSessionClosedEventSchema,\n ttsErrorEventSchema,\n]);\n\nexport type TtsSessionCreateEvent = z.infer<typeof ttsSessionCreateEventSchema>;\nexport type TtsInputTranscriptEvent = z.infer<typeof ttsInputTranscriptEventSchema>;\nexport type TtsSessionFlushEvent = z.infer<typeof ttsSessionFlushEventSchema>;\nexport type TtsSessionCloseEvent = z.infer<typeof ttsSessionCloseEventSchema>;\nexport type TtsSessionCreatedEvent = z.infer<typeof ttsSessionCreatedEventSchema>;\nexport type TtsOutputAudioEvent = z.infer<typeof ttsOutputAudioEventSchema>;\nexport type TtsDoneEvent = z.infer<typeof ttsDoneEventSchema>;\nexport type TtsSessionClosedEvent = z.infer<typeof ttsSessionClosedEventSchema>;\nexport type TtsErrorEvent = z.infer<typeof ttsErrorEventSchema>;\nexport type TtsClientEvent = z.infer<typeof ttsClientEventSchema>;\nexport type TtsServerEvent = z.infer<typeof ttsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAEX,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,MAAM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,CAAC;AAEM,MAAM,uBAAuB,EAAE,mBAAmB,QAAQ;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,MAAM,uBAAuB,EAAE,mBAAmB,QAAQ;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var inference_exports = {};
|
|
30
|
+
__export(inference_exports, {
|
|
31
|
+
LLM: () => import_llm.LLM,
|
|
32
|
+
LLMStream: () => import_llm.LLMStream,
|
|
33
|
+
STT: () => import_stt.STT,
|
|
34
|
+
TTS: () => import_tts.TTS,
|
|
35
|
+
llm: () => llm,
|
|
36
|
+
stt: () => stt,
|
|
37
|
+
tts: () => tts
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(inference_exports);
|
|
40
|
+
var llm = __toESM(require("./llm.cjs"), 1);
|
|
41
|
+
var stt = __toESM(require("./stt.cjs"), 1);
|
|
42
|
+
var tts = __toESM(require("./tts.cjs"), 1);
|
|
43
|
+
var import_llm = require("./llm.cjs");
|
|
44
|
+
var import_stt = require("./stt.cjs");
|
|
45
|
+
var import_tts = require("./tts.cjs");
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
LLM,
|
|
49
|
+
LLMStream,
|
|
50
|
+
STT,
|
|
51
|
+
TTS,
|
|
52
|
+
llm,
|
|
53
|
+
stt,
|
|
54
|
+
tts
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport * as llm from './llm.js';\nimport * as stt from './stt.js';\nimport * as tts from './tts.js';\n\nexport { LLM, LLMStream, type AzureModels, type LLMModels, type LLMOptions } from './llm.js';\nexport type { GatewayOptions, InferenceLLMOptions } from './llm.js';\nexport { STT, type STTLanguages, type STTModels, type STTOptions } from './stt.js';\nexport { TTS, type TTSModels, type TTSOptions } from './tts.js';\nexport { llm, stt, tts };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,UAAqB;AACrB,UAAqB;AACrB,UAAqB;AAErB,iBAAkF;AAElF,iBAAwE;AACxE,iBAAqD;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as llm from './llm.js';
|
|
2
|
+
import * as stt from './stt.js';
|
|
3
|
+
import * as tts from './tts.js';
|
|
4
|
+
export { LLM, LLMStream, type AzureModels, type LLMModels, type LLMOptions } from './llm.js';
|
|
5
|
+
export type { GatewayOptions, InferenceLLMOptions } from './llm.js';
|
|
6
|
+
export { STT, type STTLanguages, type STTModels, type STTOptions } from './stt.js';
|
|
7
|
+
export { TTS, type TTSModels, type TTSOptions } from './tts.js';
|
|
8
|
+
export { llm, stt, tts };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as llm from './llm.js';
|
|
2
|
+
import * as stt from './stt.js';
|
|
3
|
+
import * as tts from './tts.js';
|
|
4
|
+
export { LLM, LLMStream, type AzureModels, type LLMModels, type LLMOptions } from './llm.js';
|
|
5
|
+
export type { GatewayOptions, InferenceLLMOptions } from './llm.js';
|
|
6
|
+
export { STT, type STTLanguages, type STTModels, type STTOptions } from './stt.js';
|
|
7
|
+
export { TTS, type TTSModels, type TTSOptions } from './tts.js';
|
|
8
|
+
export { llm, stt, tts };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,EAAE,GAAG,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as llm from "./llm.js";
|
|
2
|
+
import * as stt from "./stt.js";
|
|
3
|
+
import * as tts from "./tts.js";
|
|
4
|
+
import { LLM, LLMStream } from "./llm.js";
|
|
5
|
+
import { STT } from "./stt.js";
|
|
6
|
+
import { TTS } from "./tts.js";
|
|
7
|
+
export {
|
|
8
|
+
LLM,
|
|
9
|
+
LLMStream,
|
|
10
|
+
STT,
|
|
11
|
+
TTS,
|
|
12
|
+
llm,
|
|
13
|
+
stt,
|
|
14
|
+
tts
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport * as llm from './llm.js';\nimport * as stt from './stt.js';\nimport * as tts from './tts.js';\n\nexport { LLM, LLMStream, type AzureModels, type LLMModels, type LLMOptions } from './llm.js';\nexport type { GatewayOptions, InferenceLLMOptions } from './llm.js';\nexport { STT, type STTLanguages, type STTModels, type STTOptions } from './stt.js';\nexport { TTS, type TTSModels, type TTSOptions } from './tts.js';\nexport { llm, stt, tts };\n"],"mappings":"AAGA,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,YAAY,SAAS;AAErB,SAAS,KAAK,iBAAoE;AAElF,SAAS,WAA+D;AACxE,SAAS,WAA4C;","names":[]}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var llm_exports = {};
|
|
30
|
+
__export(llm_exports, {
|
|
31
|
+
LLM: () => LLM,
|
|
32
|
+
LLMStream: () => LLMStream
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(llm_exports);
|
|
35
|
+
var import_openai = __toESM(require("openai"), 1);
|
|
36
|
+
var import__ = require("../index.cjs");
|
|
37
|
+
var llm = __toESM(require("../llm/index.cjs"), 1);
|
|
38
|
+
var import_utils = require("./utils.cjs");
|
|
39
|
+
const DEFAULT_BASE_URL = "https://agent-gateway.livekit.cloud/v1";
|
|
40
|
+
class LLM extends llm.LLM {
|
|
41
|
+
client;
|
|
42
|
+
opts;
|
|
43
|
+
constructor(opts) {
|
|
44
|
+
super();
|
|
45
|
+
const {
|
|
46
|
+
model,
|
|
47
|
+
temperature,
|
|
48
|
+
parallelToolCalls,
|
|
49
|
+
toolChoice,
|
|
50
|
+
maxCompletionTokens,
|
|
51
|
+
baseURL,
|
|
52
|
+
apiKey,
|
|
53
|
+
apiSecret,
|
|
54
|
+
maxRetries,
|
|
55
|
+
timeout,
|
|
56
|
+
verbosity,
|
|
57
|
+
extraKwargs
|
|
58
|
+
} = opts;
|
|
59
|
+
const lkBaseURL = baseURL || process.env.LIVEKIT_INFERENCE_URL || DEFAULT_BASE_URL;
|
|
60
|
+
const lkApiKey = apiKey || process.env.LIVEKIT_INFERENCE_API_KEY || process.env.LIVEKIT_API_KEY;
|
|
61
|
+
if (!lkApiKey) {
|
|
62
|
+
throw new Error("apiKey is required: pass apiKey or set LIVEKIT_API_KEY");
|
|
63
|
+
}
|
|
64
|
+
const lkApiSecret = apiSecret || process.env.LIVEKIT_INFERENCE_API_SECRET || process.env.LIVEKIT_API_SECRET;
|
|
65
|
+
if (!lkApiSecret) {
|
|
66
|
+
throw new Error("apiSecret is required: pass apiSecret or set LIVEKIT_API_SECRET");
|
|
67
|
+
}
|
|
68
|
+
this.opts = {
|
|
69
|
+
model,
|
|
70
|
+
temperature,
|
|
71
|
+
parallelToolCalls,
|
|
72
|
+
toolChoice,
|
|
73
|
+
verbosity,
|
|
74
|
+
maxCompletionTokens,
|
|
75
|
+
baseURL: lkBaseURL,
|
|
76
|
+
apiKey: lkApiKey,
|
|
77
|
+
apiSecret: lkApiSecret,
|
|
78
|
+
extraKwargs: extraKwargs || {}
|
|
79
|
+
};
|
|
80
|
+
this.client = new import_openai.default({
|
|
81
|
+
baseURL: this.opts.baseURL,
|
|
82
|
+
maxRetries: maxRetries || 0,
|
|
83
|
+
timeout: timeout || 15e3
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
label() {
|
|
87
|
+
return "inference.LLM";
|
|
88
|
+
}
|
|
89
|
+
get model() {
|
|
90
|
+
return this.opts.model;
|
|
91
|
+
}
|
|
92
|
+
chat({
|
|
93
|
+
chatCtx,
|
|
94
|
+
toolCtx,
|
|
95
|
+
connOptions = import__.DEFAULT_API_CONNECT_OPTIONS,
|
|
96
|
+
parallelToolCalls,
|
|
97
|
+
toolChoice,
|
|
98
|
+
// TODO(AJS-270): Add response_format parameter support
|
|
99
|
+
extraKwargs
|
|
100
|
+
}) {
|
|
101
|
+
let extras = { ...extraKwargs || {} };
|
|
102
|
+
if (this.opts.maxCompletionTokens !== void 0) {
|
|
103
|
+
extras.max_completion_tokens = this.opts.maxCompletionTokens;
|
|
104
|
+
}
|
|
105
|
+
if (this.opts.temperature !== void 0) {
|
|
106
|
+
extras.temperature = this.opts.temperature;
|
|
107
|
+
}
|
|
108
|
+
if (this.opts.verbosity !== void 0) {
|
|
109
|
+
extras.verbosity = this.opts.verbosity;
|
|
110
|
+
}
|
|
111
|
+
parallelToolCalls = parallelToolCalls !== void 0 ? parallelToolCalls : this.opts.parallelToolCalls;
|
|
112
|
+
if (toolCtx && Object.keys(toolCtx).length > 0 && parallelToolCalls !== void 0) {
|
|
113
|
+
extras.parallel_tool_calls = parallelToolCalls;
|
|
114
|
+
}
|
|
115
|
+
toolChoice = toolChoice !== void 0 ? toolChoice : this.opts.toolChoice;
|
|
116
|
+
if (toolChoice) {
|
|
117
|
+
extras.tool_choice = toolChoice;
|
|
118
|
+
}
|
|
119
|
+
extras = { ...extras, ...this.opts.extraKwargs };
|
|
120
|
+
return new LLMStream(this, {
|
|
121
|
+
model: this.opts.model,
|
|
122
|
+
providerFmt: "openai",
|
|
123
|
+
client: this.client,
|
|
124
|
+
chatCtx,
|
|
125
|
+
toolCtx,
|
|
126
|
+
connOptions,
|
|
127
|
+
extraKwargs: extras,
|
|
128
|
+
gatewayOptions: {
|
|
129
|
+
apiKey: this.opts.apiKey,
|
|
130
|
+
apiSecret: this.opts.apiSecret
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
class LLMStream extends llm.LLMStream {
|
|
136
|
+
model;
|
|
137
|
+
providerFmt;
|
|
138
|
+
client;
|
|
139
|
+
extraKwargs;
|
|
140
|
+
gatewayOptions;
|
|
141
|
+
toolCallId;
|
|
142
|
+
toolIndex;
|
|
143
|
+
fncName;
|
|
144
|
+
fncRawArguments;
|
|
145
|
+
constructor(llm2, {
|
|
146
|
+
model,
|
|
147
|
+
providerFmt,
|
|
148
|
+
client,
|
|
149
|
+
chatCtx,
|
|
150
|
+
toolCtx,
|
|
151
|
+
gatewayOptions,
|
|
152
|
+
connOptions,
|
|
153
|
+
extraKwargs
|
|
154
|
+
}) {
|
|
155
|
+
super(llm2, { chatCtx, toolCtx, connOptions });
|
|
156
|
+
this.client = client;
|
|
157
|
+
this.gatewayOptions = gatewayOptions;
|
|
158
|
+
this.providerFmt = providerFmt;
|
|
159
|
+
this.extraKwargs = extraKwargs;
|
|
160
|
+
this.model = model;
|
|
161
|
+
}
|
|
162
|
+
async run() {
|
|
163
|
+
var _a;
|
|
164
|
+
let retryable = true;
|
|
165
|
+
this.toolCallId = this.fncName = this.fncRawArguments = this.toolIndex = void 0;
|
|
166
|
+
try {
|
|
167
|
+
const messages = await this.chatCtx.toProviderFormat(
|
|
168
|
+
this.providerFmt
|
|
169
|
+
);
|
|
170
|
+
const tools = this.toolCtx ? Object.entries(this.toolCtx).map(([name, func]) => ({
|
|
171
|
+
type: "function",
|
|
172
|
+
function: {
|
|
173
|
+
name,
|
|
174
|
+
description: func.description,
|
|
175
|
+
parameters: llm.toJsonSchema(
|
|
176
|
+
func.parameters
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
})) : void 0;
|
|
180
|
+
const requestExtras = { ...this.extraKwargs };
|
|
181
|
+
if (!tools) {
|
|
182
|
+
delete requestExtras.tool_choice;
|
|
183
|
+
}
|
|
184
|
+
if (this.gatewayOptions) {
|
|
185
|
+
this.client.apiKey = await (0, import_utils.createAccessToken)(
|
|
186
|
+
this.gatewayOptions.apiKey,
|
|
187
|
+
this.gatewayOptions.apiSecret
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const stream = await this.client.chat.completions.create(
|
|
191
|
+
{
|
|
192
|
+
model: this.model,
|
|
193
|
+
messages,
|
|
194
|
+
tools,
|
|
195
|
+
stream: true,
|
|
196
|
+
stream_options: { include_usage: true },
|
|
197
|
+
...requestExtras
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
timeout: this.connOptions.timeoutMs
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
for await (const chunk of stream) {
|
|
204
|
+
for (const choice of chunk.choices) {
|
|
205
|
+
if (this.abortController.signal.aborted) {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
const chatChunk = this.parseChoice(chunk.id, choice);
|
|
209
|
+
if (chatChunk) {
|
|
210
|
+
retryable = false;
|
|
211
|
+
this.queue.put(chatChunk);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (chunk.usage) {
|
|
215
|
+
const usage = chunk.usage;
|
|
216
|
+
retryable = false;
|
|
217
|
+
this.queue.put({
|
|
218
|
+
id: chunk.id,
|
|
219
|
+
usage: {
|
|
220
|
+
completionTokens: usage.completion_tokens,
|
|
221
|
+
promptTokens: usage.prompt_tokens,
|
|
222
|
+
promptCachedTokens: ((_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) || 0,
|
|
223
|
+
totalTokens: usage.total_tokens
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (error instanceof import_openai.default.APIConnectionTimeoutError) {
|
|
230
|
+
throw new import__.APITimeoutError({ options: { retryable } });
|
|
231
|
+
} else if (error instanceof import_openai.default.APIError) {
|
|
232
|
+
throw new import__.APIStatusError({
|
|
233
|
+
message: error.message,
|
|
234
|
+
options: {
|
|
235
|
+
statusCode: error.status,
|
|
236
|
+
body: error.error,
|
|
237
|
+
requestId: error.request_id,
|
|
238
|
+
retryable
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
throw new import__.APIConnectionError({
|
|
243
|
+
message: (0, import__.toError)(error).message,
|
|
244
|
+
options: { retryable }
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
} finally {
|
|
248
|
+
this.queue.close();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
parseChoice(id, choice) {
|
|
252
|
+
const delta = choice.delta;
|
|
253
|
+
if (delta === void 0) return void 0;
|
|
254
|
+
if (delta.tool_calls) {
|
|
255
|
+
for (const tool of delta.tool_calls) {
|
|
256
|
+
if (!tool.function) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
let callChunk;
|
|
260
|
+
if (this.toolCallId && tool.id && tool.index !== this.toolIndex) {
|
|
261
|
+
callChunk = this.createRunningToolCallChunk(id, delta);
|
|
262
|
+
this.toolCallId = this.fncName = this.fncRawArguments = void 0;
|
|
263
|
+
}
|
|
264
|
+
if (tool.function.name) {
|
|
265
|
+
this.toolIndex = tool.index;
|
|
266
|
+
this.toolCallId = tool.id;
|
|
267
|
+
this.fncName = tool.function.name;
|
|
268
|
+
this.fncRawArguments = tool.function.arguments || "";
|
|
269
|
+
} else if (tool.function.arguments) {
|
|
270
|
+
this.fncRawArguments = (this.fncRawArguments || "") + tool.function.arguments;
|
|
271
|
+
}
|
|
272
|
+
if (callChunk) {
|
|
273
|
+
return callChunk;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (choice.finish_reason && ["tool_calls", "stop"].includes(choice.finish_reason) && this.toolCallId !== void 0) {
|
|
278
|
+
const callChunk = this.createRunningToolCallChunk(id, delta);
|
|
279
|
+
this.toolCallId = this.fncName = this.fncRawArguments = void 0;
|
|
280
|
+
return callChunk;
|
|
281
|
+
}
|
|
282
|
+
if (!delta.content) {
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
id,
|
|
287
|
+
delta: {
|
|
288
|
+
role: "assistant",
|
|
289
|
+
content: delta.content
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
createRunningToolCallChunk(id, delta) {
|
|
294
|
+
return {
|
|
295
|
+
id,
|
|
296
|
+
delta: {
|
|
297
|
+
role: "assistant",
|
|
298
|
+
content: delta.content || void 0,
|
|
299
|
+
toolCalls: [
|
|
300
|
+
llm.FunctionCall.create({
|
|
301
|
+
callId: this.toolCallId || "",
|
|
302
|
+
name: this.fncName || "",
|
|
303
|
+
args: this.fncRawArguments || ""
|
|
304
|
+
})
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
311
|
+
0 && (module.exports = {
|
|
312
|
+
LLM,
|
|
313
|
+
LLMStream
|
|
314
|
+
});
|
|
315
|
+
//# sourceMappingURL=llm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport OpenAI from 'openai';\nimport {\n APIConnectionError,\n APIStatusError,\n APITimeoutError,\n DEFAULT_API_CONNECT_OPTIONS,\n toError,\n} from '../index.js';\nimport * as llm from '../llm/index.js';\nimport type { APIConnectOptions } from '../types.js';\nimport { type AnyModels, createAccessToken } from './utils.js';\n\nexport type AzureModels =\n // | \"azure/gpt-5\"\n // | \"azure/gpt-5-mini\"\n // | \"azure/gpt-5-nano\"\n 'azure/gpt-4.1' | 'azure/gpt-4.1-mini' | 'azure/gpt-4.1-nano';\n// | \"azure/gpt-4o\"\n// | \"azure/gpt-4o-mini\"\n\n// https://inference-docs.cerebras.ai/models/overview\nexport type CerebrasModels =\n // production models\n | 'cerebras/llama3.1-8b'\n | 'cerebras/llama-3.3-70b'\n | 'cerebras/llama-4-scout-17b-16e-instruct'\n | 'cerebras/gpt-oss-120b'\n | 'cerebras/qwen-3-32b'\n // preview models\n | 'cerebras/llama-4-maverick-17b-128e-instruct'\n | 'cerebras/qwen-3-235b-a22b-instruct-2507';\n\n// https://console.groq.com/docs/models\nexport type GroqModels =\n // production models\n | 'groq/llama-3.1-8b-instant'\n | 'groq/llama-3.3-70b-versatile'\n | 'groq/openai/gpt-oss-120b'\n | 'groq/openai/gpt-oss-20b'\n // preview models\n | 'groq/meta-llama/llama-4-maverick-17b-128e-instruct'\n | 'groq/meta-llama/llama-4-scout-17b-16e-instruct'\n | 'groq/qwen/qwen3-32b';\n\n// https://www.baseten.co/library/tag/llms\nexport type BasetenModels =\n | 'baseten/deepseek-ai/DeepSeek-V3-0324'\n | 'baseten/meta-llama/Llama-4-Scout-17B-16E-Instruct'\n | 'baseten/meta-llama/Llama-4-Maverick-17B-128E-Instruct'\n | 'baseten/moonshotai/Kimi-K2-Instruct'\n | 'baseten/openai/gpt-oss-120b'\n | 'baseten/Qwen/Qwen3-235B-A22B-Instruct-2507';\n\nexport interface AzureOptions {\n top_p?: number;\n}\n\nexport interface CerebrasOptions {\n top_p?: number;\n}\n\nexport interface GroqOptions {\n top_p?: number;\n}\n\nexport interface BasetenOptions {\n top_p?: number;\n}\n\nexport type LLMModels = AzureModels | CerebrasModels | GroqModels | BasetenModels | AnyModels;\n\nexport type LLMOptions<T extends LLMModels> = T extends AzureModels\n ? AzureOptions\n : T extends CerebrasModels\n ? CerebrasOptions\n : T extends GroqOptions\n ? GroqOptions\n : T extends BasetenOptions\n ? BasetenOptions\n : Record<string, unknown>;\n\nexport type Verbosity = 'low' | 'medium' | 'high';\nconst DEFAULT_BASE_URL = 'https://agent-gateway.livekit.cloud/v1';\n\nexport interface InferenceLLMOptions<TModel extends LLMModels> {\n model: TModel;\n temperature?: number;\n parallelToolCalls?: boolean;\n toolChoice?: llm.ToolChoice;\n maxCompletionTokens?: number;\n baseURL: string;\n apiKey: string;\n apiSecret: string;\n verbosity?: Verbosity;\n extraKwargs: Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface GatewayOptions {\n apiKey: string;\n apiSecret: string;\n}\n\nexport class LLM<TModel extends LLMModels> extends llm.LLM {\n private client: OpenAI;\n private opts: InferenceLLMOptions<TModel>;\n\n constructor(opts: {\n model: TModel;\n temperature?: number;\n parallelToolCalls?: boolean;\n toolChoice?: llm.ToolChoice;\n maxCompletionTokens?: number;\n baseURL?: string;\n apiKey?: string;\n apiSecret?: string;\n maxRetries?: number;\n timeout?: number;\n verbosity?: Verbosity;\n extraKwargs?: LLMOptions<TModel>;\n }) {\n super();\n\n const {\n model,\n temperature,\n parallelToolCalls,\n toolChoice,\n maxCompletionTokens,\n baseURL,\n apiKey,\n apiSecret,\n maxRetries,\n timeout,\n verbosity,\n extraKwargs,\n } = opts;\n\n const lkBaseURL = baseURL || process.env.LIVEKIT_INFERENCE_URL || DEFAULT_BASE_URL;\n const lkApiKey = apiKey || process.env.LIVEKIT_INFERENCE_API_KEY || process.env.LIVEKIT_API_KEY;\n if (!lkApiKey) {\n throw new Error('apiKey is required: pass apiKey or set LIVEKIT_API_KEY');\n }\n\n const lkApiSecret =\n apiSecret || process.env.LIVEKIT_INFERENCE_API_SECRET || process.env.LIVEKIT_API_SECRET;\n if (!lkApiSecret) {\n throw new Error('apiSecret is required: pass apiSecret or set LIVEKIT_API_SECRET');\n }\n\n this.opts = {\n model,\n temperature,\n parallelToolCalls,\n toolChoice,\n verbosity,\n maxCompletionTokens,\n baseURL: lkBaseURL,\n apiKey: lkApiKey,\n apiSecret: lkApiSecret,\n extraKwargs: extraKwargs || {},\n };\n\n this.client = new OpenAI({\n baseURL: this.opts.baseURL,\n maxRetries: maxRetries || 0,\n timeout: timeout || 15000,\n });\n }\n\n label(): string {\n return 'inference.LLM';\n }\n\n get model(): string {\n return this.opts.model;\n }\n\n chat({\n chatCtx,\n toolCtx,\n connOptions = DEFAULT_API_CONNECT_OPTIONS,\n parallelToolCalls,\n toolChoice,\n // TODO(AJS-270): Add response_format parameter support\n extraKwargs,\n }: {\n chatCtx: llm.ChatContext;\n toolCtx?: llm.ToolContext;\n connOptions?: APIConnectOptions;\n parallelToolCalls?: boolean;\n toolChoice?: llm.ToolChoice;\n // TODO(AJS-270): Add responseFormat parameter\n extraKwargs?: Record<string, unknown>;\n }): LLMStream<TModel> {\n let extras: Record<string, unknown> = { ...(extraKwargs || {}) };\n\n if (this.opts.maxCompletionTokens !== undefined) {\n extras.max_completion_tokens = this.opts.maxCompletionTokens;\n }\n if (this.opts.temperature !== undefined) {\n extras.temperature = this.opts.temperature;\n }\n if (this.opts.verbosity !== undefined) {\n extras.verbosity = this.opts.verbosity;\n }\n\n parallelToolCalls =\n parallelToolCalls !== undefined ? parallelToolCalls : this.opts.parallelToolCalls;\n if (toolCtx && Object.keys(toolCtx).length > 0 && parallelToolCalls !== undefined) {\n extras.parallel_tool_calls = parallelToolCalls;\n }\n\n toolChoice = toolChoice !== undefined ? toolChoice : this.opts.toolChoice;\n if (toolChoice) {\n extras.tool_choice = toolChoice;\n }\n\n // TODO(AJS-270): Add response_format support here\n\n extras = { ...extras, ...this.opts.extraKwargs };\n\n return new LLMStream(this, {\n model: this.opts.model,\n providerFmt: 'openai',\n client: this.client,\n chatCtx,\n toolCtx,\n connOptions,\n extraKwargs: extras,\n gatewayOptions: {\n apiKey: this.opts.apiKey,\n apiSecret: this.opts.apiSecret,\n },\n });\n }\n}\n\nexport class LLMStream<TModel extends LLMModels> extends llm.LLMStream {\n private model: TModel;\n private providerFmt: llm.ProviderFormat;\n private client: OpenAI;\n private extraKwargs: Record<string, unknown>;\n\n private gatewayOptions?: GatewayOptions;\n private toolCallId?: string;\n private toolIndex?: number;\n private fncName?: string;\n private fncRawArguments?: string;\n\n constructor(\n llm: LLM<TModel>,\n {\n model,\n providerFmt,\n client,\n chatCtx,\n toolCtx,\n gatewayOptions,\n connOptions,\n extraKwargs,\n }: {\n model: TModel;\n providerFmt: llm.ProviderFormat;\n client: OpenAI;\n chatCtx: llm.ChatContext;\n toolCtx?: llm.ToolContext;\n gatewayOptions?: GatewayOptions;\n connOptions: APIConnectOptions;\n extraKwargs: Record<string, any>;\n },\n ) {\n super(llm, { chatCtx, toolCtx, connOptions });\n this.client = client;\n this.gatewayOptions = gatewayOptions;\n this.providerFmt = providerFmt;\n this.extraKwargs = extraKwargs;\n this.model = model;\n }\n\n protected async run(): Promise<void> {\n // current function call that we're waiting for full completion (args are streamed)\n // (defined inside the run method to make sure the state is reset for each run/attempt)\n let retryable = true;\n this.toolCallId = this.fncName = this.fncRawArguments = this.toolIndex = undefined;\n\n try {\n const messages = (await this.chatCtx.toProviderFormat(\n this.providerFmt,\n )) as OpenAI.ChatCompletionMessageParam[];\n\n const tools = this.toolCtx\n ? Object.entries(this.toolCtx).map(([name, func]) => ({\n type: 'function' as const,\n function: {\n name,\n description: func.description,\n parameters: llm.toJsonSchema(\n func.parameters,\n ) as unknown as OpenAI.Chat.Completions.ChatCompletionTool['function']['parameters'],\n },\n }))\n : undefined;\n\n const requestExtras: Record<string, unknown> = { ...this.extraKwargs };\n if (!tools) {\n delete requestExtras.tool_choice;\n }\n\n // Dynamically set the access token for the LiveKit Agent Gateway API\n if (this.gatewayOptions) {\n this.client.apiKey = await createAccessToken(\n this.gatewayOptions.apiKey,\n this.gatewayOptions.apiSecret,\n );\n }\n\n const stream = await this.client.chat.completions.create(\n {\n model: this.model,\n messages,\n tools,\n stream: true,\n stream_options: { include_usage: true },\n ...requestExtras,\n },\n {\n timeout: this.connOptions.timeoutMs,\n },\n );\n\n for await (const chunk of stream) {\n for (const choice of chunk.choices) {\n if (this.abortController.signal.aborted) {\n break;\n }\n const chatChunk = this.parseChoice(chunk.id, choice);\n if (chatChunk) {\n retryable = false;\n this.queue.put(chatChunk);\n }\n }\n\n if (chunk.usage) {\n const usage = chunk.usage;\n retryable = false;\n this.queue.put({\n id: chunk.id,\n usage: {\n completionTokens: usage.completion_tokens,\n promptTokens: usage.prompt_tokens,\n promptCachedTokens: usage.prompt_tokens_details?.cached_tokens || 0,\n totalTokens: usage.total_tokens,\n },\n });\n }\n }\n } catch (error) {\n if (error instanceof OpenAI.APIConnectionTimeoutError) {\n throw new APITimeoutError({ options: { retryable } });\n } else if (error instanceof OpenAI.APIError) {\n throw new APIStatusError({\n message: error.message,\n options: {\n statusCode: error.status,\n body: error.error,\n requestId: error.request_id,\n retryable,\n },\n });\n } else {\n throw new APIConnectionError({\n message: toError(error).message,\n options: { retryable },\n });\n }\n } finally {\n this.queue.close();\n }\n }\n\n private parseChoice(\n id: string,\n choice: OpenAI.ChatCompletionChunk.Choice,\n ): llm.ChatChunk | undefined {\n const delta = choice.delta;\n\n // https://github.com/livekit/agents/issues/688\n // the delta can be None when using Azure OpenAI (content filtering)\n if (delta === undefined) return undefined;\n\n if (delta.tool_calls) {\n // check if we have functions to calls\n for (const tool of delta.tool_calls) {\n if (!tool.function) {\n continue; // oai may add other tools in the future\n }\n\n /**\n * The way OpenAI streams tool calls is a bit tricky.\n *\n * For any new tool call, it first emits a delta tool call with id, and function name,\n * the rest of the delta chunks will only stream the remaining arguments string,\n * until a new tool call is started or the tool call is finished.\n * See below for an example.\n *\n * Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role='assistant', tool_calls=None), finish_reason=None, index=0, logprobs=None)\n * [ChoiceDeltaToolCall(index=0, id='call_LaVeHWUHpef9K1sd5UO8TtLg', function=ChoiceDeltaToolCallFunction(arguments='', name='get_weather'), type='function')]\n * [ChoiceDeltaToolCall(index=0, id=None, function=ChoiceDeltaToolCallFunction(arguments='{\"location\": \"P', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=0, id=None, function=ChoiceDeltaToolCallFunction(arguments='aris}', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=1, id='call_ThU4OmMdQXnnVmpXGOCknXIB', function=ChoiceDeltaToolCallFunction(arguments='', name='get_weather'), type='function')]\n * [ChoiceDeltaToolCall(index=1, id=None, function=ChoiceDeltaToolCallFunction(arguments='{\"location\": \"T', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=1, id=None, function=ChoiceDeltaToolCallFunction(arguments='okyo', name=None), type=None)]\n * Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None), finish_reason='tool_calls', index=0, logprobs=None)\n */\n let callChunk: llm.ChatChunk | undefined;\n // If we have a previous tool call and this is a new one, emit the previous\n if (this.toolCallId && tool.id && tool.index !== this.toolIndex) {\n callChunk = this.createRunningToolCallChunk(id, delta);\n this.toolCallId = this.fncName = this.fncRawArguments = undefined;\n }\n\n // Start or continue building the current tool call\n if (tool.function.name) {\n this.toolIndex = tool.index;\n this.toolCallId = tool.id;\n this.fncName = tool.function.name;\n this.fncRawArguments = tool.function.arguments || '';\n } else if (tool.function.arguments) {\n this.fncRawArguments = (this.fncRawArguments || '') + tool.function.arguments;\n }\n\n if (callChunk) {\n return callChunk;\n }\n }\n }\n\n // If we're done with tool calls, emit the final one\n if (\n choice.finish_reason &&\n ['tool_calls', 'stop'].includes(choice.finish_reason) &&\n this.toolCallId !== undefined\n ) {\n const callChunk = this.createRunningToolCallChunk(id, delta);\n this.toolCallId = this.fncName = this.fncRawArguments = undefined;\n return callChunk;\n }\n\n // Regular content message\n if (!delta.content) {\n return undefined;\n }\n\n return {\n id,\n delta: {\n role: 'assistant',\n content: delta.content,\n },\n };\n }\n\n private createRunningToolCallChunk(\n id: string,\n delta: OpenAI.Chat.Completions.ChatCompletionChunk.Choice.Delta,\n ): llm.ChatChunk {\n return {\n id,\n delta: {\n role: 'assistant',\n content: delta.content || undefined,\n toolCalls: [\n llm.FunctionCall.create({\n callId: this.toolCallId || '',\n name: this.fncName || '',\n args: this.fncRawArguments || '',\n }),\n ],\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmB;AACnB,eAMO;AACP,UAAqB;AAErB,mBAAkD;AAwElD,MAAM,mBAAmB;AAoBlB,MAAM,YAAsC,IAAI,IAAI;AAAA,EACjD;AAAA,EACA;AAAA,EAER,YAAY,MAaT;AACD,UAAM;AAEN,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,UAAM,YAAY,WAAW,QAAQ,IAAI,yBAAyB;AAClE,UAAM,WAAW,UAAU,QAAQ,IAAI,6BAA6B,QAAQ,IAAI;AAChF,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAEA,UAAM,cACJ,aAAa,QAAQ,IAAI,gCAAgC,QAAQ,IAAI;AACvE,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iEAAiE;AAAA,IACnF;AAEA,SAAK,OAAO;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,aAAa,eAAe,CAAC;AAAA,IAC/B;AAEA,SAAK,SAAS,IAAI,cAAAA,QAAO;AAAA,MACvB,SAAS,KAAK,KAAK;AAAA,MACnB,YAAY,cAAc;AAAA,MAC1B,SAAS,WAAW;AAAA,IACtB,CAAC;AAAA,EACH;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
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import * as llm from '../llm/index.js';
|
|
3
|
+
import type { APIConnectOptions } from '../types.js';
|
|
4
|
+
import { type AnyModels } from './utils.js';
|
|
5
|
+
export type AzureModels = 'azure/gpt-4.1' | 'azure/gpt-4.1-mini' | 'azure/gpt-4.1-nano';
|
|
6
|
+
export type CerebrasModels = 'cerebras/llama3.1-8b' | 'cerebras/llama-3.3-70b' | 'cerebras/llama-4-scout-17b-16e-instruct' | 'cerebras/gpt-oss-120b' | 'cerebras/qwen-3-32b' | 'cerebras/llama-4-maverick-17b-128e-instruct' | 'cerebras/qwen-3-235b-a22b-instruct-2507';
|
|
7
|
+
export type GroqModels = 'groq/llama-3.1-8b-instant' | 'groq/llama-3.3-70b-versatile' | 'groq/openai/gpt-oss-120b' | 'groq/openai/gpt-oss-20b' | 'groq/meta-llama/llama-4-maverick-17b-128e-instruct' | 'groq/meta-llama/llama-4-scout-17b-16e-instruct' | 'groq/qwen/qwen3-32b';
|
|
8
|
+
export type BasetenModels = 'baseten/deepseek-ai/DeepSeek-V3-0324' | 'baseten/meta-llama/Llama-4-Scout-17B-16E-Instruct' | 'baseten/meta-llama/Llama-4-Maverick-17B-128E-Instruct' | 'baseten/moonshotai/Kimi-K2-Instruct' | 'baseten/openai/gpt-oss-120b' | 'baseten/Qwen/Qwen3-235B-A22B-Instruct-2507';
|
|
9
|
+
export interface AzureOptions {
|
|
10
|
+
top_p?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CerebrasOptions {
|
|
13
|
+
top_p?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface GroqOptions {
|
|
16
|
+
top_p?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface BasetenOptions {
|
|
19
|
+
top_p?: number;
|
|
20
|
+
}
|
|
21
|
+
export type LLMModels = AzureModels | CerebrasModels | GroqModels | BasetenModels | AnyModels;
|
|
22
|
+
export type LLMOptions<T extends LLMModels> = T extends AzureModels ? AzureOptions : T extends CerebrasModels ? CerebrasOptions : T extends GroqOptions ? GroqOptions : T extends BasetenOptions ? BasetenOptions : Record<string, unknown>;
|
|
23
|
+
export type Verbosity = 'low' | 'medium' | 'high';
|
|
24
|
+
export interface InferenceLLMOptions<TModel extends LLMModels> {
|
|
25
|
+
model: TModel;
|
|
26
|
+
temperature?: number;
|
|
27
|
+
parallelToolCalls?: boolean;
|
|
28
|
+
toolChoice?: llm.ToolChoice;
|
|
29
|
+
maxCompletionTokens?: number;
|
|
30
|
+
baseURL: string;
|
|
31
|
+
apiKey: string;
|
|
32
|
+
apiSecret: string;
|
|
33
|
+
verbosity?: Verbosity;
|
|
34
|
+
extraKwargs: Record<string, any>;
|
|
35
|
+
}
|
|
36
|
+
export interface GatewayOptions {
|
|
37
|
+
apiKey: string;
|
|
38
|
+
apiSecret: string;
|
|
39
|
+
}
|
|
40
|
+
export declare class LLM<TModel extends LLMModels> extends llm.LLM {
|
|
41
|
+
private client;
|
|
42
|
+
private opts;
|
|
43
|
+
constructor(opts: {
|
|
44
|
+
model: TModel;
|
|
45
|
+
temperature?: number;
|
|
46
|
+
parallelToolCalls?: boolean;
|
|
47
|
+
toolChoice?: llm.ToolChoice;
|
|
48
|
+
maxCompletionTokens?: number;
|
|
49
|
+
baseURL?: string;
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
apiSecret?: string;
|
|
52
|
+
maxRetries?: number;
|
|
53
|
+
timeout?: number;
|
|
54
|
+
verbosity?: Verbosity;
|
|
55
|
+
extraKwargs?: LLMOptions<TModel>;
|
|
56
|
+
});
|
|
57
|
+
label(): string;
|
|
58
|
+
get model(): string;
|
|
59
|
+
chat({ chatCtx, toolCtx, connOptions, parallelToolCalls, toolChoice, extraKwargs, }: {
|
|
60
|
+
chatCtx: llm.ChatContext;
|
|
61
|
+
toolCtx?: llm.ToolContext;
|
|
62
|
+
connOptions?: APIConnectOptions;
|
|
63
|
+
parallelToolCalls?: boolean;
|
|
64
|
+
toolChoice?: llm.ToolChoice;
|
|
65
|
+
extraKwargs?: Record<string, unknown>;
|
|
66
|
+
}): LLMStream<TModel>;
|
|
67
|
+
}
|
|
68
|
+
export declare class LLMStream<TModel extends LLMModels> extends llm.LLMStream {
|
|
69
|
+
private model;
|
|
70
|
+
private providerFmt;
|
|
71
|
+
private client;
|
|
72
|
+
private extraKwargs;
|
|
73
|
+
private gatewayOptions?;
|
|
74
|
+
private toolCallId?;
|
|
75
|
+
private toolIndex?;
|
|
76
|
+
private fncName?;
|
|
77
|
+
private fncRawArguments?;
|
|
78
|
+
constructor(llm: LLM<TModel>, { model, providerFmt, client, chatCtx, toolCtx, gatewayOptions, connOptions, extraKwargs, }: {
|
|
79
|
+
model: TModel;
|
|
80
|
+
providerFmt: llm.ProviderFormat;
|
|
81
|
+
client: OpenAI;
|
|
82
|
+
chatCtx: llm.ChatContext;
|
|
83
|
+
toolCtx?: llm.ToolContext;
|
|
84
|
+
gatewayOptions?: GatewayOptions;
|
|
85
|
+
connOptions: APIConnectOptions;
|
|
86
|
+
extraKwargs: Record<string, any>;
|
|
87
|
+
});
|
|
88
|
+
protected run(): Promise<void>;
|
|
89
|
+
private parseChoice;
|
|
90
|
+
private createRunningToolCallChunk;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=llm.d.ts.map
|