@livekit/agents-plugin-openai 0.0.0-next-20260624041820

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.
Files changed (179) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +18 -0
  3. package/dist/index.cjs +74 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +9 -0
  6. package/dist/index.d.ts +9 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +30 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/llm.cjs +382 -0
  11. package/dist/llm.cjs.map +1 -0
  12. package/dist/llm.d.cts +230 -0
  13. package/dist/llm.d.ts +230 -0
  14. package/dist/llm.d.ts.map +1 -0
  15. package/dist/llm.js +357 -0
  16. package/dist/llm.js.map +1 -0
  17. package/dist/llm.test.cjs +36 -0
  18. package/dist/llm.test.cjs.map +1 -0
  19. package/dist/llm.test.d.cts +2 -0
  20. package/dist/llm.test.d.ts +2 -0
  21. package/dist/llm.test.d.ts.map +1 -0
  22. package/dist/llm.test.js +35 -0
  23. package/dist/llm.test.js.map +1 -0
  24. package/dist/models.cjs +50 -0
  25. package/dist/models.cjs.map +1 -0
  26. package/dist/models.d.cts +26 -0
  27. package/dist/models.d.ts +26 -0
  28. package/dist/models.d.ts.map +1 -0
  29. package/dist/models.js +25 -0
  30. package/dist/models.js.map +1 -0
  31. package/dist/realtime/api_proto.cjs +41 -0
  32. package/dist/realtime/api_proto.cjs.map +1 -0
  33. package/dist/realtime/api_proto.d.cts +501 -0
  34. package/dist/realtime/api_proto.d.ts +501 -0
  35. package/dist/realtime/api_proto.d.ts.map +1 -0
  36. package/dist/realtime/api_proto.js +13 -0
  37. package/dist/realtime/api_proto.js.map +1 -0
  38. package/dist/realtime/index.cjs +25 -0
  39. package/dist/realtime/index.cjs.map +1 -0
  40. package/dist/realtime/index.d.cts +3 -0
  41. package/dist/realtime/index.d.ts +3 -0
  42. package/dist/realtime/index.d.ts.map +1 -0
  43. package/dist/realtime/index.js +3 -0
  44. package/dist/realtime/index.js.map +1 -0
  45. package/dist/realtime/realtime_model.cjs +1658 -0
  46. package/dist/realtime/realtime_model.cjs.map +1 -0
  47. package/dist/realtime/realtime_model.d.cts +202 -0
  48. package/dist/realtime/realtime_model.d.ts +202 -0
  49. package/dist/realtime/realtime_model.d.ts.map +1 -0
  50. package/dist/realtime/realtime_model.js +1637 -0
  51. package/dist/realtime/realtime_model.js.map +1 -0
  52. package/dist/realtime/realtime_model.test.cjs +596 -0
  53. package/dist/realtime/realtime_model.test.cjs.map +1 -0
  54. package/dist/realtime/realtime_model.test.d.cts +2 -0
  55. package/dist/realtime/realtime_model.test.d.ts +2 -0
  56. package/dist/realtime/realtime_model.test.d.ts.map +1 -0
  57. package/dist/realtime/realtime_model.test.js +600 -0
  58. package/dist/realtime/realtime_model.test.js.map +1 -0
  59. package/dist/responses/index.cjs +23 -0
  60. package/dist/responses/index.cjs.map +1 -0
  61. package/dist/responses/index.d.cts +2 -0
  62. package/dist/responses/index.d.ts +2 -0
  63. package/dist/responses/index.d.ts.map +1 -0
  64. package/dist/responses/index.js +2 -0
  65. package/dist/responses/index.js.map +1 -0
  66. package/dist/responses/llm.cjs +353 -0
  67. package/dist/responses/llm.cjs.map +1 -0
  68. package/dist/responses/llm.d.cts +52 -0
  69. package/dist/responses/llm.d.ts +52 -0
  70. package/dist/responses/llm.d.ts.map +1 -0
  71. package/dist/responses/llm.js +327 -0
  72. package/dist/responses/llm.js.map +1 -0
  73. package/dist/responses/llm.test.cjs +37 -0
  74. package/dist/responses/llm.test.cjs.map +1 -0
  75. package/dist/responses/llm.test.d.cts +2 -0
  76. package/dist/responses/llm.test.d.ts +2 -0
  77. package/dist/responses/llm.test.d.ts.map +1 -0
  78. package/dist/responses/llm.test.js +36 -0
  79. package/dist/responses/llm.test.js.map +1 -0
  80. package/dist/stt.cjs +627 -0
  81. package/dist/stt.cjs.map +1 -0
  82. package/dist/stt.d.cts +105 -0
  83. package/dist/stt.d.ts +105 -0
  84. package/dist/stt.d.ts.map +1 -0
  85. package/dist/stt.js +605 -0
  86. package/dist/stt.js.map +1 -0
  87. package/dist/stt.test.cjs +132 -0
  88. package/dist/stt.test.cjs.map +1 -0
  89. package/dist/stt.test.d.cts +2 -0
  90. package/dist/stt.test.d.ts +2 -0
  91. package/dist/stt.test.d.ts.map +1 -0
  92. package/dist/stt.test.js +131 -0
  93. package/dist/stt.test.js.map +1 -0
  94. package/dist/tool_utils.cjs +53 -0
  95. package/dist/tool_utils.cjs.map +1 -0
  96. package/dist/tool_utils.d.cts +4 -0
  97. package/dist/tool_utils.d.ts +4 -0
  98. package/dist/tool_utils.d.ts.map +1 -0
  99. package/dist/tool_utils.js +29 -0
  100. package/dist/tool_utils.js.map +1 -0
  101. package/dist/tool_utils.test.cjs +77 -0
  102. package/dist/tool_utils.test.cjs.map +1 -0
  103. package/dist/tool_utils.test.d.cts +2 -0
  104. package/dist/tool_utils.test.d.ts +2 -0
  105. package/dist/tool_utils.test.d.ts.map +1 -0
  106. package/dist/tool_utils.test.js +76 -0
  107. package/dist/tool_utils.test.js.map +1 -0
  108. package/dist/tools.cjs +117 -0
  109. package/dist/tools.cjs.map +1 -0
  110. package/dist/tools.d.cts +88 -0
  111. package/dist/tools.d.ts +88 -0
  112. package/dist/tools.d.ts.map +1 -0
  113. package/dist/tools.js +90 -0
  114. package/dist/tools.js.map +1 -0
  115. package/dist/tts.cjs +141 -0
  116. package/dist/tts.cjs.map +1 -0
  117. package/dist/tts.d.cts +42 -0
  118. package/dist/tts.d.ts +42 -0
  119. package/dist/tts.d.ts.map +1 -0
  120. package/dist/tts.js +116 -0
  121. package/dist/tts.js.map +1 -0
  122. package/dist/tts.test.cjs +17 -0
  123. package/dist/tts.test.cjs.map +1 -0
  124. package/dist/tts.test.d.cts +2 -0
  125. package/dist/tts.test.d.ts +2 -0
  126. package/dist/tts.test.d.ts.map +1 -0
  127. package/dist/tts.test.js +16 -0
  128. package/dist/tts.test.js.map +1 -0
  129. package/dist/ws/index.cjs +29 -0
  130. package/dist/ws/index.cjs.map +1 -0
  131. package/dist/ws/index.d.cts +3 -0
  132. package/dist/ws/index.d.ts +3 -0
  133. package/dist/ws/index.d.ts.map +1 -0
  134. package/dist/ws/index.js +5 -0
  135. package/dist/ws/index.js.map +1 -0
  136. package/dist/ws/llm.cjs +523 -0
  137. package/dist/ws/llm.cjs.map +1 -0
  138. package/dist/ws/llm.d.cts +96 -0
  139. package/dist/ws/llm.d.ts +96 -0
  140. package/dist/ws/llm.d.ts.map +1 -0
  141. package/dist/ws/llm.js +505 -0
  142. package/dist/ws/llm.js.map +1 -0
  143. package/dist/ws/llm.test.cjs +69 -0
  144. package/dist/ws/llm.test.cjs.map +1 -0
  145. package/dist/ws/llm.test.d.cts +2 -0
  146. package/dist/ws/llm.test.d.ts +2 -0
  147. package/dist/ws/llm.test.d.ts.map +1 -0
  148. package/dist/ws/llm.test.js +68 -0
  149. package/dist/ws/llm.test.js.map +1 -0
  150. package/dist/ws/types.cjs +129 -0
  151. package/dist/ws/types.cjs.map +1 -0
  152. package/dist/ws/types.d.cts +172 -0
  153. package/dist/ws/types.d.ts +172 -0
  154. package/dist/ws/types.d.ts.map +1 -0
  155. package/dist/ws/types.js +96 -0
  156. package/dist/ws/types.js.map +1 -0
  157. package/package.json +56 -0
  158. package/src/index.ts +25 -0
  159. package/src/llm.test.ts +38 -0
  160. package/src/llm.ts +553 -0
  161. package/src/models.ts +235 -0
  162. package/src/realtime/api_proto.ts +714 -0
  163. package/src/realtime/index.ts +5 -0
  164. package/src/realtime/realtime_model.test.ts +793 -0
  165. package/src/realtime/realtime_model.ts +2116 -0
  166. package/src/responses/index.ts +4 -0
  167. package/src/responses/llm.test.ts +39 -0
  168. package/src/responses/llm.ts +452 -0
  169. package/src/stt.test.ts +167 -0
  170. package/src/stt.ts +793 -0
  171. package/src/tool_utils.test.ts +84 -0
  172. package/src/tool_utils.ts +46 -0
  173. package/src/tools.ts +166 -0
  174. package/src/tts.test.ts +19 -0
  175. package/src/tts.ts +158 -0
  176. package/src/ws/index.ts +17 -0
  177. package/src/ws/llm.test.ts +83 -0
  178. package/src/ws/llm.ts +710 -0
  179. package/src/ws/types.ts +132 -0
