ai 3.0.9 → 3.1.0-canary.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.
Files changed (33) hide show
  1. package/core/dist/index.d.mts +480 -0
  2. package/core/dist/index.d.ts +480 -0
  3. package/core/dist/index.js +1528 -0
  4. package/core/dist/index.js.map +1 -0
  5. package/core/dist/index.mjs +1479 -0
  6. package/core/dist/index.mjs.map +1 -0
  7. package/package.json +20 -3
  8. package/provider/dist/chunk-3DTRVHCT.mjs +5046 -0
  9. package/provider/dist/chunk-3DTRVHCT.mjs.map +1 -0
  10. package/provider/dist/chunk-4OUDS3CP.mjs +30 -0
  11. package/provider/dist/chunk-4OUDS3CP.mjs.map +1 -0
  12. package/provider/dist/chunk-5IYCPJBV.mjs +56 -0
  13. package/provider/dist/chunk-5IYCPJBV.mjs.map +1 -0
  14. package/provider/dist/chunk-VB2TCVQ4.mjs +6746 -0
  15. package/provider/dist/chunk-VB2TCVQ4.mjs.map +1 -0
  16. package/provider/dist/chunk-VYIXVZ6L.mjs +317 -0
  17. package/provider/dist/chunk-VYIXVZ6L.mjs.map +1 -0
  18. package/provider/dist/chunk-WTOUHN6A.mjs +2251 -0
  19. package/provider/dist/chunk-WTOUHN6A.mjs.map +1 -0
  20. package/provider/dist/client-22WAAXR7.mjs +10 -0
  21. package/provider/dist/client-22WAAXR7.mjs.map +1 -0
  22. package/provider/dist/fileFromPath-23RINPB2.mjs +115 -0
  23. package/provider/dist/fileFromPath-23RINPB2.mjs.map +1 -0
  24. package/provider/dist/index.d.mts +387 -0
  25. package/provider/dist/index.d.ts +387 -0
  26. package/provider/dist/index.js +26487 -0
  27. package/provider/dist/index.js.map +1 -0
  28. package/provider/dist/index.mjs +8087 -0
  29. package/provider/dist/index.mjs.map +1 -0
  30. package/provider/dist/lib-BZMMM4HX.mjs +20 -0
  31. package/provider/dist/lib-BZMMM4HX.mjs.map +1 -0
  32. package/provider/dist/openai-3YL4AWLI.mjs +3451 -0
  33. package/provider/dist/openai-3YL4AWLI.mjs.map +1 -0
