@ai-sdk/mistral 4.0.0-beta.3 → 4.0.0-beta.30
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/CHANGELOG.md +228 -8
- package/README.md +2 -0
- package/dist/index.d.ts +14 -10
- package/dist/index.js +208 -150
- package/dist/index.js.map +1 -1
- package/docs/20-mistral.mdx +21 -0
- package/package.json +9 -10
- package/src/convert-mistral-usage.ts +2 -2
- package/src/convert-to-mistral-chat-messages.ts +12 -6
- package/src/map-mistral-finish-reason.ts +2 -2
- package/src/mistral-chat-language-model.ts +74 -22
- package/src/mistral-chat-options.ts +18 -12
- package/src/mistral-embedding-model.ts +24 -7
- package/src/mistral-prepare-tools.ts +6 -6
- package/src/mistral-provider.ts +12 -12
- package/dist/index.d.mts +0 -78
- package/dist/index.mjs +0 -883
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
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
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createMistral: () => createMistral,
|
|
25
|
-
mistral: () => mistral
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/mistral-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
32
10
|
|
|
33
11
|
// src/mistral-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
combineHeaders,
|
|
14
|
+
createEventSourceResponseHandler,
|
|
15
|
+
createJsonResponseHandler,
|
|
16
|
+
generateId,
|
|
17
|
+
injectJsonInstructionIntoMessages,
|
|
18
|
+
isCustomReasoning,
|
|
19
|
+
mapReasoningToProviderEffort,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
25
|
+
} from "@ai-sdk/provider-utils";
|
|
26
|
+
import { z as z3 } from "zod/v4";
|
|
36
27
|
|
|
37
28
|
// src/convert-mistral-usage.ts
|
|
38
29
|
function convertMistralUsage(usage) {
|
|
@@ -71,13 +62,15 @@ function convertMistralUsage(usage) {
|
|
|
71
62
|
}
|
|
72
63
|
|
|
73
64
|
// src/convert-to-mistral-chat-messages.ts
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
import {
|
|
66
|
+
UnsupportedFunctionalityError
|
|
67
|
+
} from "@ai-sdk/provider";
|
|
68
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
76
69
|
function formatFileUrl({
|
|
77
70
|
data,
|
|
78
71
|
mediaType
|
|
79
72
|
}) {
|
|
80
|
-
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${
|
|
73
|
+
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
|
|
81
74
|
}
|
|
82
75
|
function convertToMistralChatMessages(prompt) {
|
|
83
76
|
var _a;
|
|
@@ -99,6 +92,11 @@ function convertToMistralChatMessages(prompt) {
|
|
|
99
92
|
return { type: "text", text: part.text };
|
|
100
93
|
}
|
|
101
94
|
case "file": {
|
|
95
|
+
if (isProviderReference(part.data)) {
|
|
96
|
+
throw new UnsupportedFunctionalityError({
|
|
97
|
+
functionality: "file parts with provider references"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
102
100
|
if (part.mediaType.startsWith("image/")) {
|
|
103
101
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
104
102
|
return {
|
|
@@ -114,7 +112,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
114
112
|
})
|
|
115
113
|
};
|
|
116
114
|
} else {
|
|
117
|
-
throw new
|
|
115
|
+
throw new UnsupportedFunctionalityError({
|
|
118
116
|
functionality: "Only images and PDF file parts are supported"
|
|
119
117
|
});
|
|
120
118
|
}
|
|
@@ -176,7 +174,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
176
174
|
contentValue = output.value;
|
|
177
175
|
break;
|
|
178
176
|
case "execution-denied":
|
|
179
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
177
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
180
178
|
break;
|
|
181
179
|
case "content":
|
|
182
180
|
case "json":
|
|
@@ -231,54 +229,63 @@ function mapMistralFinishReason(finishReason) {
|
|
|
231
229
|
}
|
|
232
230
|
|
|
233
231
|
// src/mistral-chat-options.ts
|
|
234
|
-
|
|
235
|
-
var mistralLanguageModelOptions =
|
|
232
|
+
import { z } from "zod/v4";
|
|
233
|
+
var mistralLanguageModelOptions = z.object({
|
|
236
234
|
/**
|
|
237
235
|
* Whether to inject a safety prompt before all conversations.
|
|
238
236
|
*
|
|
239
237
|
* Defaults to `false`.
|
|
240
238
|
*/
|
|
241
|
-
safePrompt:
|
|
242
|
-
documentImageLimit:
|
|
243
|
-
documentPageLimit:
|
|
239
|
+
safePrompt: z.boolean().optional(),
|
|
240
|
+
documentImageLimit: z.number().optional(),
|
|
241
|
+
documentPageLimit: z.number().optional(),
|
|
244
242
|
/**
|
|
245
243
|
* Whether to use structured outputs.
|
|
246
244
|
*
|
|
247
245
|
* @default true
|
|
248
246
|
*/
|
|
249
|
-
structuredOutputs:
|
|
247
|
+
structuredOutputs: z.boolean().optional(),
|
|
250
248
|
/**
|
|
251
249
|
* Whether to use strict JSON schema validation.
|
|
252
250
|
*
|
|
253
251
|
* @default false
|
|
254
252
|
*/
|
|
255
|
-
strictJsonSchema:
|
|
253
|
+
strictJsonSchema: z.boolean().optional(),
|
|
256
254
|
/**
|
|
257
255
|
* Whether to enable parallel function calling during tool use.
|
|
258
256
|
* When set to false, the model will use at most one tool per response.
|
|
259
257
|
*
|
|
260
258
|
* @default true
|
|
261
259
|
*/
|
|
262
|
-
parallelToolCalls:
|
|
260
|
+
parallelToolCalls: z.boolean().optional(),
|
|
261
|
+
/**
|
|
262
|
+
* Controls the reasoning effort for models that support adjustable reasoning.
|
|
263
|
+
*
|
|
264
|
+
* - `'high'`: Enable reasoning
|
|
265
|
+
* - `'none'`: Disable reasoning
|
|
266
|
+
*/
|
|
267
|
+
reasoningEffort: z.enum(["high", "none"]).optional()
|
|
263
268
|
});
|
|
264
269
|
|
|
265
270
|
// src/mistral-error.ts
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var mistralErrorDataSchema =
|
|
269
|
-
object:
|
|
270
|
-
message:
|
|
271
|
-
type:
|
|
272
|
-
param:
|
|
273
|
-
code:
|
|
271
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
272
|
+
import { z as z2 } from "zod/v4";
|
|
273
|
+
var mistralErrorDataSchema = z2.object({
|
|
274
|
+
object: z2.literal("error"),
|
|
275
|
+
message: z2.string(),
|
|
276
|
+
type: z2.string(),
|
|
277
|
+
param: z2.string().nullable(),
|
|
278
|
+
code: z2.string().nullable()
|
|
274
279
|
});
|
|
275
|
-
var mistralFailedResponseHandler =
|
|
280
|
+
var mistralFailedResponseHandler = createJsonErrorResponseHandler({
|
|
276
281
|
errorSchema: mistralErrorDataSchema,
|
|
277
282
|
errorToMessage: (data) => data.message
|
|
278
283
|
});
|
|
279
284
|
|
|
280
285
|
// src/mistral-prepare-tools.ts
|
|
281
|
-
|
|
286
|
+
import {
|
|
287
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
288
|
+
} from "@ai-sdk/provider";
|
|
282
289
|
function prepareTools({
|
|
283
290
|
tools,
|
|
284
291
|
toolChoice
|
|
@@ -329,7 +336,7 @@ function prepareTools({
|
|
|
329
336
|
};
|
|
330
337
|
default: {
|
|
331
338
|
const _exhaustiveCheck = type;
|
|
332
|
-
throw new
|
|
339
|
+
throw new UnsupportedFunctionalityError2({
|
|
333
340
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
334
341
|
});
|
|
335
342
|
}
|
|
@@ -337,16 +344,25 @@ function prepareTools({
|
|
|
337
344
|
}
|
|
338
345
|
|
|
339
346
|
// src/mistral-chat-language-model.ts
|
|
340
|
-
var MistralChatLanguageModel = class {
|
|
347
|
+
var MistralChatLanguageModel = class _MistralChatLanguageModel {
|
|
341
348
|
constructor(modelId, config) {
|
|
342
|
-
this.specificationVersion = "
|
|
349
|
+
this.specificationVersion = "v4";
|
|
343
350
|
this.supportedUrls = {
|
|
344
351
|
"application/pdf": [/^https:\/\/.*$/]
|
|
345
352
|
};
|
|
346
353
|
var _a;
|
|
347
354
|
this.modelId = modelId;
|
|
348
355
|
this.config = config;
|
|
349
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
356
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
357
|
+
}
|
|
358
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
359
|
+
return serializeModelOptions({
|
|
360
|
+
modelId: model.modelId,
|
|
361
|
+
config: model.config
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
365
|
+
return new _MistralChatLanguageModel(options.modelId, options.config);
|
|
350
366
|
}
|
|
351
367
|
get provider() {
|
|
352
368
|
return this.config.provider;
|
|
@@ -359,6 +375,7 @@ var MistralChatLanguageModel = class {
|
|
|
359
375
|
topK,
|
|
360
376
|
frequencyPenalty,
|
|
361
377
|
presencePenalty,
|
|
378
|
+
reasoning,
|
|
362
379
|
stopSequences,
|
|
363
380
|
responseFormat,
|
|
364
381
|
seed,
|
|
@@ -366,9 +383,9 @@ var MistralChatLanguageModel = class {
|
|
|
366
383
|
tools,
|
|
367
384
|
toolChoice
|
|
368
385
|
}) {
|
|
369
|
-
var _a, _b, _c, _d;
|
|
386
|
+
var _a, _b, _c, _d, _e;
|
|
370
387
|
const warnings = [];
|
|
371
|
-
const options = (_a = await
|
|
388
|
+
const options = (_a = await parseProviderOptions({
|
|
372
389
|
provider: "mistral",
|
|
373
390
|
providerOptions,
|
|
374
391
|
schema: mistralLanguageModelOptions
|
|
@@ -385,10 +402,31 @@ var MistralChatLanguageModel = class {
|
|
|
385
402
|
if (stopSequences != null) {
|
|
386
403
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
387
404
|
}
|
|
388
|
-
const
|
|
389
|
-
|
|
405
|
+
const supportsReasoningEffort = this.modelId === "mistral-small-latest" || this.modelId === "mistral-small-2603";
|
|
406
|
+
let resolvedReasoningEffort;
|
|
407
|
+
if (supportsReasoningEffort) {
|
|
408
|
+
resolvedReasoningEffort = (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
409
|
+
reasoning,
|
|
410
|
+
effortMap: {
|
|
411
|
+
minimal: "high",
|
|
412
|
+
low: "high",
|
|
413
|
+
medium: "high",
|
|
414
|
+
high: "high",
|
|
415
|
+
xhigh: "high"
|
|
416
|
+
},
|
|
417
|
+
warnings
|
|
418
|
+
}) : void 0;
|
|
419
|
+
} else if (isCustomReasoning(reasoning)) {
|
|
420
|
+
warnings.push({
|
|
421
|
+
type: "unsupported",
|
|
422
|
+
feature: "reasoning",
|
|
423
|
+
details: "This model does not support reasoning configuration."
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
const structuredOutputs = (_c = options.structuredOutputs) != null ? _c : true;
|
|
427
|
+
const strictJsonSchema = (_d = options.strictJsonSchema) != null ? _d : false;
|
|
390
428
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && !(responseFormat == null ? void 0 : responseFormat.schema)) {
|
|
391
|
-
prompt =
|
|
429
|
+
prompt = injectJsonInstructionIntoMessages({
|
|
392
430
|
messages: prompt,
|
|
393
431
|
schema: responseFormat.schema
|
|
394
432
|
});
|
|
@@ -403,13 +441,14 @@ var MistralChatLanguageModel = class {
|
|
|
403
441
|
temperature,
|
|
404
442
|
top_p: topP,
|
|
405
443
|
random_seed: seed,
|
|
444
|
+
reasoning_effort: resolvedReasoningEffort,
|
|
406
445
|
// response format:
|
|
407
446
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
|
|
408
447
|
type: "json_schema",
|
|
409
448
|
json_schema: {
|
|
410
449
|
schema: responseFormat.schema,
|
|
411
450
|
strict: strictJsonSchema,
|
|
412
|
-
name: (
|
|
451
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
413
452
|
description: responseFormat.description
|
|
414
453
|
}
|
|
415
454
|
} : { type: "json_object" } : void 0,
|
|
@@ -438,18 +477,18 @@ var MistralChatLanguageModel = class {
|
|
|
438
477
|
};
|
|
439
478
|
}
|
|
440
479
|
async doGenerate(options) {
|
|
441
|
-
var _a;
|
|
480
|
+
var _a, _b, _c;
|
|
442
481
|
const { args: body, warnings } = await this.getArgs(options);
|
|
443
482
|
const {
|
|
444
483
|
responseHeaders,
|
|
445
484
|
value: response,
|
|
446
485
|
rawValue: rawResponse
|
|
447
|
-
} = await
|
|
486
|
+
} = await postJsonToApi({
|
|
448
487
|
url: `${this.config.baseURL}/chat/completions`,
|
|
449
|
-
headers: (
|
|
488
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
450
489
|
body,
|
|
451
490
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
452
|
-
successfulResponseHandler:
|
|
491
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
453
492
|
mistralChatResponseSchema
|
|
454
493
|
),
|
|
455
494
|
abortSignal: options.abortSignal,
|
|
@@ -490,7 +529,7 @@ var MistralChatLanguageModel = class {
|
|
|
490
529
|
content,
|
|
491
530
|
finishReason: {
|
|
492
531
|
unified: mapMistralFinishReason(choice.finish_reason),
|
|
493
|
-
raw: (
|
|
532
|
+
raw: (_c = choice.finish_reason) != null ? _c : void 0
|
|
494
533
|
},
|
|
495
534
|
usage: convertMistralUsage(response.usage),
|
|
496
535
|
request: { body },
|
|
@@ -503,14 +542,15 @@ var MistralChatLanguageModel = class {
|
|
|
503
542
|
};
|
|
504
543
|
}
|
|
505
544
|
async doStream(options) {
|
|
545
|
+
var _a, _b;
|
|
506
546
|
const { args, warnings } = await this.getArgs(options);
|
|
507
547
|
const body = { ...args, stream: true };
|
|
508
|
-
const { responseHeaders, value: response } = await
|
|
548
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
509
549
|
url: `${this.config.baseURL}/chat/completions`,
|
|
510
|
-
headers: (
|
|
550
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
511
551
|
body,
|
|
512
552
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
513
|
-
successfulResponseHandler:
|
|
553
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
514
554
|
mistralChatChunkSchema
|
|
515
555
|
),
|
|
516
556
|
abortSignal: options.abortSignal,
|
|
@@ -682,98 +722,107 @@ function extractTextContent(content) {
|
|
|
682
722
|
}
|
|
683
723
|
return textContent.length ? textContent.join("") : void 0;
|
|
684
724
|
}
|
|
685
|
-
var mistralContentSchema =
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
type:
|
|
691
|
-
text:
|
|
725
|
+
var mistralContentSchema = z3.union([
|
|
726
|
+
z3.string(),
|
|
727
|
+
z3.array(
|
|
728
|
+
z3.discriminatedUnion("type", [
|
|
729
|
+
z3.object({
|
|
730
|
+
type: z3.literal("text"),
|
|
731
|
+
text: z3.string()
|
|
692
732
|
}),
|
|
693
|
-
|
|
694
|
-
type:
|
|
695
|
-
image_url:
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
url:
|
|
699
|
-
detail:
|
|
733
|
+
z3.object({
|
|
734
|
+
type: z3.literal("image_url"),
|
|
735
|
+
image_url: z3.union([
|
|
736
|
+
z3.string(),
|
|
737
|
+
z3.object({
|
|
738
|
+
url: z3.string(),
|
|
739
|
+
detail: z3.string().nullable()
|
|
700
740
|
})
|
|
701
741
|
])
|
|
702
742
|
}),
|
|
703
|
-
|
|
704
|
-
type:
|
|
705
|
-
reference_ids:
|
|
743
|
+
z3.object({
|
|
744
|
+
type: z3.literal("reference"),
|
|
745
|
+
reference_ids: z3.array(z3.union([z3.string(), z3.number()]))
|
|
706
746
|
}),
|
|
707
|
-
|
|
708
|
-
type:
|
|
709
|
-
thinking:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
747
|
+
z3.object({
|
|
748
|
+
type: z3.literal("thinking"),
|
|
749
|
+
thinking: z3.array(
|
|
750
|
+
z3.object({
|
|
751
|
+
type: z3.literal("text"),
|
|
752
|
+
text: z3.string()
|
|
713
753
|
})
|
|
714
754
|
)
|
|
715
755
|
})
|
|
716
756
|
])
|
|
717
757
|
)
|
|
718
758
|
]).nullish();
|
|
719
|
-
var mistralUsageSchema =
|
|
720
|
-
prompt_tokens:
|
|
721
|
-
completion_tokens:
|
|
722
|
-
total_tokens:
|
|
759
|
+
var mistralUsageSchema = z3.object({
|
|
760
|
+
prompt_tokens: z3.number(),
|
|
761
|
+
completion_tokens: z3.number(),
|
|
762
|
+
total_tokens: z3.number()
|
|
723
763
|
});
|
|
724
|
-
var mistralChatResponseSchema =
|
|
725
|
-
id:
|
|
726
|
-
created:
|
|
727
|
-
model:
|
|
728
|
-
choices:
|
|
729
|
-
|
|
730
|
-
message:
|
|
731
|
-
role:
|
|
764
|
+
var mistralChatResponseSchema = z3.object({
|
|
765
|
+
id: z3.string().nullish(),
|
|
766
|
+
created: z3.number().nullish(),
|
|
767
|
+
model: z3.string().nullish(),
|
|
768
|
+
choices: z3.array(
|
|
769
|
+
z3.object({
|
|
770
|
+
message: z3.object({
|
|
771
|
+
role: z3.literal("assistant"),
|
|
732
772
|
content: mistralContentSchema,
|
|
733
|
-
tool_calls:
|
|
734
|
-
|
|
735
|
-
id:
|
|
736
|
-
function:
|
|
773
|
+
tool_calls: z3.array(
|
|
774
|
+
z3.object({
|
|
775
|
+
id: z3.string(),
|
|
776
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
737
777
|
})
|
|
738
778
|
).nullish()
|
|
739
779
|
}),
|
|
740
|
-
index:
|
|
741
|
-
finish_reason:
|
|
780
|
+
index: z3.number(),
|
|
781
|
+
finish_reason: z3.string().nullish()
|
|
742
782
|
})
|
|
743
783
|
),
|
|
744
|
-
object:
|
|
784
|
+
object: z3.literal("chat.completion"),
|
|
745
785
|
usage: mistralUsageSchema
|
|
746
786
|
});
|
|
747
|
-
var mistralChatChunkSchema =
|
|
748
|
-
id:
|
|
749
|
-
created:
|
|
750
|
-
model:
|
|
751
|
-
choices:
|
|
752
|
-
|
|
753
|
-
delta:
|
|
754
|
-
role:
|
|
787
|
+
var mistralChatChunkSchema = z3.object({
|
|
788
|
+
id: z3.string().nullish(),
|
|
789
|
+
created: z3.number().nullish(),
|
|
790
|
+
model: z3.string().nullish(),
|
|
791
|
+
choices: z3.array(
|
|
792
|
+
z3.object({
|
|
793
|
+
delta: z3.object({
|
|
794
|
+
role: z3.enum(["assistant"]).optional(),
|
|
755
795
|
content: mistralContentSchema,
|
|
756
|
-
tool_calls:
|
|
757
|
-
|
|
758
|
-
id:
|
|
759
|
-
function:
|
|
796
|
+
tool_calls: z3.array(
|
|
797
|
+
z3.object({
|
|
798
|
+
id: z3.string(),
|
|
799
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
760
800
|
})
|
|
761
801
|
).nullish()
|
|
762
802
|
}),
|
|
763
|
-
finish_reason:
|
|
764
|
-
index:
|
|
803
|
+
finish_reason: z3.string().nullish(),
|
|
804
|
+
index: z3.number()
|
|
765
805
|
})
|
|
766
806
|
),
|
|
767
807
|
usage: mistralUsageSchema.nullish()
|
|
768
808
|
});
|
|
769
809
|
|
|
770
810
|
// src/mistral-embedding-model.ts
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
811
|
+
import {
|
|
812
|
+
TooManyEmbeddingValuesForCallError
|
|
813
|
+
} from "@ai-sdk/provider";
|
|
814
|
+
import {
|
|
815
|
+
combineHeaders as combineHeaders2,
|
|
816
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
817
|
+
postJsonToApi as postJsonToApi2,
|
|
818
|
+
serializeModelOptions as serializeModelOptions2,
|
|
819
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
820
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
821
|
+
} from "@ai-sdk/provider-utils";
|
|
822
|
+
import { z as z4 } from "zod/v4";
|
|
823
|
+
var MistralEmbeddingModel = class _MistralEmbeddingModel {
|
|
775
824
|
constructor(modelId, config) {
|
|
776
|
-
this.specificationVersion = "
|
|
825
|
+
this.specificationVersion = "v4";
|
|
777
826
|
this.maxEmbeddingsPerCall = 32;
|
|
778
827
|
this.supportsParallelCalls = false;
|
|
779
828
|
this.modelId = modelId;
|
|
@@ -782,13 +831,23 @@ var MistralEmbeddingModel = class {
|
|
|
782
831
|
get provider() {
|
|
783
832
|
return this.config.provider;
|
|
784
833
|
}
|
|
834
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
835
|
+
return serializeModelOptions2({
|
|
836
|
+
modelId: model.modelId,
|
|
837
|
+
config: model.config
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
841
|
+
return new _MistralEmbeddingModel(options.modelId, options.config);
|
|
842
|
+
}
|
|
785
843
|
async doEmbed({
|
|
786
844
|
values,
|
|
787
845
|
abortSignal,
|
|
788
846
|
headers
|
|
789
847
|
}) {
|
|
848
|
+
var _a, _b;
|
|
790
849
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
791
|
-
throw new
|
|
850
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
792
851
|
provider: this.provider,
|
|
793
852
|
modelId: this.modelId,
|
|
794
853
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -799,16 +858,16 @@ var MistralEmbeddingModel = class {
|
|
|
799
858
|
responseHeaders,
|
|
800
859
|
value: response,
|
|
801
860
|
rawValue
|
|
802
|
-
} = await (
|
|
861
|
+
} = await postJsonToApi2({
|
|
803
862
|
url: `${this.config.baseURL}/embeddings`,
|
|
804
|
-
headers: (
|
|
863
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
805
864
|
body: {
|
|
806
865
|
model: this.modelId,
|
|
807
866
|
input: values,
|
|
808
867
|
encoding_format: "float"
|
|
809
868
|
},
|
|
810
869
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
811
|
-
successfulResponseHandler: (
|
|
870
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
812
871
|
MistralTextEmbeddingResponseSchema
|
|
813
872
|
),
|
|
814
873
|
abortSignal,
|
|
@@ -822,21 +881,21 @@ var MistralEmbeddingModel = class {
|
|
|
822
881
|
};
|
|
823
882
|
}
|
|
824
883
|
};
|
|
825
|
-
var MistralTextEmbeddingResponseSchema =
|
|
826
|
-
data:
|
|
827
|
-
usage:
|
|
884
|
+
var MistralTextEmbeddingResponseSchema = z4.object({
|
|
885
|
+
data: z4.array(z4.object({ embedding: z4.array(z4.number()) })),
|
|
886
|
+
usage: z4.object({ prompt_tokens: z4.number() }).nullish()
|
|
828
887
|
});
|
|
829
888
|
|
|
830
889
|
// src/version.ts
|
|
831
|
-
var VERSION = true ? "4.0.0-beta.
|
|
890
|
+
var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
|
|
832
891
|
|
|
833
892
|
// src/mistral-provider.ts
|
|
834
893
|
function createMistral(options = {}) {
|
|
835
894
|
var _a;
|
|
836
|
-
const baseURL = (_a =
|
|
837
|
-
const getHeaders = () =>
|
|
895
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.mistral.ai/v1";
|
|
896
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
838
897
|
{
|
|
839
|
-
Authorization: `Bearer ${
|
|
898
|
+
Authorization: `Bearer ${loadApiKey({
|
|
840
899
|
apiKey: options.apiKey,
|
|
841
900
|
environmentVariableName: "MISTRAL_API_KEY",
|
|
842
901
|
description: "Mistral"
|
|
@@ -866,7 +925,7 @@ function createMistral(options = {}) {
|
|
|
866
925
|
}
|
|
867
926
|
return createChatModel(modelId);
|
|
868
927
|
};
|
|
869
|
-
provider.specificationVersion = "
|
|
928
|
+
provider.specificationVersion = "v4";
|
|
870
929
|
provider.languageModel = createChatModel;
|
|
871
930
|
provider.chat = createChatModel;
|
|
872
931
|
provider.embedding = createEmbeddingModel;
|
|
@@ -874,15 +933,14 @@ function createMistral(options = {}) {
|
|
|
874
933
|
provider.textEmbedding = createEmbeddingModel;
|
|
875
934
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
876
935
|
provider.imageModel = (modelId) => {
|
|
877
|
-
throw new
|
|
936
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
878
937
|
};
|
|
879
938
|
return provider;
|
|
880
939
|
}
|
|
881
940
|
var mistral = createMistral();
|
|
882
|
-
|
|
883
|
-
0 && (module.exports = {
|
|
941
|
+
export {
|
|
884
942
|
VERSION,
|
|
885
943
|
createMistral,
|
|
886
944
|
mistral
|
|
887
|
-
}
|
|
945
|
+
};
|
|
888
946
|
//# sourceMappingURL=index.js.map
|