package/dist/llm.cjs ADDED
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var llm_exports = {};
20
+ __export(llm_exports, {
21
+ LLM: () => LLM,
22
+ LLMStream: () => LLMStream
23
+ });
24
+ module.exports = __toCommonJS(llm_exports);
25
+ var import_agents = require("@livekit/agents");
26
+ var import_openai = require("openai");
27
+ var import_models = require("./models.cjs");
28
+ const defaultLLMOptions = {
29
+ model: "gpt-4.1",
30
+ apiKey: process.env.OPENAI_API_KEY,
31
+ parallelToolCalls: true,
32
+ strictToolSchema: false
33
+ };
34
+ const defaultAzureLLMOptions = {
35
+ model: "gpt-4.1",
36
+ apiKey: process.env.AZURE_API_KEY,
37
+ strictToolSchema: false
38
+ };
39
+ class LLM extends import_agents.llm.LLM {
40
+ #opts;
41
+ #client;
42
+ #providerFmt;
43
+ /**
44
+ * Create a new instance of OpenAI LLM.
45
+ *
46
+ * @remarks
47
+ * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the
48
+ * `OPENAI_API_KEY` environment variable.
49
+ */
50
+ constructor(opts = defaultLLMOptions, providerFmt = "openai") {
51
+ super();
52
+ this.#opts = { ...defaultLLMOptions, ...opts };
53
+ this.#opts.reasoningEffort ??= (0, import_models.defaultReasoningEffort)(this.#opts.model);
54
+ this.#providerFmt = providerFmt;
55
+ if (this.#opts.apiKey === void 0 && !this.#opts.client) {
56
+ throw new Error("OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY");
57
+ }
58
+ this.#client = this.#opts.client || new import_openai.OpenAI({
59
+ baseURL: this.#opts.baseURL,
60
+ apiKey: this.#opts.apiKey
61
+ });
62
+ }
63
+ label() {
64
+ return "openai.LLM";
65
+ }
66
+ get model() {
67
+ return this.#opts.model;
68
+ }
69
+ get provider() {
70
+ try {
71
+ const url = new URL(this.#client.baseURL);
72
+ return url.host;
73
+ } catch {
74
+ return "api.openai.com";
75
+ }
76
+ }
77
+ /**
78
+ * Create a new instance of OpenAI LLM with Azure.
79
+ *
80
+ * @remarks
81
+ * This automatically infers the following arguments from their corresponding environment variables if they are not provided:
82
+ * - `apiKey` from `AZURE_OPENAI_API_KEY`
83
+ * - `organization` from `OPENAI_ORG_ID`
84
+ * - `project` from `OPENAI_PROJECT_ID`
85
+ * - `azureAdToken` from `AZURE_OPENAI_AD_TOKEN`
86
+ * - `apiVersion` from `OPENAI_API_VERSION`
87
+ * - `azureEndpoint` from `AZURE_OPENAI_ENDPOINT`
88
+ */
89
+ static withAzure(opts = defaultAzureLLMOptions) {
90
+ opts = { ...defaultAzureLLMOptions, ...opts };
91
+ if (opts.apiKey === void 0) {
92
+ throw new Error("Azure API key is required, whether as an argument or as $AZURE_API_KEY");
93
+ }
94
+ return new LLM({
95
+ temperature: opts.temperature,
96
+ user: opts.user,
97
+ client: new import_openai.AzureOpenAI(opts)
98
+ });
99
+ }
100
+ /**
101
+ * Create a new instance of Cerebras LLM.
102
+ *
103
+ * @remarks
104
+ * `apiKey` must be set to your Cerebras API key, either using the argument or by setting the
105
+ * `CEREBRAS_API_KEY` environment variable.
106
+ */
107
+ static withCerebras(opts = {}) {
108
+ opts.apiKey = opts.apiKey || process.env.CEREBRAS_API_KEY;
109
+ if (opts.apiKey === void 0) {
110
+ throw new Error(
111
+ "Cerebras API key is required, whether as an argument or as $CEREBRAS_API_KEY"
112
+ );
113
+ }
114
+ return new LLM({
115
+ model: "llama3.1-8b",
116
+ baseURL: "https://api.cerebras.ai/v1",
117
+ ...opts
118
+ });
119
+ }
120
+ /**
121
+ * Create a new instance of Fireworks LLM.
122
+ *
123
+ * @remarks
124
+ * `apiKey` must be set to your Fireworks API key, either using the argument or by setting the
125
+ * `FIREWORKS_API_KEY` environment variable.
126
+ */
127
+ static withFireworks(opts = {}) {
128
+ opts.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;
129
+ if (opts.apiKey === void 0) {
130
+ throw new Error(
131
+ "Fireworks API key is required, whether as an argument or as $FIREWORKS_API_KEY"
132
+ );
133
+ }
134
+ return new LLM({
135
+ model: "accounts/fireworks/models/llama-v3p1-70b-instruct",
136
+ baseURL: "https://api.fireworks.ai/inference/v1",
137
+ ...opts
138
+ });
139
+ }
140
+ /**
141
+ * Create a new instance of xAI LLM.
142
+ *
143
+ * @remarks
144
+ * `apiKey` must be set to your xAI API key, either using the argument or by setting the
145
+ * `XAI_API_KEY` environment variable.
146
+ */
147
+ static withXAI(opts = {}) {
148
+ opts.apiKey = opts.apiKey || process.env.XAI_API_KEY;
149
+ if (opts.apiKey === void 0) {
150
+ throw new Error("xAI API key is required, whether as an argument or as $XAI_API_KEY");
151
+ }
152
+ return new LLM({
153
+ model: "grok-2-public",
154
+ baseURL: "https://api.x.ai/v1",
155
+ ...opts
156
+ });
157
+ }
158
+ /**
159
+ * Create a new instance of Groq LLM.
160
+ *
161
+ * @remarks
162
+ * `apiKey` must be set to your Groq API key, either using the argument or by setting the
163
+ * `GROQ_API_KEY` environment variable.
164
+ */
165
+ static withGroq(opts = {}) {
166
+ opts.apiKey = opts.apiKey || process.env.GROQ_API_KEY;
167
+ if (opts.apiKey === void 0) {
168
+ throw new Error("Groq API key is required, whether as an argument or as $GROQ_API_KEY");
169
+ }
170
+ return new LLM({
171
+ model: "openai/gpt-oss-120b",
172
+ baseURL: "https://api.groq.com/openai/v1",
173
+ ...opts
174
+ });
175
+ }
176
+ /**
177
+ * Create a new instance of DeepSeek LLM.
178
+ *
179
+ * @remarks
180
+ * `apiKey` must be set to your DeepSeek API key, either using the argument or by setting the
181
+ * `DEEPSEEK_API_KEY` environment variable.
182
+ */
183
+ static withDeepSeek(opts = {}) {
184
+ opts.apiKey = opts.apiKey || process.env.DEEPSEEK_API_KEY;
185
+ if (opts.apiKey === void 0) {
186
+ throw new Error(
187
+ "DeepSeek API key is required, whether as an argument or as $DEEPSEEK_API_KEY"
188
+ );
189
+ }
190
+ return new LLM({
191
+ model: "deepseek-chat",
192
+ baseURL: "https://api.deepseek.com/v1",
193
+ ...opts
194
+ });
195
+ }
196
+ /**
197
+ * Create a new instance of OctoAI LLM.
198
+ *
199
+ * @remarks
200
+ * `apiKey` must be set to your OctoAI API key, either using the argument or by setting the
201
+ * `OCTOAI_TOKEN` environment variable.
202
+ */
203
+ static withOcto(opts = {}) {
204
+ opts.apiKey = opts.apiKey || process.env.OCTOAI_TOKEN;
205
+ if (opts.apiKey === void 0) {
206
+ throw new Error("OctoAI API key is required, whether as an argument or as $OCTOAI_TOKEN");
207
+ }
208
+ return new LLM({
209
+ model: "llama-2-13b-chat",
210
+ baseURL: "https://text.octoai.run/v1",
211
+ ...opts
212
+ });
213
+ }
214
+ /** Create a new instance of Ollama LLM. */
215
+ static withOllama(opts = {}) {
216
+ return new LLM({
217
+ model: "llama3.1",
218
+ baseURL: "http://localhost:11434/v1",
219
+ apiKey: "ollama",
220
+ ...opts
221
+ });
222
+ }
223
+ /**
224
+ * Create a new instance of PerplexityAI LLM.
225
+ *
226
+ * @remarks
227
+ * `apiKey` must be set to your PerplexityAI API key, either using the argument or by setting the
228
+ * `PERPLEXITY_API_KEY` environment variable.
229
+ */
230
+ static withPerplexity(opts = {}) {
231
+ opts.apiKey = opts.apiKey || process.env.PERPLEXITY_API_KEY;
232
+ if (opts.apiKey === void 0) {
233
+ throw new Error(
234
+ "PerplexityAI API key is required, whether as an argument or as $PERPLEXITY_API_KEY"
235
+ );
236
+ }
237
+ return new LLM({
238
+ model: "llama-3.1-sonar-small-128k-chat",
239
+ baseURL: "https://api.perplexity.ai",
240
+ ...opts
241
+ });
242
+ }
243
+ /**
244
+ * Create a new instance of TogetherAI LLM.
245
+ *
246
+ * @remarks
247
+ * `apiKey` must be set to your TogetherAI API key, either using the argument or by setting the
248
+ * `TOGETHER_API_KEY` environment variable.
249
+ */
250
+ static withTogether(opts = {}) {
251
+ opts.apiKey = opts.apiKey || process.env.TOGETHER_API_KEY;
252
+ if (opts.apiKey === void 0) {
253
+ throw new Error(
254
+ "TogetherAI API key is required, whether as an argument or as $TOGETHER_API_KEY"
255
+ );
256
+ }
257
+ return new LLM({
258
+ model: "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
259
+ baseURL: "https://api.together.xyz/v1",
260
+ ...opts
261
+ });
262
+ }
263
+ /**
264
+ * Create a new instance of Telnyx LLM.
265
+ *
266
+ * @remarks
267
+ * `apiKey` must be set to your Telnyx API key, either using the argument or by setting the
268
+ * `TELNYX_API_KEY` environment variable.
269
+ */
270
+ static withTelnyx(opts = {}) {
271
+ opts.apiKey = opts.apiKey || process.env.TELNYX_API_KEY;
272
+ if (opts.apiKey === void 0) {
273
+ throw new Error("Telnyx API key is required, whether as an argument or as $TELNYX_API_KEY");
274
+ }
275
+ return new LLM({
276
+ model: "meta-llama/Meta-Llama-3.1-70B-Instruct",
277
+ baseURL: "https://api.telnyx.com/v2/ai",
278
+ ...opts
279
+ });
280
+ }
281
+ /**
282
+ * Create a new instance of Meta Llama LLM.
283
+ *
284
+ * @remarks
285
+ * `apiKey` must be set to your Meta Llama API key, either using the argument or by setting the
286
+ * `LLAMA_API_KEY` environment variable.
287
+ */
288
+ static withMeta(opts = {}) {
289
+ opts.apiKey = opts.apiKey || process.env.LLAMA_API_KEY;
290
+ opts.baseURL = opts.baseURL || "https://api.llama.com/compat/v1/";
291
+ opts.model = opts.model || "Llama-4-Maverick-17B-128E-Instruct-FP8";
292
+ if (opts.apiKey === void 0) {
293
+ throw new Error(
294
+ "Meta Llama API key is required, either as argument or set LLAMA_API_KEY environment variable"
295
+ );
296
+ }
297
+ return new LLM(opts);
298
+ }
299
+ /**
300
+ * Create a new instance of OVHcloud AI Endpoints LLM.
301
+ *
302
+ * @remarks
303
+ * `apiKey` must be set to your OVHcloud AI Endpoints API key, either using the argument or by setting the
304
+ * `OVHCLOUD_API_KEY` environment variable.
305
+ */
306
+ static withOVHcloud(opts = {}) {
307
+ opts.apiKey = opts.apiKey || process.env.OVHCLOUD_API_KEY;
308
+ if (opts.apiKey === void 0) {
309
+ throw new Error(
310
+ "OVHcloud AI Endpoints API key is required, whether as an argument or as $OVHCLOUD_API_KEY"
311
+ );
312
+ }
313
+ return new LLM({
314
+ model: "gpt-oss-120b",
315
+ baseURL: "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1",
316
+ ...opts
317
+ });
318
+ }
319
+ chat({
320
+ chatCtx,
321
+ toolCtx: toolCtxInput,
322
+ connOptions = import_agents.DEFAULT_API_CONNECT_OPTIONS,
323
+ parallelToolCalls,
324
+ toolChoice,
325
+ extraKwargs
326
+ }) {
327
+ const toolCtx = import_agents.llm.toToolContext(toolCtxInput);
328
+ const extras = { ...extraKwargs };
329
+ if (this.#opts.metadata) {
330
+ extras.metadata = this.#opts.metadata;
331
+ }
332
+ if (this.#opts.user) {
333
+ extras.user = this.#opts.user;
334
+ }
335
+ if (this.#opts.maxCompletionTokens) {
336
+ extras.max_completion_tokens = this.#opts.maxCompletionTokens;
337
+ }
338
+ if (this.#opts.temperature) {
339
+ extras.temperature = this.#opts.temperature;
340
+ }
341
+ if (this.#opts.topP !== void 0) {
342
+ extras.top_p = this.#opts.topP;
343
+ }
344
+ if (this.#opts.serviceTier) {
345
+ extras.service_tier = this.#opts.serviceTier;
346
+ }
347
+ if (this.#opts.store !== void 0) {
348
+ extras.store = this.#opts.store;
349
+ }
350
+ if (this.#opts.reasoningEffort !== void 0) {
351
+ extras.reasoning_effort = this.#opts.reasoningEffort;
352
+ }
353
+ parallelToolCalls = parallelToolCalls !== void 0 ? parallelToolCalls : this.#opts.parallelToolCalls;
354
+ if (toolCtx && Object.keys(toolCtx.functionTools).length > 0 && parallelToolCalls !== void 0) {
355
+ extras.parallel_tool_calls = parallelToolCalls;
356
+ }
357
+ toolChoice = toolChoice !== void 0 ? toolChoice : this.#opts.toolChoice;
358
+ if (toolChoice) {
359
+ extras.tool_choice = toolChoice;
360
+ }
361
+ return new LLMStream(this, {
362
+ model: this.#opts.model,
363
+ providerFmt: this.#providerFmt,
364
+ client: this.#client,
365
+ chatCtx,
366
+ toolCtx,
367
+ connOptions,
368
+ modelOptions: extras,
369
+ strictToolSchema: this.#opts.strictToolSchema || false,
370
+ gatewayOptions: void 0
371
+ // OpenAI plugin doesn't use gateway authentication
372
+ });
373
+ }
374
+ }
375
+ class LLMStream extends import_agents.inference.LLMStream {
376
+ }
377
+ // Annotate the CommonJS export names for ESM import in node:
378
+ 0 && (module.exports = {
379
+ LLM,
380
+ LLMStream
381
+ });
382
+ //# sourceMappingURL=llm.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { APIConnectOptions } from '@livekit/agents';\nimport { DEFAULT_API_CONNECT_OPTIONS, inference, llm } from '@livekit/agents';\nimport { AzureOpenAI, OpenAI } from 'openai';\nimport type {\n CerebrasChatModels,\n ChatModels,\n DeepSeekChatModels,\n GroqChatModels,\n MetaChatModels,\n OctoChatModels,\n PerplexityChatModels,\n ReasoningEffort,\n TelnyxChatModels,\n TogetherChatModels,\n XAIChatModels,\n} from './models.js';\nimport { defaultReasoningEffort } from './models.js';\n\nexport interface LLMOptions {\n model: string | ChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n topP?: number;\n client?: OpenAI;\n toolChoice?: llm.ToolChoice;\n parallelToolCalls?: boolean;\n metadata?: Record<string, string>;\n maxCompletionTokens?: number;\n serviceTier?: string;\n store?: boolean;\n reasoningEffort?: ReasoningEffort;\n strictToolSchema?: boolean;\n}\n\nconst defaultLLMOptions: LLMOptions = {\n model: 'gpt-4.1',\n apiKey: process.env.OPENAI_API_KEY,\n parallelToolCalls: true,\n strictToolSchema: false,\n};\n\nconst defaultAzureLLMOptions: LLMOptions = {\n model: 'gpt-4.1',\n apiKey: process.env.AZURE_API_KEY,\n strictToolSchema: false,\n};\n\nexport class LLM extends llm.LLM {\n #opts: LLMOptions;\n #client: OpenAI;\n #providerFmt: llm.ProviderFormat;\n\n /**\n * Create a new instance of OpenAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the\n * `OPENAI_API_KEY` environment variable.\n */\n constructor(\n opts: Partial<LLMOptions> = defaultLLMOptions,\n providerFmt: llm.ProviderFormat = 'openai',\n ) {\n super();\n\n this.#opts = { ...defaultLLMOptions, ...opts };\n this.#opts.reasoningEffort ??= defaultReasoningEffort(this.#opts.model);\n this.#providerFmt = providerFmt;\n if (this.#opts.apiKey === undefined && !this.#opts.client) {\n throw new Error('OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY');\n }\n\n this.#client =\n this.#opts.client ||\n new OpenAI({\n baseURL: this.#opts.baseURL,\n apiKey: this.#opts.apiKey,\n });\n }\n\n label(): string {\n return 'openai.LLM';\n }\n\n get model(): string {\n return this.#opts.model;\n }\n\n get provider(): string {\n try {\n const url = new URL(this.#client.baseURL);\n return url.host;\n } catch {\n return 'api.openai.com';\n }\n }\n\n /**\n * Create a new instance of OpenAI LLM with Azure.\n *\n * @remarks\n * This automatically infers the following arguments from their corresponding environment variables if they are not provided:\n * - `apiKey` from `AZURE_OPENAI_API_KEY`\n * - `organization` from `OPENAI_ORG_ID`\n * - `project` from `OPENAI_PROJECT_ID`\n * - `azureAdToken` from `AZURE_OPENAI_AD_TOKEN`\n * - `apiVersion` from `OPENAI_API_VERSION`\n * - `azureEndpoint` from `AZURE_OPENAI_ENDPOINT`\n */\n static withAzure(\n opts: {\n model: string | ChatModels;\n azureEndpoint?: string;\n azureDeployment?: string;\n apiVersion?: string;\n apiKey?: string;\n azureAdToken?: string;\n azureAdTokenProvider?: () => Promise<string>;\n organization?: string;\n project?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n } = defaultAzureLLMOptions,\n ): LLM {\n opts = { ...defaultAzureLLMOptions, ...opts };\n if (opts.apiKey === undefined) {\n throw new Error('Azure API key is required, whether as an argument or as $AZURE_API_KEY');\n }\n\n return new LLM({\n temperature: opts.temperature,\n user: opts.user,\n client: new AzureOpenAI(opts),\n });\n }\n\n /**\n * Create a new instance of Cerebras LLM.\n *\n * @remarks\n * `apiKey` must be set to your Cerebras API key, either using the argument or by setting the\n * `CEREBRAS_API_KEY` environment variable.\n */\n static withCerebras(\n opts: Partial<{\n model: string | CerebrasChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.CEREBRAS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Cerebras API key is required, whether as an argument or as $CEREBRAS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama3.1-8b',\n baseURL: 'https://api.cerebras.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Fireworks LLM.\n *\n * @remarks\n * `apiKey` must be set to your Fireworks API key, either using the argument or by setting the\n * `FIREWORKS_API_KEY` environment variable.\n */\n static withFireworks(opts: Partial<LLMOptions> = {}): LLM {\n opts.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Fireworks API key is required, whether as an argument or as $FIREWORKS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'accounts/fireworks/models/llama-v3p1-70b-instruct',\n baseURL: 'https://api.fireworks.ai/inference/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of xAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your xAI API key, either using the argument or by setting the\n * `XAI_API_KEY` environment variable.\n */\n static withXAI(\n opts: Partial<{\n model: string | XAIChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.XAI_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('xAI API key is required, whether as an argument or as $XAI_API_KEY');\n }\n\n return new LLM({\n model: 'grok-2-public',\n baseURL: 'https://api.x.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Groq LLM.\n *\n * @remarks\n * `apiKey` must be set to your Groq API key, either using the argument or by setting the\n * `GROQ_API_KEY` environment variable.\n */\n static withGroq(\n opts: Partial<{\n model: string | GroqChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.GROQ_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Groq API key is required, whether as an argument or as $GROQ_API_KEY');\n }\n\n return new LLM({\n model: 'openai/gpt-oss-120b',\n baseURL: 'https://api.groq.com/openai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of DeepSeek LLM.\n *\n * @remarks\n * `apiKey` must be set to your DeepSeek API key, either using the argument or by setting the\n * `DEEPSEEK_API_KEY` environment variable.\n */\n static withDeepSeek(\n opts: Partial<{\n model: string | DeepSeekChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.DEEPSEEK_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'DeepSeek API key is required, whether as an argument or as $DEEPSEEK_API_KEY',\n );\n }\n\n return new LLM({\n model: 'deepseek-chat',\n baseURL: 'https://api.deepseek.com/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of OctoAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OctoAI API key, either using the argument or by setting the\n * `OCTOAI_TOKEN` environment variable.\n */\n static withOcto(\n opts: Partial<{\n model: string | OctoChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.OCTOAI_TOKEN;\n if (opts.apiKey === undefined) {\n throw new Error('OctoAI API key is required, whether as an argument or as $OCTOAI_TOKEN');\n }\n\n return new LLM({\n model: 'llama-2-13b-chat',\n baseURL: 'https://text.octoai.run/v1',\n ...opts,\n });\n }\n\n /** Create a new instance of Ollama LLM. */\n static withOllama(\n opts: Partial<{\n model: string;\n baseURL?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n return new LLM({\n model: 'llama3.1',\n baseURL: 'http://localhost:11434/v1',\n apiKey: 'ollama',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of PerplexityAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your PerplexityAI API key, either using the argument or by setting the\n * `PERPLEXITY_API_KEY` environment variable.\n */\n static withPerplexity(\n opts: Partial<{\n model: string | PerplexityChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.PERPLEXITY_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'PerplexityAI API key is required, whether as an argument or as $PERPLEXITY_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama-3.1-sonar-small-128k-chat',\n baseURL: 'https://api.perplexity.ai',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of TogetherAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your TogetherAI API key, either using the argument or by setting the\n * `TOGETHER_API_KEY` environment variable.\n */\n static withTogether(\n opts: Partial<{\n model: string | TogetherChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TOGETHER_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'TogetherAI API key is required, whether as an argument or as $TOGETHER_API_KEY',\n );\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',\n baseURL: 'https://api.together.xyz/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Telnyx LLM.\n *\n * @remarks\n * `apiKey` must be set to your Telnyx API key, either using the argument or by setting the\n * `TELNYX_API_KEY` environment variable.\n */\n static withTelnyx(\n opts: Partial<{\n model: string | TelnyxChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TELNYX_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Telnyx API key is required, whether as an argument or as $TELNYX_API_KEY');\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-70B-Instruct',\n baseURL: 'https://api.telnyx.com/v2/ai',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Meta Llama LLM.\n *\n * @remarks\n * `apiKey` must be set to your Meta Llama API key, either using the argument or by setting the\n * `LLAMA_API_KEY` environment variable.\n */\n static withMeta(\n opts: Partial<{\n apiKey?: string;\n baseURL?: string;\n client?: OpenAI;\n model?: string | MetaChatModels;\n temperature?: number;\n user?: string;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.LLAMA_API_KEY;\n opts.baseURL = opts.baseURL || 'https://api.llama.com/compat/v1/';\n opts.model = opts.model || 'Llama-4-Maverick-17B-128E-Instruct-FP8';\n\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Meta Llama API key is required, either as argument or set LLAMA_API_KEY environment variable',\n );\n }\n\n return new LLM(opts);\n }\n\n /**\n * Create a new instance of OVHcloud AI Endpoints LLM.\n *\n * @remarks\n * `apiKey` must be set to your OVHcloud AI Endpoints API key, either using the argument or by setting the\n * `OVHCLOUD_API_KEY` environment variable.\n */\n static withOVHcloud(opts: Partial<LLMOptions> = {}): LLM {\n opts.apiKey = opts.apiKey || process.env.OVHCLOUD_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'OVHcloud AI Endpoints API key is required, whether as an argument or as $OVHCLOUD_API_KEY',\n );\n }\n\n return new LLM({\n model: 'gpt-oss-120b',\n baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1',\n ...opts,\n });\n }\n\n chat({\n chatCtx,\n toolCtx: toolCtxInput,\n connOptions = DEFAULT_API_CONNECT_OPTIONS,\n parallelToolCalls,\n toolChoice,\n extraKwargs,\n }: {\n chatCtx: llm.ChatContext;\n toolCtx?: llm.ToolContextLike;\n connOptions?: APIConnectOptions;\n parallelToolCalls?: boolean;\n toolChoice?: llm.ToolChoice;\n extraKwargs?: Record<string, unknown>;\n }): LLMStream {\n const toolCtx = llm.toToolContext(toolCtxInput);\n const extras: Record<string, unknown> = { ...extraKwargs };\n\n if (this.#opts.metadata) {\n extras.metadata = this.#opts.metadata;\n }\n\n if (this.#opts.user) {\n extras.user = this.#opts.user;\n }\n\n if (this.#opts.maxCompletionTokens) {\n extras.max_completion_tokens = this.#opts.maxCompletionTokens;\n }\n\n if (this.#opts.temperature) {\n extras.temperature = this.#opts.temperature;\n }\n\n if (this.#opts.topP !== undefined) {\n extras.top_p = this.#opts.topP;\n }\n\n if (this.#opts.serviceTier) {\n extras.service_tier = this.#opts.serviceTier;\n }\n\n if (this.#opts.store !== undefined) {\n extras.store = this.#opts.store;\n }\n\n if (this.#opts.reasoningEffort !== undefined) {\n extras.reasoning_effort = this.#opts.reasoningEffort;\n }\n\n parallelToolCalls =\n parallelToolCalls !== undefined ? parallelToolCalls : this.#opts.parallelToolCalls;\n if (\n toolCtx &&\n Object.keys(toolCtx.functionTools).length > 0 &&\n parallelToolCalls !== undefined\n ) {\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 return new LLMStream(this as unknown as inference.LLM, {\n model: this.#opts.model,\n providerFmt: this.#providerFmt,\n client: this.#client as any,\n chatCtx,\n toolCtx,\n connOptions,\n modelOptions: extras,\n strictToolSchema: this.#opts.strictToolSchema || false,\n gatewayOptions: undefined, // OpenAI plugin doesn't use gateway authentication\n });\n }\n}\n\nexport class LLMStream extends inference.LLMStream {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA4D;AAC5D,oBAAoC;AAcpC,oBAAuC;AAoBvC,MAAM,oBAAgC;AAAA,EACpC,OAAO;AAAA,EACP,QAAQ,QAAQ,IAAI;AAAA,EACpB,mBAAmB;AAAA,EACnB,kBAAkB;AACpB;AAEA,MAAM,yBAAqC;AAAA,EACzC,OAAO;AAAA,EACP,QAAQ,QAAQ,IAAI;AAAA,EACpB,kBAAkB;AACpB;AAEO,MAAM,YAAY,kBAAI,IAAI;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YACE,OAA4B,mBAC5B,cAAkC,UAClC;AACA,UAAM;AAEN,SAAK,QAAQ,EAAE,GAAG,mBAAmB,GAAG,KAAK;AAC7C,SAAK,MAAM,wBAAoB,sCAAuB,KAAK,MAAM,KAAK;AACtE,SAAK,eAAe;AACpB,QAAI,KAAK,MAAM,WAAW,UAAa,CAAC,KAAK,MAAM,QAAQ;AACzD,YAAM,IAAI,MAAM,0EAA0E;AAAA,IAC5F;AAEA,SAAK,UACH,KAA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AK,MAAM,UAAU,QAAW;AAClC,aAAO,QAAQ,KAAK,MAAM;AAAA,IAC5B;AAEA,QAAI,KAAK,MAAM,oBAAoB,QAAW;AAC5C,aAAO,mBAAmB,KAAK,MAAM;AAAA,IACvC;AAEA,wBACE,sBAAsB,SAAY,oBAAoB,KAAK,MAAM;AACnE,QACE,WACA,OAAO,KAAK,QAAQ,aAAa,EAAE,SAAS,KAC5C,sBAAsB,QACtB;AACA,aAAO,sBAAsB;AAAA,IAC/B;AAEA,iBAAa,eAAe,SAAY,aAAa,KAAK,MAAM;AAChE,QAAI,YAAY;AACd,aAAO,cAAc;AAAA,IACvB;AAEA,WAAO,IAAI,UAAU,MAAkC;AAAA,MACrD,OAAO,KAAK,MAAM;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,QAAQ,KAAK;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,kBAAkB,KAAK,MAAM,oBAAoB;AAAA,MACjD,gBAAgB;AAAA;AAAA,IAClB,CAAC;AAAA,EACH;AACF;AAEO,MAAM,kBAAkB,wBAAU,UAAU;AAAC;","names":[]}
package/dist/llm.d.cts ADDED
@@ -0,0 +1,230 @@
1
+ import type { APIConnectOptions } from '@livekit/agents';
2
+ import { inference, llm } from '@livekit/agents';
3
+ import { OpenAI } from 'openai';
4
+ import type { CerebrasChatModels, ChatModels, DeepSeekChatModels, GroqChatModels, MetaChatModels, OctoChatModels, PerplexityChatModels, ReasoningEffort, TelnyxChatModels, TogetherChatModels, XAIChatModels } from './models.js';
5
+ export interface LLMOptions {
6
+ model: string | ChatModels;
7
+ apiKey?: string;
8
+ baseURL?: string;
9
+ user?: string;
10
+ temperature?: number;
11
+ topP?: number;
12
+ client?: OpenAI;
13
+ toolChoice?: llm.ToolChoice;
14
+ parallelToolCalls?: boolean;
15
+ metadata?: Record<string, string>;
16
+ maxCompletionTokens?: number;
17
+ serviceTier?: string;
18
+ store?: boolean;
19
+ reasoningEffort?: ReasoningEffort;
20
+ strictToolSchema?: boolean;
21
+ }
22
+ export declare class LLM extends llm.LLM {
23
+ #private;
24
+ /**
25
+ * Create a new instance of OpenAI LLM.
26
+ *
27
+ * @remarks
28
+ * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the
29
+ * `OPENAI_API_KEY` environment variable.
30
+ */
31
+ constructor(opts?: Partial<LLMOptions>, providerFmt?: llm.ProviderFormat);
32
+ label(): string;
33
+ get model(): string;
34
+ get provider(): string;
35
+ /**
36
+ * Create a new instance of OpenAI LLM with Azure.
37
+ *
38
+ * @remarks
39
+ * This automatically infers the following arguments from their corresponding environment variables if they are not provided:
40
+ * - `apiKey` from `AZURE_OPENAI_API_KEY`
41
+ * - `organization` from `OPENAI_ORG_ID`
42
+ * - `project` from `OPENAI_PROJECT_ID`
43
+ * - `azureAdToken` from `AZURE_OPENAI_AD_TOKEN`
44
+ * - `apiVersion` from `OPENAI_API_VERSION`
45
+ * - `azureEndpoint` from `AZURE_OPENAI_ENDPOINT`
46
+ */
47
+ static withAzure(opts?: {
48
+ model: string | ChatModels;
49
+ azureEndpoint?: string;
50
+ azureDeployment?: string;
51
+ apiVersion?: string;
52
+ apiKey?: string;
53
+ azureAdToken?: string;
54
+ azureAdTokenProvider?: () => Promise<string>;
55
+ organization?: string;
56
+ project?: string;
57
+ baseURL?: string;
58
+ user?: string;
59
+ temperature?: number;
60
+ }): LLM;
61
+ /**
62
+ * Create a new instance of Cerebras LLM.
63
+ *
64
+ * @remarks
65
+ * `apiKey` must be set to your Cerebras API key, either using the argument or by setting the
66
+ * `CEREBRAS_API_KEY` environment variable.
67
+ */
68
+ static withCerebras(opts?: Partial<{
69
+ model: string | CerebrasChatModels;
70
+ apiKey?: string;
71
+ baseURL?: string;
72
+ user?: string;
73
+ temperature?: number;
74
+ client: OpenAI;
75
+ }>): LLM;
76
+ /**
77
+ * Create a new instance of Fireworks LLM.
78
+ *
79
+ * @remarks
80
+ * `apiKey` must be set to your Fireworks API key, either using the argument or by setting the
81
+ * `FIREWORKS_API_KEY` environment variable.
82
+ */
83
+ static withFireworks(opts?: Partial<LLMOptions>): LLM;
84
+ /**
85
+ * Create a new instance of xAI LLM.
86
+ *
87
+ * @remarks
88
+ * `apiKey` must be set to your xAI API key, either using the argument or by setting the
89
+ * `XAI_API_KEY` environment variable.
90
+ */
91
+ static withXAI(opts?: Partial<{
92
+ model: string | XAIChatModels;
93
+ apiKey?: string;
94
+ baseURL?: string;
95
+ user?: string;
96
+ temperature?: number;
97
+ client: OpenAI;
98
+ }>): LLM;
99
+ /**
100
+ * Create a new instance of Groq LLM.
101
+ *
102
+ * @remarks
103
+ * `apiKey` must be set to your Groq API key, either using the argument or by setting the
104
+ * `GROQ_API_KEY` environment variable.
105
+ */
106
+ static withGroq(opts?: Partial<{
107
+ model: string | GroqChatModels;
108
+ apiKey?: string;
109
+ baseURL?: string;
110
+ user?: string;
111
+ temperature?: number;
112
+ client: OpenAI;
113
+ }>): LLM;
114
+ /**
115
+ * Create a new instance of DeepSeek LLM.
116
+ *
117
+ * @remarks
118
+ * `apiKey` must be set to your DeepSeek API key, either using the argument or by setting the
119
+ * `DEEPSEEK_API_KEY` environment variable.
120
+ */
121
+ static withDeepSeek(opts?: Partial<{
122
+ model: string | DeepSeekChatModels;
123
+ apiKey?: string;
124
+ baseURL?: string;
125
+ user?: string;
126
+ temperature?: number;
127
+ client: OpenAI;
128
+ }>): LLM;
129
+ /**
130
+ * Create a new instance of OctoAI LLM.
131
+ *
132
+ * @remarks
133
+ * `apiKey` must be set to your OctoAI API key, either using the argument or by setting the
134
+ * `OCTOAI_TOKEN` environment variable.
135
+ */
136
+ static withOcto(opts?: Partial<{
137
+ model: string | OctoChatModels;
138
+ apiKey?: string;
139
+ baseURL?: string;
140
+ user?: string;
141
+ temperature?: number;
142
+ client: OpenAI;
143
+ }>): LLM;
144
+ /** Create a new instance of Ollama LLM. */
145
+ static withOllama(opts?: Partial<{
146
+ model: string;
147
+ baseURL?: string;
148
+ temperature?: number;
149
+ client: OpenAI;
150
+ }>): LLM;
151
+ /**
152
+ * Create a new instance of PerplexityAI LLM.
153
+ *
154
+ * @remarks
155
+ * `apiKey` must be set to your PerplexityAI API key, either using the argument or by setting the
156
+ * `PERPLEXITY_API_KEY` environment variable.
157
+ */
158
+ static withPerplexity(opts?: Partial<{
159
+ model: string | PerplexityChatModels;
160
+ apiKey?: string;
161
+ baseURL?: string;
162
+ user?: string;
163
+ temperature?: number;
164
+ client: OpenAI;
165
+ }>): LLM;
166
+ /**
167
+ * Create a new instance of TogetherAI LLM.
168
+ *
169
+ * @remarks
170
+ * `apiKey` must be set to your TogetherAI API key, either using the argument or by setting the
171
+ * `TOGETHER_API_KEY` environment variable.
172
+ */
173
+ static withTogether(opts?: Partial<{
174
+ model: string | TogetherChatModels;
175
+ apiKey?: string;
176
+ baseURL?: string;
177
+ user?: string;
178
+ temperature?: number;
179
+ client: OpenAI;
180
+ }>): LLM;
181
+ /**
182
+ * Create a new instance of Telnyx LLM.
183
+ *
184
+ * @remarks
185
+ * `apiKey` must be set to your Telnyx API key, either using the argument or by setting the
186
+ * `TELNYX_API_KEY` environment variable.
187
+ */
188
+ static withTelnyx(opts?: Partial<{
189
+ model: string | TelnyxChatModels;
190
+ apiKey?: string;
191
+ baseURL?: string;
192
+ user?: string;
193
+ temperature?: number;
194
+ client: OpenAI;
195
+ }>): LLM;
196
+ /**
197
+ * Create a new instance of Meta Llama LLM.
198
+ *
199
+ * @remarks
200
+ * `apiKey` must be set to your Meta Llama API key, either using the argument or by setting the
201
+ * `LLAMA_API_KEY` environment variable.
202
+ */
203
+ static withMeta(opts?: Partial<{
204
+ apiKey?: string;
205
+ baseURL?: string;
206
+ client?: OpenAI;
207
+ model?: string | MetaChatModels;
208
+ temperature?: number;
209
+ user?: string;
210
+ }>): LLM;
211
+ /**
212
+ * Create a new instance of OVHcloud AI Endpoints LLM.
213
+ *
214
+ * @remarks
215
+ * `apiKey` must be set to your OVHcloud AI Endpoints API key, either using the argument or by setting the
216
+ * `OVHCLOUD_API_KEY` environment variable.
217
+ */
218
+ static withOVHcloud(opts?: Partial<LLMOptions>): LLM;
219
+ chat({ chatCtx, toolCtx: toolCtxInput, connOptions, parallelToolCalls, toolChoice, extraKwargs, }: {
220
+ chatCtx: llm.ChatContext;
221
+ toolCtx?: llm.ToolContextLike;
222
+ connOptions?: APIConnectOptions;
223
+ parallelToolCalls?: boolean;
224
+ toolChoice?: llm.ToolChoice;
225
+ extraKwargs?: Record<string, unknown>;
226
+ }): LLMStream;
227
+ }
228
+ export declare class LLMStream extends inference.LLMStream {
229
+ }
230
+ //# sourceMappingURL=llm.d.ts.map