@@ -0,0 +1,387 @@
1
+ import OpenAI from 'openai';
2
+ import MistralClient from '@mistralai/mistralai';
3
+
4
+ type LanguageModelV1CallSettings = {
5
+ /**
6
+ * Maximum number of tokens to generate.
7
+ */
8
+ maxTokens?: number;
9
+ /**
10
+ * Temperature setting. This is a number between 0 (almost no randomness) and
11
+ * 1 (very random).
12
+ *
13
+ * Different LLM providers have different temperature
14
+ * scales, so they'd need to map it (without mapping, the same temperature has
15
+ * different effects on different models). The provider can also chose to map
16
+ * this to topP, potentially even using a custom setting on their model.
17
+ *
18
+ * Note: This is an example of a setting that requires a clear specification of
19
+ * the semantics.
20
+ */
21
+ temperature?: number;
22
+ /**
23
+ * Nucleus sampling. This is a number between 0 and 1.
24
+ *
25
+ * E.g. 0.1 would mean that only tokens with the top 10% probability mass
26
+ * are considered.
27
+ *
28
+ * It is recommended to set either `temperature` or `topP`, but not both.
29
+ */
30
+ topP?: number;
31
+ /**
32
+ * Presence penalty setting. This is a number between 0 (no penalty)
33
+ * and 1 (maximum penalty). It affects the likelihood of the model to repeat
34
+ * information that is already in the prompt.
35
+ */
36
+ presencePenalty?: number;
37
+ /**
38
+ * Frequency penalty setting. This is a number between 0 (no penalty)
39
+ * and 1 (maximum penalty). It affects the likelihood of the model to repeatedly
40
+ * use the same words or phrases.
41
+ */
42
+ frequencyPenalty?: number;
43
+ /**
44
+ * The seed to use for random sampling. If set and supported by the model,
45
+ * calls will generate deterministic results.
46
+ */
47
+ seed?: number;
48
+ };
49
+
50
+ /**
51
+ * Warning from the model provider for this call. The call will proceed, but e.g.
52
+ * some settings might not be supported, which can lead to suboptimal results.
53
+ */
54
+ type LanguageModelV1CallWarning = {
55
+ type: 'unsupported-setting';
56
+ setting: keyof LanguageModelV1CallSettings;
57
+ } | {
58
+ type: 'other';
59
+ message: string;
60
+ };
61
+
62
+ type JsonSchema = Record<string, unknown>;
63
+
64
+ /**
65
+ * A tool has a name, a description, and a set of parameters.
66
+ *
67
+ * Note: this is **not** the user-facing tool definition. The AI SDK methods will
68
+ * map the user-facing tool definitions to this format.
69
+ */
70
+ type LanguageModelV1FunctionTool = {
71
+ /**
72
+ * The type of the tool. Only functions for now, but this gives us room to
73
+ * add more specific tool types in the future and use a discriminated union.
74
+ */
75
+ type: 'function';
76
+ /**
77
+ * The name of the tool. Unique within this model call.
78
+ */
79
+ name: string;
80
+ description?: string;
81
+ parameters: JsonSchema;
82
+ };
83
+
84
+ /**
85
+ * A prompt is a list of messages.
86
+ *
87
+ * Note: Not all models and prompt formats support multi-modal inputs and
88
+ * tool calls. The validation happens at runtime.
89
+ *
90
+ * Note: This is not a user-facing prompt. The AI SDK methods will map the
91
+ * user-facing prompt types such as chat or instruction prompts to this format.
92
+ */
93
+ type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
94
+ type LanguageModelV1Message = {
95
+ role: 'system';
96
+ content: string;
97
+ } | {
98
+ role: 'user';
99
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
100
+ } | {
101
+ role: 'assistant';
102
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
103
+ } | {
104
+ role: 'tool';
105
+ content: Array<LanguageModelV1ToolResultPart>;
106
+ };
107
+ interface LanguageModelV1TextPart {
108
+ type: 'text';
109
+ /**
110
+ * The text content.
111
+ */
112
+ text: string;
113
+ }
114
+ interface LanguageModelV1ImagePart {
115
+ type: 'image';
116
+ /**
117
+ * Image data as a Uint8Array.
118
+ */
119
+ image: Uint8Array;
120
+ /**
121
+ * Optional mime type of the image.
122
+ */
123
+ mimeType?: string;
124
+ }
125
+ interface LanguageModelV1ToolCallPart {
126
+ type: 'tool-call';
127
+ toolCallId: string;
128
+ toolName: string;
129
+ args: unknown;
130
+ }
131
+ interface LanguageModelV1ToolResultPart {
132
+ type: 'tool-result';
133
+ toolCallId: string;
134
+ toolName: string;
135
+ result: unknown;
136
+ }
137
+
138
+ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
139
+ /**
140
+ * Whether the user provided the input as messages or as
141
+ * a prompt. This can help guide non-chat models in the
142
+ * expansion, bc different expansions can be needed for
143
+ * chat/non-chat use cases.
144
+ */
145
+ inputFormat: 'messages' | 'prompt';
146
+ /**
147
+ * The mode affects the behavior of the language model. It is required to
148
+ * support provider-independent streaming and generation of structured objects.
149
+ * The model can take this information and e.g. configure json mode, the correct
150
+ * low level grammar, etc. It can also be used to optimize the efficiency of the
151
+ * streaming, e.g. tool-delta stream parts are only needed in the
152
+ * object-tool mode.
153
+ */
154
+ mode: {
155
+ type: 'regular';
156
+ tools?: Array<LanguageModelV1FunctionTool>;
157
+ } | {
158
+ type: 'object-json';
159
+ } | {
160
+ type: 'object-grammar';
161
+ schema: JsonSchema;
162
+ } | {
163
+ type: 'object-tool';
164
+ tool: LanguageModelV1FunctionTool;
165
+ };
166
+ /**
167
+ * A language mode prompt is a standardized prompt type.
168
+ *
169
+ * Note: This is **not** the user-facing prompt. The AI SDK methods will map the
170
+ * user-facing prompt types such as chat or instruction prompts to this format.
171
+ * That approach allows us to evolve the user facing prompts without breaking
172
+ * the language model interface.
173
+ */
174
+ prompt: LanguageModelV1Prompt;
175
+ };
176
+
177
+ interface LanguageModel {
178
+ /**
179
+ * Default object generation mode that should be used with this model when
180
+ * no mode is specified. Should be the mode with the best results for this
181
+ * model. `undefined` can be returned if object generation is not supported.
182
+ *
183
+ * This is needed to generate the best objects possible w/o requiring the
184
+ * user to explicitly specify the object generation mode.
185
+ */
186
+ readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
187
+ doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
188
+ text?: string;
189
+ toolCalls?: Array<LanguageModelToolCall>;
190
+ warnings: LanguageModelV1CallWarning[];
191
+ }>;
192
+ doStream(options: LanguageModelV1CallOptions): PromiseLike<{
193
+ stream: ReadableStream<LanguageModelStreamPart>;
194
+ warnings: LanguageModelV1CallWarning[];
195
+ }>;
196
+ }
197
+ type ErrorStreamPart = {
198
+ type: 'error';
199
+ error: unknown;
200
+ };
201
+ type LanguageModelToolCall = {
202
+ toolCallId: string;
203
+ toolName: string;
204
+ args: string;
205
+ };
206
+ type ToolCallStreamPart = {
207
+ type: 'tool-call';
208
+ } & LanguageModelToolCall;
209
+ type ToolCallDeltaStreamPart = {
210
+ type: 'tool-call-delta';
211
+ toolCallId: string;
212
+ toolName: string;
213
+ argsTextDelta: string;
214
+ };
215
+ type TextDeltaStreamPart = {
216
+ type: 'text-delta';
217
+ textDelta: string;
218
+ };
219
+ type LanguageModelStreamPart = TextDeltaStreamPart | ToolCallDeltaStreamPart | ToolCallStreamPart | ErrorStreamPart;
220
+
221
+ declare class OpenAIChatLanguageModel<SETTINGS> implements LanguageModel {
222
+ readonly settings: SETTINGS;
223
+ readonly defaultObjectGenerationMode = "tool";
224
+ private readonly getClient;
225
+ private readonly mapSettings;
226
+ constructor(settings: SETTINGS, config: {
227
+ client: () => Promise<OpenAI>;
228
+ mapSettings: (settings: SETTINGS) => Record<string, unknown> & {
229
+ model: string;
230
+ };
231
+ });
232
+ private get basePrompt();
233
+ private getArgs;
234
+ doGenerate(options: Parameters<LanguageModel['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModel['doGenerate']>>>;
235
+ doStream(options: Parameters<LanguageModel['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModel['doStream']>>>;
236
+ }
237
+
238
+ type FireworksChatModelId = `accounts/${string}/models/${string}`;
239
+ /**
240
+ * @see https://readme.fireworks.ai/reference/createchatcompletion
241
+ */
242
+ interface FireworksChatSettings {
243
+ /**
244
+ * The ID of the model to use.
245
+ */
246
+ id: FireworksChatModelId;
247
+ /**
248
+ * The size to which to truncate chat prompts. Earlier user/assistant messages will be
249
+ * evicted to fit the prompt into this length.
250
+ *
251
+ * This should usually be set to a number << the max context size of the model, to allow
252
+ * enough remaining tokens for generating a response.
253
+ *
254
+ * If omitted, you may receive "prompt too long" errors in your responses as
255
+ * conversations grow. Note that even with this set, you may still receive "prompt too long"
256
+ * errors if individual messages are too long for the model context window.
257
+ */
258
+ promptTruncateLength?: number;
259
+ /**
260
+ * Top-k sampling is another sampling method where the k most probable next tokens are filtered
261
+ * and the probability mass is redistributed among only those k next tokens. The value of k
262
+ * controls the number of candidates for the next token at each step during text generation.
263
+ */
264
+ topK?: number;
265
+ /**
266
+ * What to do if the token count of prompt plus max_tokens exceeds the model's context window.
267
+ *
268
+ * Passing truncate limits the max_tokens to at most context_window_length - prompt_length.
269
+ * This is the default.
270
+ *
271
+ * Passing error would trigger a request error.
272
+ *
273
+ * The default of 'truncate' is selected as it allows to ask for high max_tokens value while
274
+ * respecting the context window length without having to do client-side prompt tokenization.
275
+ *
276
+ * Note, that it differs from OpenAI's behavior that matches that of error.
277
+ */
278
+ contextLengthExceededBehavior?: 'truncate' | 'error';
279
+ }
280
+
281
+ declare function chat$3(settings: Omit<FireworksChatSettings, 'client'> & {
282
+ client?: OpenAI;
283
+ apiKey?: string;
284
+ }): OpenAIChatLanguageModel<{
285
+ id: `accounts/${string}/models/${string}`;
286
+ promptTruncateLength?: number | undefined;
287
+ topK?: number | undefined;
288
+ contextLengthExceededBehavior?: "error" | "truncate" | undefined;
289
+ }>;
290
+
291
+ declare namespace fireworksFacade {
292
+ export {
293
+ chat$3 as chat,
294
+ };
295
+ }
296
+
297
+ type MistralChatModelId = 'open-mistral-7b' | 'open-mixtral-8x7b' | 'mistral-small-latest' | 'mistral-medium-latest' | 'mistral-large-latest' | (string & {});
298
+ interface MistralChatSettings {
299
+ /**
300
+ * The ID of the model to use.
301
+ */
302
+ id: MistralChatModelId;
303
+ /**
304
+ * Whether to inject a safety prompt before all conversations.
305
+ *
306
+ * Default: false
307
+ */
308
+ safePrompt?: boolean;
309
+ }
310
+
311
+ declare class MistralChatLanguageModel implements LanguageModel {
312
+ readonly settings: MistralChatSettings;
313
+ readonly defaultObjectGenerationMode = "json";
314
+ private readonly getClient;
315
+ constructor(settings: MistralChatSettings, config: {
316
+ client: () => Promise<MistralClient>;
317
+ });
318
+ private get basePrompt();
319
+ private getArgs;
320
+ doGenerate(options: Parameters<LanguageModel['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModel['doGenerate']>>>;
321
+ doStream(options: Parameters<LanguageModel['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModel['doStream']>>>;
322
+ }
323
+
324
+ declare function chat$2(settings: Omit<MistralChatSettings, 'client'> & {
325
+ client?: MistralClient;
326
+ apiKey?: string;
327
+ }): MistralChatLanguageModel;
328
+
329
+ declare namespace mistralFacade {
330
+ export {
331
+ chat$2 as chat,
332
+ };
333
+ }
334
+
335
+ type OpenAIChatModelId = 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-4-vision-preview' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | (string & {});
336
+ interface OpenAIChatSettings {
337
+ /**
338
+ * The ID of the model to use.
339
+ */
340
+ id: OpenAIChatModelId;
341
+ logitBias?: Record<number, number>;
342
+ }
343
+
344
+ declare function chat$1(settings: OpenAIChatSettings & {
345
+ client?: OpenAI;
346
+ apiKey?: string;
347
+ }): OpenAIChatLanguageModel<OpenAIChatSettings>;
348
+
349
+ declare namespace openaiFacade {
350
+ export {
351
+ chat$1 as chat,
352
+ };
353
+ }
354
+
355
+ type PerplexityChatModelId = 'sonar-small-chat' | 'sonar-small-online' | 'sonar-medium-chat' | 'sonar-medium-online' | 'mistral-7b-instruct' | 'mixtral-8x7b-instruct' | (string & {});
356
+ /**
357
+ * @see https://docs.perplexity.ai/reference/post_chat_completions
358
+ */
359
+ interface PerplexityChatSettings {
360
+ /**
361
+ * The ID of the model to use.
362
+ */
363
+ id: PerplexityChatModelId;
364
+ /**
365
+ * The number of tokens to keep for highest top-k filtering, specified as an
366
+ * integer between 0 and 2048 inclusive. If set to 0, top-k filtering is disabled.
367
+ * We recommend either altering top_k or top_p, but not both.
368
+ */
369
+ topK?: number;
370
+ }
371
+
372
+ declare function chat(settings: PerplexityChatSettings & {
373
+ client?: OpenAI;
374
+ apiKey?: string;
375
+ }): OpenAIChatLanguageModel<{
376
+ id: PerplexityChatModelId;
377
+ topK?: number | undefined;
378
+ }>;
379
+
380
+ declare const perplexityFacade_chat: typeof chat;
381
+ declare namespace perplexityFacade {
382
+ export {
383
+ perplexityFacade_chat as chat,
384
+ };
385
+ }
386
+
387
+ export { fireworksFacade as fireworks, mistralFacade as mistral, openaiFacade as openai, perplexityFacade as perplexity };