@ai-sdk/provider 0.0.0-85f9a635-20240518005312
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/LICENSE +13 -0
- package/README.md +1 -0
- package/dist/index.d.mts +803 -0
- package/dist/index.d.ts +803 -0
- package/dist/index.js +509 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +466 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.d.mts
ADDED
@@ -0,0 +1,803 @@
|
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
2
|
+
|
3
|
+
/**
|
4
|
+
An embedding is a vector, i.e. an array of numbers.
|
5
|
+
It is e.g. used to represent a text as a vector of word embeddings.
|
6
|
+
*/
|
7
|
+
type EmbeddingModelV1Embedding = Array<number>;
|
8
|
+
|
9
|
+
/**
|
10
|
+
Experimental: Specification for an embedding model that implements the embedding model
|
11
|
+
interface version 1.
|
12
|
+
|
13
|
+
VALUE is the type of the values that the model can embed.
|
14
|
+
This will allow us to go beyond text embeddings in the future,
|
15
|
+
e.g. to support image embeddings
|
16
|
+
*/
|
17
|
+
type EmbeddingModelV1<VALUE> = {
|
18
|
+
/**
|
19
|
+
The embedding model must specify which embedding model interface
|
20
|
+
version it implements. This will allow us to evolve the embedding
|
21
|
+
model interface and retain backwards compatibility. The different
|
22
|
+
implementation versions can be handled as a discriminated union
|
23
|
+
on our side.
|
24
|
+
*/
|
25
|
+
readonly specificationVersion: 'v1';
|
26
|
+
/**
|
27
|
+
Name of the provider for logging purposes.
|
28
|
+
*/
|
29
|
+
readonly provider: string;
|
30
|
+
/**
|
31
|
+
Provider-specific model ID for logging purposes.
|
32
|
+
*/
|
33
|
+
readonly modelId: string;
|
34
|
+
/**
|
35
|
+
Limit of how many embeddings can be generated in a single API call.
|
36
|
+
*/
|
37
|
+
readonly maxEmbeddingsPerCall: number | undefined;
|
38
|
+
/**
|
39
|
+
True if the model can handle multiple embedding calls in parallel.
|
40
|
+
*/
|
41
|
+
readonly supportsParallelCalls: boolean;
|
42
|
+
/**
|
43
|
+
Generates a list of embeddings for the given input text.
|
44
|
+
|
45
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
46
|
+
by the user.
|
47
|
+
*/
|
48
|
+
doEmbed(options: {
|
49
|
+
/**
|
50
|
+
List of values to embed.
|
51
|
+
*/
|
52
|
+
values: Array<VALUE>;
|
53
|
+
/**
|
54
|
+
Abort signal for cancelling the operation.
|
55
|
+
*/
|
56
|
+
abortSignal?: AbortSignal;
|
57
|
+
}): PromiseLike<{
|
58
|
+
/**
|
59
|
+
Generated embeddings. They are in the same order as the input values.
|
60
|
+
*/
|
61
|
+
embeddings: Array<EmbeddingModelV1Embedding>;
|
62
|
+
/**
|
63
|
+
Optional raw response information for debugging purposes.
|
64
|
+
*/
|
65
|
+
rawResponse?: {
|
66
|
+
/**
|
67
|
+
Response headers.
|
68
|
+
*/
|
69
|
+
headers?: Record<string, string>;
|
70
|
+
};
|
71
|
+
}>;
|
72
|
+
};
|
73
|
+
|
74
|
+
declare class APICallError extends Error {
|
75
|
+
readonly url: string;
|
76
|
+
readonly requestBodyValues: unknown;
|
77
|
+
readonly statusCode?: number;
|
78
|
+
readonly responseHeaders?: Record<string, string>;
|
79
|
+
readonly responseBody?: string;
|
80
|
+
readonly cause?: unknown;
|
81
|
+
readonly isRetryable: boolean;
|
82
|
+
readonly data?: unknown;
|
83
|
+
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable, // server error
|
84
|
+
data, }: {
|
85
|
+
message: string;
|
86
|
+
url: string;
|
87
|
+
requestBodyValues: unknown;
|
88
|
+
statusCode?: number;
|
89
|
+
responseHeaders?: Record<string, string>;
|
90
|
+
responseBody?: string;
|
91
|
+
cause?: unknown;
|
92
|
+
isRetryable?: boolean;
|
93
|
+
data?: unknown;
|
94
|
+
});
|
95
|
+
static isAPICallError(error: unknown): error is APICallError;
|
96
|
+
toJSON(): {
|
97
|
+
name: string;
|
98
|
+
message: string;
|
99
|
+
url: string;
|
100
|
+
requestBodyValues: unknown;
|
101
|
+
statusCode: number | undefined;
|
102
|
+
responseHeaders: Record<string, string> | undefined;
|
103
|
+
responseBody: string | undefined;
|
104
|
+
cause: unknown;
|
105
|
+
isRetryable: boolean;
|
106
|
+
data: unknown;
|
107
|
+
};
|
108
|
+
}
|
109
|
+
|
110
|
+
declare class EmptyResponseBodyError extends Error {
|
111
|
+
constructor({ message }?: {
|
112
|
+
message?: string;
|
113
|
+
});
|
114
|
+
static isEmptyResponseBodyError(error: unknown): error is EmptyResponseBodyError;
|
115
|
+
toJSON(): {
|
116
|
+
name: string;
|
117
|
+
message: string;
|
118
|
+
stack: string | undefined;
|
119
|
+
};
|
120
|
+
}
|
121
|
+
|
122
|
+
declare class InvalidArgumentError extends Error {
|
123
|
+
readonly parameter: string;
|
124
|
+
readonly value: unknown;
|
125
|
+
constructor({ parameter, value, message, }: {
|
126
|
+
parameter: string;
|
127
|
+
value: unknown;
|
128
|
+
message: string;
|
129
|
+
});
|
130
|
+
static isInvalidArgumentError(error: unknown): error is InvalidArgumentError;
|
131
|
+
toJSON(): {
|
132
|
+
name: string;
|
133
|
+
message: string;
|
134
|
+
stack: string | undefined;
|
135
|
+
parameter: string;
|
136
|
+
value: unknown;
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
declare class InvalidDataContentError extends Error {
|
141
|
+
readonly content: unknown;
|
142
|
+
readonly cause?: unknown;
|
143
|
+
constructor({ content, cause, message, }: {
|
144
|
+
content: unknown;
|
145
|
+
cause?: unknown;
|
146
|
+
message?: string;
|
147
|
+
});
|
148
|
+
static isInvalidDataContentError(error: unknown): error is InvalidDataContentError;
|
149
|
+
toJSON(): {
|
150
|
+
name: string;
|
151
|
+
message: string;
|
152
|
+
stack: string | undefined;
|
153
|
+
cause: unknown;
|
154
|
+
content: unknown;
|
155
|
+
};
|
156
|
+
}
|
157
|
+
|
158
|
+
declare class InvalidPromptError extends Error {
|
159
|
+
readonly prompt: unknown;
|
160
|
+
constructor({ prompt, message }: {
|
161
|
+
prompt: unknown;
|
162
|
+
message: string;
|
163
|
+
});
|
164
|
+
static isInvalidPromptError(error: unknown): error is InvalidPromptError;
|
165
|
+
toJSON(): {
|
166
|
+
name: string;
|
167
|
+
message: string;
|
168
|
+
stack: string | undefined;
|
169
|
+
prompt: unknown;
|
170
|
+
};
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
Server returned a response with invalid data content. This should be thrown by providers when they
|
175
|
+
cannot parse the response from the API.
|
176
|
+
*/
|
177
|
+
declare class InvalidResponseDataError extends Error {
|
178
|
+
readonly data: unknown;
|
179
|
+
constructor({ data, message, }: {
|
180
|
+
data: unknown;
|
181
|
+
message?: string;
|
182
|
+
});
|
183
|
+
static isInvalidResponseDataError(error: unknown): error is InvalidResponseDataError;
|
184
|
+
toJSON(): {
|
185
|
+
name: string;
|
186
|
+
message: string;
|
187
|
+
stack: string | undefined;
|
188
|
+
data: unknown;
|
189
|
+
};
|
190
|
+
}
|
191
|
+
|
192
|
+
declare class InvalidToolArgumentsError extends Error {
|
193
|
+
readonly toolName: string;
|
194
|
+
readonly toolArgs: string;
|
195
|
+
readonly cause: unknown;
|
196
|
+
constructor({ toolArgs, toolName, cause, message, }: {
|
197
|
+
message?: string;
|
198
|
+
toolArgs: string;
|
199
|
+
toolName: string;
|
200
|
+
cause: unknown;
|
201
|
+
});
|
202
|
+
static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
|
203
|
+
toJSON(): {
|
204
|
+
name: string;
|
205
|
+
message: string;
|
206
|
+
cause: unknown;
|
207
|
+
stack: string | undefined;
|
208
|
+
toolName: string;
|
209
|
+
toolArgs: string;
|
210
|
+
};
|
211
|
+
}
|
212
|
+
|
213
|
+
declare class JSONParseError extends Error {
|
214
|
+
readonly text: string;
|
215
|
+
readonly cause: unknown;
|
216
|
+
constructor({ text, cause }: {
|
217
|
+
text: string;
|
218
|
+
cause: unknown;
|
219
|
+
});
|
220
|
+
static isJSONParseError(error: unknown): error is JSONParseError;
|
221
|
+
toJSON(): {
|
222
|
+
name: string;
|
223
|
+
message: string;
|
224
|
+
cause: unknown;
|
225
|
+
stack: string | undefined;
|
226
|
+
valueText: string;
|
227
|
+
};
|
228
|
+
}
|
229
|
+
|
230
|
+
declare class LoadAPIKeyError extends Error {
|
231
|
+
constructor({ message }: {
|
232
|
+
message: string;
|
233
|
+
});
|
234
|
+
static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError;
|
235
|
+
toJSON(): {
|
236
|
+
name: string;
|
237
|
+
message: string;
|
238
|
+
};
|
239
|
+
}
|
240
|
+
|
241
|
+
declare class NoObjectGeneratedError extends Error {
|
242
|
+
readonly cause: unknown;
|
243
|
+
constructor();
|
244
|
+
static isNoTextGeneratedError(error: unknown): error is NoObjectGeneratedError;
|
245
|
+
toJSON(): {
|
246
|
+
name: string;
|
247
|
+
cause: unknown;
|
248
|
+
message: string;
|
249
|
+
stack: string | undefined;
|
250
|
+
};
|
251
|
+
}
|
252
|
+
|
253
|
+
declare class NoSuchToolError extends Error {
|
254
|
+
readonly toolName: string;
|
255
|
+
readonly availableTools: string[] | undefined;
|
256
|
+
constructor({ toolName, availableTools, message, }: {
|
257
|
+
toolName: string;
|
258
|
+
availableTools?: string[] | undefined;
|
259
|
+
message?: string;
|
260
|
+
});
|
261
|
+
static isNoSuchToolError(error: unknown): error is NoSuchToolError;
|
262
|
+
toJSON(): {
|
263
|
+
name: string;
|
264
|
+
message: string;
|
265
|
+
stack: string | undefined;
|
266
|
+
toolName: string;
|
267
|
+
availableTools: string[] | undefined;
|
268
|
+
};
|
269
|
+
}
|
270
|
+
|
271
|
+
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
272
|
+
declare class RetryError extends Error {
|
273
|
+
readonly reason: RetryErrorReason;
|
274
|
+
readonly lastError: unknown;
|
275
|
+
readonly errors: Array<unknown>;
|
276
|
+
constructor({ message, reason, errors, }: {
|
277
|
+
message: string;
|
278
|
+
reason: RetryErrorReason;
|
279
|
+
errors: Array<unknown>;
|
280
|
+
});
|
281
|
+
static isRetryError(error: unknown): error is RetryError;
|
282
|
+
toJSON(): {
|
283
|
+
name: string;
|
284
|
+
message: string;
|
285
|
+
reason: RetryErrorReason;
|
286
|
+
lastError: unknown;
|
287
|
+
errors: unknown[];
|
288
|
+
};
|
289
|
+
}
|
290
|
+
|
291
|
+
declare class TooManyEmbeddingValuesForCallError extends Error {
|
292
|
+
readonly provider: string;
|
293
|
+
readonly modelId: string;
|
294
|
+
readonly maxEmbeddingsPerCall: number;
|
295
|
+
readonly values: Array<unknown>;
|
296
|
+
constructor(options: {
|
297
|
+
provider: string;
|
298
|
+
modelId: string;
|
299
|
+
maxEmbeddingsPerCall: number;
|
300
|
+
values: Array<unknown>;
|
301
|
+
});
|
302
|
+
static isInvalidPromptError(error: unknown): error is TooManyEmbeddingValuesForCallError;
|
303
|
+
toJSON(): {
|
304
|
+
name: string;
|
305
|
+
message: string;
|
306
|
+
stack: string | undefined;
|
307
|
+
provider: string;
|
308
|
+
modelId: string;
|
309
|
+
maxEmbeddingsPerCall: number;
|
310
|
+
values: unknown[];
|
311
|
+
};
|
312
|
+
}
|
313
|
+
|
314
|
+
/**
|
315
|
+
A tool has a name, a description, and a set of parameters.
|
316
|
+
|
317
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
318
|
+
map the user-facing tool definitions to this format.
|
319
|
+
*/
|
320
|
+
type LanguageModelV1FunctionTool = {
|
321
|
+
/**
|
322
|
+
The type of the tool. Only functions for now, but this gives us room to
|
323
|
+
add more specific tool types in the future and use a discriminated union.
|
324
|
+
*/
|
325
|
+
type: 'function';
|
326
|
+
/**
|
327
|
+
The name of the tool. Unique within this model call.
|
328
|
+
*/
|
329
|
+
name: string;
|
330
|
+
/**
|
331
|
+
A description of the tool. The language model uses this to understand the
|
332
|
+
tool's purpose and to provide better completion suggestions.
|
333
|
+
*/
|
334
|
+
description?: string;
|
335
|
+
/**
|
336
|
+
The parameters that the tool expects. The language model uses this to
|
337
|
+
understand the tool's input requirements and to provide matching suggestions.
|
338
|
+
*/
|
339
|
+
parameters: JSONSchema7;
|
340
|
+
};
|
341
|
+
|
342
|
+
declare class ToolCallParseError extends Error {
|
343
|
+
readonly cause: unknown;
|
344
|
+
readonly text: string;
|
345
|
+
readonly tools: LanguageModelV1FunctionTool[];
|
346
|
+
constructor({ cause, text, tools, message, }: {
|
347
|
+
cause: unknown;
|
348
|
+
text: string;
|
349
|
+
tools: LanguageModelV1FunctionTool[];
|
350
|
+
message?: string;
|
351
|
+
});
|
352
|
+
static isToolCallParseError(error: unknown): error is ToolCallParseError;
|
353
|
+
toJSON(): {
|
354
|
+
name: string;
|
355
|
+
message: string;
|
356
|
+
stack: string | undefined;
|
357
|
+
cause: unknown;
|
358
|
+
text: string;
|
359
|
+
tools: LanguageModelV1FunctionTool[];
|
360
|
+
};
|
361
|
+
}
|
362
|
+
|
363
|
+
declare class TypeValidationError extends Error {
|
364
|
+
readonly value: unknown;
|
365
|
+
readonly cause: unknown;
|
366
|
+
constructor({ value, cause }: {
|
367
|
+
value: unknown;
|
368
|
+
cause: unknown;
|
369
|
+
});
|
370
|
+
static isTypeValidationError(error: unknown): error is TypeValidationError;
|
371
|
+
toJSON(): {
|
372
|
+
name: string;
|
373
|
+
message: string;
|
374
|
+
cause: unknown;
|
375
|
+
stack: string | undefined;
|
376
|
+
value: unknown;
|
377
|
+
};
|
378
|
+
}
|
379
|
+
|
380
|
+
declare class UnsupportedFunctionalityError extends Error {
|
381
|
+
readonly functionality: string;
|
382
|
+
constructor({ functionality }: {
|
383
|
+
functionality: string;
|
384
|
+
});
|
385
|
+
static isUnsupportedFunctionalityError(error: unknown): error is UnsupportedFunctionalityError;
|
386
|
+
toJSON(): {
|
387
|
+
name: string;
|
388
|
+
message: string;
|
389
|
+
stack: string | undefined;
|
390
|
+
functionality: string;
|
391
|
+
};
|
392
|
+
}
|
393
|
+
|
394
|
+
declare class UnsupportedJSONSchemaError extends Error {
|
395
|
+
readonly reason: string;
|
396
|
+
readonly schema: unknown;
|
397
|
+
constructor({ schema, reason, message, }: {
|
398
|
+
schema: unknown;
|
399
|
+
reason: string;
|
400
|
+
message?: string;
|
401
|
+
});
|
402
|
+
static isUnsupportedJSONSchemaError(error: unknown): error is UnsupportedJSONSchemaError;
|
403
|
+
toJSON(): {
|
404
|
+
name: string;
|
405
|
+
message: string;
|
406
|
+
stack: string | undefined;
|
407
|
+
reason: string;
|
408
|
+
schema: unknown;
|
409
|
+
};
|
410
|
+
}
|
411
|
+
|
412
|
+
type LanguageModelV1CallSettings = {
|
413
|
+
/**
|
414
|
+
Maximum number of tokens to generate.
|
415
|
+
*/
|
416
|
+
maxTokens?: number;
|
417
|
+
/**
|
418
|
+
Temperature setting.
|
419
|
+
|
420
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
421
|
+
*/
|
422
|
+
temperature?: number;
|
423
|
+
/**
|
424
|
+
Nucleus sampling.
|
425
|
+
|
426
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
427
|
+
*/
|
428
|
+
topP?: number;
|
429
|
+
/**
|
430
|
+
Presence penalty setting. It affects the likelihood of the model to
|
431
|
+
repeat information that is already in the prompt.
|
432
|
+
*/
|
433
|
+
presencePenalty?: number;
|
434
|
+
/**
|
435
|
+
Frequency penalty setting. It affects the likelihood of the model
|
436
|
+
to repeatedly use the same words or phrases.
|
437
|
+
*/
|
438
|
+
frequencyPenalty?: number;
|
439
|
+
/**
|
440
|
+
The seed (integer) to use for random sampling. If set and supported
|
441
|
+
by the model, calls will generate deterministic results.
|
442
|
+
*/
|
443
|
+
seed?: number;
|
444
|
+
/**
|
445
|
+
Abort signal for cancelling the operation.
|
446
|
+
*/
|
447
|
+
abortSignal?: AbortSignal;
|
448
|
+
};
|
449
|
+
|
450
|
+
/**
|
451
|
+
A prompt is a list of messages.
|
452
|
+
|
453
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
454
|
+
tool calls. The validation happens at runtime.
|
455
|
+
|
456
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
457
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
458
|
+
*/
|
459
|
+
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
460
|
+
type LanguageModelV1Message = {
|
461
|
+
role: 'system';
|
462
|
+
content: string;
|
463
|
+
} | {
|
464
|
+
role: 'user';
|
465
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
|
466
|
+
} | {
|
467
|
+
role: 'assistant';
|
468
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
|
469
|
+
} | {
|
470
|
+
role: 'tool';
|
471
|
+
content: Array<LanguageModelV1ToolResultPart>;
|
472
|
+
};
|
473
|
+
/**
|
474
|
+
Text content part of a prompt. It contains a string of text.
|
475
|
+
*/
|
476
|
+
interface LanguageModelV1TextPart {
|
477
|
+
type: 'text';
|
478
|
+
/**
|
479
|
+
The text content.
|
480
|
+
*/
|
481
|
+
text: string;
|
482
|
+
}
|
483
|
+
/**
|
484
|
+
Image content part of a prompt. It contains an image.
|
485
|
+
*/
|
486
|
+
interface LanguageModelV1ImagePart {
|
487
|
+
type: 'image';
|
488
|
+
/**
|
489
|
+
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
490
|
+
*/
|
491
|
+
image: Uint8Array | URL;
|
492
|
+
/**
|
493
|
+
Optional mime type of the image.
|
494
|
+
*/
|
495
|
+
mimeType?: string;
|
496
|
+
}
|
497
|
+
/**
|
498
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
499
|
+
*/
|
500
|
+
interface LanguageModelV1ToolCallPart {
|
501
|
+
type: 'tool-call';
|
502
|
+
/**
|
503
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
504
|
+
*/
|
505
|
+
toolCallId: string;
|
506
|
+
/**
|
507
|
+
Name of the tool that is being called.
|
508
|
+
*/
|
509
|
+
toolName: string;
|
510
|
+
/**
|
511
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
512
|
+
*/
|
513
|
+
args: unknown;
|
514
|
+
}
|
515
|
+
/**
|
516
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
517
|
+
*/
|
518
|
+
interface LanguageModelV1ToolResultPart {
|
519
|
+
type: 'tool-result';
|
520
|
+
/**
|
521
|
+
ID of the tool call that this result is associated with.
|
522
|
+
*/
|
523
|
+
toolCallId: string;
|
524
|
+
/**
|
525
|
+
Name of the tool that generated this result.
|
526
|
+
*/
|
527
|
+
toolName: string;
|
528
|
+
/**
|
529
|
+
Result of the tool call. This is a JSON-serializable object.
|
530
|
+
*/
|
531
|
+
result: unknown;
|
532
|
+
/**
|
533
|
+
Optional flag if the result is an error or an error message.
|
534
|
+
*/
|
535
|
+
isError?: boolean;
|
536
|
+
}
|
537
|
+
|
538
|
+
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
539
|
+
/**
|
540
|
+
Whether the user provided the input as messages or as
|
541
|
+
a prompt. This can help guide non-chat models in the
|
542
|
+
expansion, bc different expansions can be needed for
|
543
|
+
chat/non-chat use cases.
|
544
|
+
*/
|
545
|
+
inputFormat: 'messages' | 'prompt';
|
546
|
+
/**
|
547
|
+
The mode affects the behavior of the language model. It is required to
|
548
|
+
support provider-independent streaming and generation of structured objects.
|
549
|
+
The model can take this information and e.g. configure json mode, the correct
|
550
|
+
low level grammar, etc. It can also be used to optimize the efficiency of the
|
551
|
+
streaming, e.g. tool-delta stream parts are only needed in the
|
552
|
+
object-tool mode.
|
553
|
+
*/
|
554
|
+
mode: {
|
555
|
+
type: 'regular';
|
556
|
+
tools?: Array<LanguageModelV1FunctionTool>;
|
557
|
+
} | {
|
558
|
+
type: 'object-json';
|
559
|
+
} | {
|
560
|
+
type: 'object-grammar';
|
561
|
+
schema: JSONSchema7;
|
562
|
+
} | {
|
563
|
+
type: 'object-tool';
|
564
|
+
tool: LanguageModelV1FunctionTool;
|
565
|
+
};
|
566
|
+
/**
|
567
|
+
A language mode prompt is a standardized prompt type.
|
568
|
+
|
569
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
570
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
571
|
+
That approach allows us to evolve the user facing prompts without breaking
|
572
|
+
the language model interface.
|
573
|
+
*/
|
574
|
+
prompt: LanguageModelV1Prompt;
|
575
|
+
};
|
576
|
+
|
577
|
+
/**
|
578
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
579
|
+
some settings might not be supported, which can lead to suboptimal results.
|
580
|
+
*/
|
581
|
+
type LanguageModelV1CallWarning = {
|
582
|
+
type: 'unsupported-setting';
|
583
|
+
setting: keyof LanguageModelV1CallSettings;
|
584
|
+
} | {
|
585
|
+
type: 'other';
|
586
|
+
message: string;
|
587
|
+
};
|
588
|
+
|
589
|
+
/**
|
590
|
+
Reason why a language model finished generating a response.
|
591
|
+
|
592
|
+
Can be one of the following:
|
593
|
+
- `stop`: model generated stop sequence
|
594
|
+
- `length`: model generated maximum number of tokens
|
595
|
+
- `content-filter`: content filter violation stopped the model
|
596
|
+
- `tool-calls`: model triggered tool calls
|
597
|
+
- `error`: model stopped because of an error
|
598
|
+
- `other`: model stopped for other reasons
|
599
|
+
*/
|
600
|
+
type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
|
601
|
+
|
602
|
+
type LanguageModelV1FunctionToolCall = {
|
603
|
+
toolCallType: 'function';
|
604
|
+
toolCallId: string;
|
605
|
+
toolName: string;
|
606
|
+
/**
|
607
|
+
Stringified JSON object with the tool call arguments. Must match the
|
608
|
+
parameters schema of the tool.
|
609
|
+
*/
|
610
|
+
args: string;
|
611
|
+
};
|
612
|
+
|
613
|
+
/**
|
614
|
+
Log probabilities for each token and its top log probabilities.
|
615
|
+
*/
|
616
|
+
type LanguageModelV1LogProbs = Array<{
|
617
|
+
token: string;
|
618
|
+
logprob: number;
|
619
|
+
topLogprobs: Array<{
|
620
|
+
token: string;
|
621
|
+
logprob: number;
|
622
|
+
}>;
|
623
|
+
}>;
|
624
|
+
|
625
|
+
/**
|
626
|
+
Specification for a language model that implements the language model interface version 1.
|
627
|
+
*/
|
628
|
+
type LanguageModelV1 = {
|
629
|
+
/**
|
630
|
+
The language model must specify which language model interface
|
631
|
+
version it implements. This will allow us to evolve the language
|
632
|
+
model interface and retain backwards compatibility. The different
|
633
|
+
implementation versions can be handled as a discriminated union
|
634
|
+
on our side.
|
635
|
+
*/
|
636
|
+
readonly specificationVersion: 'v1';
|
637
|
+
/**
|
638
|
+
Name of the provider for logging purposes.
|
639
|
+
*/
|
640
|
+
readonly provider: string;
|
641
|
+
/**
|
642
|
+
Provider-specific model ID for logging purposes.
|
643
|
+
*/
|
644
|
+
readonly modelId: string;
|
645
|
+
/**
|
646
|
+
Default object generation mode that should be used with this model when
|
647
|
+
no mode is specified. Should be the mode with the best results for this
|
648
|
+
model. `undefined` can be returned if object generation is not supported.
|
649
|
+
|
650
|
+
This is needed to generate the best objects possible w/o requiring the
|
651
|
+
user to explicitly specify the object generation mode.
|
652
|
+
*/
|
653
|
+
readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
|
654
|
+
/**
|
655
|
+
Generates a language model output (non-streaming).
|
656
|
+
|
657
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
658
|
+
by the user.
|
659
|
+
*/
|
660
|
+
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
661
|
+
/**
|
662
|
+
Text that the model has generated. Can be undefined if the model
|
663
|
+
has only generated tool calls.
|
664
|
+
*/
|
665
|
+
text?: string;
|
666
|
+
/**
|
667
|
+
Tool calls that the model has generated. Can be undefined if the
|
668
|
+
model has only generated text.
|
669
|
+
*/
|
670
|
+
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
671
|
+
/**
|
672
|
+
Finish reason.
|
673
|
+
*/
|
674
|
+
finishReason: LanguageModelV1FinishReason;
|
675
|
+
/**
|
676
|
+
Usage information.
|
677
|
+
*/
|
678
|
+
usage: {
|
679
|
+
promptTokens: number;
|
680
|
+
completionTokens: number;
|
681
|
+
};
|
682
|
+
/**
|
683
|
+
Raw prompt and setting information for observability provider integration.
|
684
|
+
*/
|
685
|
+
rawCall: {
|
686
|
+
/**
|
687
|
+
Raw prompt after expansion and conversion to the format that the
|
688
|
+
provider uses to send the information to their API.
|
689
|
+
*/
|
690
|
+
rawPrompt: unknown;
|
691
|
+
/**
|
692
|
+
Raw settings that are used for the API call. Includes provider-specific
|
693
|
+
settings.
|
694
|
+
*/
|
695
|
+
rawSettings: Record<string, unknown>;
|
696
|
+
};
|
697
|
+
/**
|
698
|
+
Optional raw response information for debugging purposes.
|
699
|
+
*/
|
700
|
+
rawResponse?: {
|
701
|
+
/**
|
702
|
+
Response headers.
|
703
|
+
*/
|
704
|
+
headers?: Record<string, string>;
|
705
|
+
};
|
706
|
+
warnings?: LanguageModelV1CallWarning[];
|
707
|
+
/**
|
708
|
+
Logprobs for the completion.
|
709
|
+
`undefined` if the mode does not support logprobs or if was not enabled
|
710
|
+
*/
|
711
|
+
logprobs?: LanguageModelV1LogProbs;
|
712
|
+
}>;
|
713
|
+
/**
|
714
|
+
Generates a language model output (streaming).
|
715
|
+
|
716
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
717
|
+
by the user.
|
718
|
+
*
|
719
|
+
@return A stream of higher-level language model output parts.
|
720
|
+
*/
|
721
|
+
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
722
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
723
|
+
/**
|
724
|
+
Raw prompt and setting information for observability provider integration.
|
725
|
+
*/
|
726
|
+
rawCall: {
|
727
|
+
/**
|
728
|
+
Raw prompt after expansion and conversion to the format that the
|
729
|
+
provider uses to send the information to their API.
|
730
|
+
*/
|
731
|
+
rawPrompt: unknown;
|
732
|
+
/**
|
733
|
+
Raw settings that are used for the API call. Includes provider-specific
|
734
|
+
settings.
|
735
|
+
*/
|
736
|
+
rawSettings: Record<string, unknown>;
|
737
|
+
};
|
738
|
+
/**
|
739
|
+
Optional raw response data.
|
740
|
+
*/
|
741
|
+
rawResponse?: {
|
742
|
+
/**
|
743
|
+
Response headers.
|
744
|
+
*/
|
745
|
+
headers?: Record<string, string>;
|
746
|
+
};
|
747
|
+
warnings?: LanguageModelV1CallWarning[];
|
748
|
+
}>;
|
749
|
+
doRawStream?: (options: LanguageModelV1CallOptions) => PromiseLike<{
|
750
|
+
stream: ReadableStream<Uint8Array>;
|
751
|
+
/**
|
752
|
+
Raw prompt and setting information for observability provider integration.
|
753
|
+
*/
|
754
|
+
rawCall: {
|
755
|
+
/**
|
756
|
+
Raw prompt after expansion and conversion to the format that the
|
757
|
+
provider uses to send the information to their API.
|
758
|
+
*/
|
759
|
+
rawPrompt: unknown;
|
760
|
+
/**
|
761
|
+
Raw settings that are used for the API call. Includes provider-specific
|
762
|
+
settings.
|
763
|
+
*/
|
764
|
+
rawSettings: Record<string, unknown>;
|
765
|
+
};
|
766
|
+
/**
|
767
|
+
Optional raw response data.
|
768
|
+
*/
|
769
|
+
rawResponse?: {
|
770
|
+
/**
|
771
|
+
Response headers.
|
772
|
+
*/
|
773
|
+
headers?: Record<string, string>;
|
774
|
+
};
|
775
|
+
warnings?: LanguageModelV1CallWarning[];
|
776
|
+
}>;
|
777
|
+
};
|
778
|
+
type LanguageModelV1StreamPart = {
|
779
|
+
type: 'text-delta';
|
780
|
+
textDelta: string;
|
781
|
+
} | ({
|
782
|
+
type: 'tool-call';
|
783
|
+
} & LanguageModelV1FunctionToolCall) | {
|
784
|
+
type: 'tool-call-delta';
|
785
|
+
toolCallType: 'function';
|
786
|
+
toolCallId: string;
|
787
|
+
toolName: string;
|
788
|
+
argsTextDelta: string;
|
789
|
+
} | {
|
790
|
+
type: 'finish';
|
791
|
+
finishReason: LanguageModelV1FinishReason;
|
792
|
+
logprobs?: LanguageModelV1LogProbs;
|
793
|
+
usage: {
|
794
|
+
promptTokens: number;
|
795
|
+
completionTokens: number;
|
796
|
+
};
|
797
|
+
} | {
|
798
|
+
type: 'error';
|
799
|
+
error: unknown;
|
800
|
+
};
|
801
|
+
type LanguageModelV1ResponseMetadata = {};
|
802
|
+
|
803
|
+
export { APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ResponseMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolResultPart, LoadAPIKeyError, NoObjectGeneratedError, NoSuchToolError, RetryError, type RetryErrorReason, TooManyEmbeddingValuesForCallError, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError };
|