@ai-sdk/mistral 2.0.0-canary.5 → 2.0.0-canary.7
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 +35 -0
- package/dist/index.d.mts +7 -15
- package/dist/index.d.ts +7 -15
- package/dist/index.js +110 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -90
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @ai-sdk/mistral
|
|
2
2
|
|
|
3
|
+
## 2.0.0-canary.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1251401: chore(providers/mistral): convert to providerOptions
|
|
8
|
+
- 26735b5: chore(embedding-model): add v2 interface
|
|
9
|
+
- 443d8ec: feat(embedding-model-v2): add response body field
|
|
10
|
+
- fd65bc6: chore(embedding-model-v2): rename rawResponse to response
|
|
11
|
+
- Updated dependencies [26735b5]
|
|
12
|
+
- Updated dependencies [443d8ec]
|
|
13
|
+
- Updated dependencies [14c9410]
|
|
14
|
+
- Updated dependencies [d9c98f4]
|
|
15
|
+
- Updated dependencies [c4a2fec]
|
|
16
|
+
- Updated dependencies [0054544]
|
|
17
|
+
- Updated dependencies [9e9c809]
|
|
18
|
+
- Updated dependencies [32831c6]
|
|
19
|
+
- Updated dependencies [d0f9495]
|
|
20
|
+
- Updated dependencies [fd65bc6]
|
|
21
|
+
- Updated dependencies [393138b]
|
|
22
|
+
- Updated dependencies [7182d14]
|
|
23
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
|
24
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
25
|
+
|
|
26
|
+
## 2.0.0-canary.6
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [411e483]
|
|
31
|
+
- Updated dependencies [79457bd]
|
|
32
|
+
- Updated dependencies [ad80501]
|
|
33
|
+
- Updated dependencies [1766ede]
|
|
34
|
+
- Updated dependencies [f10304b]
|
|
35
|
+
- @ai-sdk/provider@2.0.0-canary.5
|
|
36
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
|
37
|
+
|
|
3
38
|
## 2.0.0-canary.5
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
|
|
4
4
|
type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-small-latest' | 'pixtral-large-latest' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
|
|
5
|
-
interface MistralChatSettings {
|
|
6
|
-
/**
|
|
7
|
-
Whether to inject a safety prompt before all conversations.
|
|
8
|
-
|
|
9
|
-
Defaults to `false`.
|
|
10
|
-
*/
|
|
11
|
-
safePrompt?: boolean;
|
|
12
|
-
}
|
|
13
5
|
|
|
14
6
|
type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
|
|
15
7
|
interface MistralEmbeddingSettings {
|
|
@@ -24,24 +16,24 @@ interface MistralEmbeddingSettings {
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
interface MistralProvider extends ProviderV2 {
|
|
27
|
-
(modelId: MistralChatModelId
|
|
19
|
+
(modelId: MistralChatModelId): LanguageModelV2;
|
|
28
20
|
/**
|
|
29
21
|
Creates a model for text generation.
|
|
30
22
|
*/
|
|
31
|
-
languageModel(modelId: MistralChatModelId
|
|
23
|
+
languageModel(modelId: MistralChatModelId): LanguageModelV2;
|
|
32
24
|
/**
|
|
33
25
|
Creates a model for text generation.
|
|
34
26
|
*/
|
|
35
|
-
chat(modelId: MistralChatModelId
|
|
27
|
+
chat(modelId: MistralChatModelId): LanguageModelV2;
|
|
36
28
|
/**
|
|
37
29
|
@deprecated Use `textEmbeddingModel()` instead.
|
|
38
30
|
*/
|
|
39
|
-
embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings):
|
|
31
|
+
embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
|
|
40
32
|
/**
|
|
41
33
|
@deprecated Use `textEmbeddingModel()` instead.
|
|
42
34
|
*/
|
|
43
|
-
textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings):
|
|
44
|
-
textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) =>
|
|
35
|
+
textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
|
|
36
|
+
textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV2<string>;
|
|
45
37
|
}
|
|
46
38
|
interface MistralProviderSettings {
|
|
47
39
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2,
|
|
1
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
|
|
4
4
|
type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-small-latest' | 'pixtral-large-latest' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
|
|
5
|
-
interface MistralChatSettings {
|
|
6
|
-
/**
|
|
7
|
-
Whether to inject a safety prompt before all conversations.
|
|
8
|
-
|
|
9
|
-
Defaults to `false`.
|
|
10
|
-
*/
|
|
11
|
-
safePrompt?: boolean;
|
|
12
|
-
}
|
|
13
5
|
|
|
14
6
|
type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
|
|
15
7
|
interface MistralEmbeddingSettings {
|
|
@@ -24,24 +16,24 @@ interface MistralEmbeddingSettings {
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
interface MistralProvider extends ProviderV2 {
|
|
27
|
-
(modelId: MistralChatModelId
|
|
19
|
+
(modelId: MistralChatModelId): LanguageModelV2;
|
|
28
20
|
/**
|
|
29
21
|
Creates a model for text generation.
|
|
30
22
|
*/
|
|
31
|
-
languageModel(modelId: MistralChatModelId
|
|
23
|
+
languageModel(modelId: MistralChatModelId): LanguageModelV2;
|
|
32
24
|
/**
|
|
33
25
|
Creates a model for text generation.
|
|
34
26
|
*/
|
|
35
|
-
chat(modelId: MistralChatModelId
|
|
27
|
+
chat(modelId: MistralChatModelId): LanguageModelV2;
|
|
36
28
|
/**
|
|
37
29
|
@deprecated Use `textEmbeddingModel()` instead.
|
|
38
30
|
*/
|
|
39
|
-
embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings):
|
|
31
|
+
embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
|
|
40
32
|
/**
|
|
41
33
|
@deprecated Use `textEmbeddingModel()` instead.
|
|
42
34
|
*/
|
|
43
|
-
textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings):
|
|
44
|
-
textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) =>
|
|
35
|
+
textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
|
|
36
|
+
textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV2<string>;
|
|
45
37
|
}
|
|
46
38
|
interface MistralProviderSettings {
|
|
47
39
|
/**
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
|
31
31
|
|
|
32
32
|
// src/mistral-chat-language-model.ts
|
|
33
33
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
34
|
-
var
|
|
34
|
+
var import_zod3 = require("zod");
|
|
35
35
|
|
|
36
36
|
// src/convert-to-mistral-chat-messages.ts
|
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -154,15 +154,28 @@ function mapMistralFinishReason(finishReason) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
// src/mistral-chat-options.ts
|
|
158
|
+
var import_zod = require("zod");
|
|
159
|
+
var mistralProviderOptions = import_zod.z.object({
|
|
160
|
+
/**
|
|
161
|
+
Whether to inject a safety prompt before all conversations.
|
|
162
|
+
|
|
163
|
+
Defaults to `false`.
|
|
164
|
+
*/
|
|
165
|
+
safePrompt: import_zod.z.boolean().nullish(),
|
|
166
|
+
documentImageLimit: import_zod.z.number().nullish(),
|
|
167
|
+
documentPageLimit: import_zod.z.number().nullish()
|
|
168
|
+
});
|
|
169
|
+
|
|
157
170
|
// src/mistral-error.ts
|
|
158
171
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
159
|
-
var
|
|
160
|
-
var mistralErrorDataSchema =
|
|
161
|
-
object:
|
|
162
|
-
message:
|
|
163
|
-
type:
|
|
164
|
-
param:
|
|
165
|
-
code:
|
|
172
|
+
var import_zod2 = require("zod");
|
|
173
|
+
var mistralErrorDataSchema = import_zod2.z.object({
|
|
174
|
+
object: import_zod2.z.literal("error"),
|
|
175
|
+
message: import_zod2.z.string(),
|
|
176
|
+
type: import_zod2.z.string(),
|
|
177
|
+
param: import_zod2.z.string().nullable(),
|
|
178
|
+
code: import_zod2.z.string().nullable()
|
|
166
179
|
});
|
|
167
180
|
var mistralFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
|
168
181
|
errorSchema: mistralErrorDataSchema,
|
|
@@ -224,12 +237,11 @@ function prepareTools({
|
|
|
224
237
|
|
|
225
238
|
// src/mistral-chat-language-model.ts
|
|
226
239
|
var MistralChatLanguageModel = class {
|
|
227
|
-
constructor(modelId,
|
|
240
|
+
constructor(modelId, config) {
|
|
228
241
|
this.specificationVersion = "v2";
|
|
229
242
|
this.defaultObjectGenerationMode = "json";
|
|
230
243
|
this.supportsImageUrls = false;
|
|
231
244
|
this.modelId = modelId;
|
|
232
|
-
this.settings = settings;
|
|
233
245
|
this.config = config;
|
|
234
246
|
}
|
|
235
247
|
get provider() {
|
|
@@ -240,7 +252,7 @@ var MistralChatLanguageModel = class {
|
|
|
240
252
|
}
|
|
241
253
|
getArgs({
|
|
242
254
|
prompt,
|
|
243
|
-
|
|
255
|
+
maxOutputTokens,
|
|
244
256
|
temperature,
|
|
245
257
|
topP,
|
|
246
258
|
topK,
|
|
@@ -253,8 +265,13 @@ var MistralChatLanguageModel = class {
|
|
|
253
265
|
tools,
|
|
254
266
|
toolChoice
|
|
255
267
|
}) {
|
|
256
|
-
var _a
|
|
268
|
+
var _a;
|
|
257
269
|
const warnings = [];
|
|
270
|
+
const options = (_a = (0, import_provider_utils2.parseProviderOptions)({
|
|
271
|
+
provider: "mistral",
|
|
272
|
+
providerOptions,
|
|
273
|
+
schema: mistralProviderOptions
|
|
274
|
+
})) != null ? _a : {};
|
|
258
275
|
if (topK != null) {
|
|
259
276
|
warnings.push({
|
|
260
277
|
type: "unsupported-setting",
|
|
@@ -290,17 +307,17 @@ var MistralChatLanguageModel = class {
|
|
|
290
307
|
// model id:
|
|
291
308
|
model: this.modelId,
|
|
292
309
|
// model specific settings:
|
|
293
|
-
safe_prompt:
|
|
310
|
+
safe_prompt: options.safePrompt,
|
|
294
311
|
// standardized settings:
|
|
295
|
-
max_tokens:
|
|
312
|
+
max_tokens: maxOutputTokens,
|
|
296
313
|
temperature,
|
|
297
314
|
top_p: topP,
|
|
298
315
|
random_seed: seed,
|
|
299
316
|
// response format:
|
|
300
317
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
|
|
301
318
|
// mistral-specific provider options:
|
|
302
|
-
document_image_limit:
|
|
303
|
-
document_page_limit:
|
|
319
|
+
document_image_limit: options.documentImageLimit,
|
|
320
|
+
document_page_limit: options.documentPageLimit,
|
|
304
321
|
// messages:
|
|
305
322
|
messages: convertToMistralChatMessages(prompt)
|
|
306
323
|
};
|
|
@@ -346,8 +363,9 @@ var MistralChatLanguageModel = class {
|
|
|
346
363
|
text = text.slice(lastMessage.content.length);
|
|
347
364
|
}
|
|
348
365
|
return {
|
|
349
|
-
text,
|
|
366
|
+
text: text != null ? { type: "text", text } : void 0,
|
|
350
367
|
toolCalls: (_a = choice.message.tool_calls) == null ? void 0 : _a.map((toolCall) => ({
|
|
368
|
+
type: "tool-call",
|
|
351
369
|
toolCallType: "function",
|
|
352
370
|
toolCallId: toolCall.id,
|
|
353
371
|
toolName: toolCall.function.name,
|
|
@@ -355,8 +373,8 @@ var MistralChatLanguageModel = class {
|
|
|
355
373
|
})),
|
|
356
374
|
finishReason: mapMistralFinishReason(choice.finish_reason),
|
|
357
375
|
usage: {
|
|
358
|
-
|
|
359
|
-
|
|
376
|
+
inputTokens: response.usage.prompt_tokens,
|
|
377
|
+
outputTokens: response.usage.completion_tokens
|
|
360
378
|
},
|
|
361
379
|
request: { body },
|
|
362
380
|
response: {
|
|
@@ -382,9 +400,9 @@ var MistralChatLanguageModel = class {
|
|
|
382
400
|
fetch: this.config.fetch
|
|
383
401
|
});
|
|
384
402
|
let finishReason = "unknown";
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
403
|
+
const usage = {
|
|
404
|
+
inputTokens: void 0,
|
|
405
|
+
outputTokens: void 0
|
|
388
406
|
};
|
|
389
407
|
let chunkNumber = 0;
|
|
390
408
|
let trimLeadingSpace = false;
|
|
@@ -405,10 +423,8 @@ var MistralChatLanguageModel = class {
|
|
|
405
423
|
});
|
|
406
424
|
}
|
|
407
425
|
if (value.usage != null) {
|
|
408
|
-
usage =
|
|
409
|
-
|
|
410
|
-
completionTokens: value.usage.completion_tokens
|
|
411
|
-
};
|
|
426
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
427
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
412
428
|
}
|
|
413
429
|
const choice = value.choices[0];
|
|
414
430
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -430,8 +446,8 @@ var MistralChatLanguageModel = class {
|
|
|
430
446
|
}
|
|
431
447
|
if (textContent != null) {
|
|
432
448
|
controller.enqueue({
|
|
433
|
-
type: "text
|
|
434
|
-
|
|
449
|
+
type: "text",
|
|
450
|
+
text: trimLeadingSpace ? textContent.trimStart() : textContent
|
|
435
451
|
});
|
|
436
452
|
trimLeadingSpace = false;
|
|
437
453
|
}
|
|
@@ -490,90 +506,90 @@ function extractTextContent(content) {
|
|
|
490
506
|
}
|
|
491
507
|
return textContent.length ? textContent.join("") : void 0;
|
|
492
508
|
}
|
|
493
|
-
var mistralContentSchema =
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
type:
|
|
499
|
-
text:
|
|
509
|
+
var mistralContentSchema = import_zod3.z.union([
|
|
510
|
+
import_zod3.z.string(),
|
|
511
|
+
import_zod3.z.array(
|
|
512
|
+
import_zod3.z.discriminatedUnion("type", [
|
|
513
|
+
import_zod3.z.object({
|
|
514
|
+
type: import_zod3.z.literal("text"),
|
|
515
|
+
text: import_zod3.z.string()
|
|
500
516
|
}),
|
|
501
|
-
|
|
502
|
-
type:
|
|
503
|
-
image_url:
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
url:
|
|
507
|
-
detail:
|
|
517
|
+
import_zod3.z.object({
|
|
518
|
+
type: import_zod3.z.literal("image_url"),
|
|
519
|
+
image_url: import_zod3.z.union([
|
|
520
|
+
import_zod3.z.string(),
|
|
521
|
+
import_zod3.z.object({
|
|
522
|
+
url: import_zod3.z.string(),
|
|
523
|
+
detail: import_zod3.z.string().nullable()
|
|
508
524
|
})
|
|
509
525
|
])
|
|
510
526
|
}),
|
|
511
|
-
|
|
512
|
-
type:
|
|
513
|
-
reference_ids:
|
|
527
|
+
import_zod3.z.object({
|
|
528
|
+
type: import_zod3.z.literal("reference"),
|
|
529
|
+
reference_ids: import_zod3.z.array(import_zod3.z.number())
|
|
514
530
|
})
|
|
515
531
|
])
|
|
516
532
|
)
|
|
517
533
|
]).nullish();
|
|
518
|
-
var mistralChatResponseSchema =
|
|
519
|
-
id:
|
|
520
|
-
created:
|
|
521
|
-
model:
|
|
522
|
-
choices:
|
|
523
|
-
|
|
524
|
-
message:
|
|
525
|
-
role:
|
|
534
|
+
var mistralChatResponseSchema = import_zod3.z.object({
|
|
535
|
+
id: import_zod3.z.string().nullish(),
|
|
536
|
+
created: import_zod3.z.number().nullish(),
|
|
537
|
+
model: import_zod3.z.string().nullish(),
|
|
538
|
+
choices: import_zod3.z.array(
|
|
539
|
+
import_zod3.z.object({
|
|
540
|
+
message: import_zod3.z.object({
|
|
541
|
+
role: import_zod3.z.literal("assistant"),
|
|
526
542
|
content: mistralContentSchema,
|
|
527
|
-
tool_calls:
|
|
528
|
-
|
|
529
|
-
id:
|
|
530
|
-
function:
|
|
543
|
+
tool_calls: import_zod3.z.array(
|
|
544
|
+
import_zod3.z.object({
|
|
545
|
+
id: import_zod3.z.string(),
|
|
546
|
+
function: import_zod3.z.object({ name: import_zod3.z.string(), arguments: import_zod3.z.string() })
|
|
531
547
|
})
|
|
532
548
|
).nullish()
|
|
533
549
|
}),
|
|
534
|
-
index:
|
|
535
|
-
finish_reason:
|
|
550
|
+
index: import_zod3.z.number(),
|
|
551
|
+
finish_reason: import_zod3.z.string().nullish()
|
|
536
552
|
})
|
|
537
553
|
),
|
|
538
|
-
object:
|
|
539
|
-
usage:
|
|
540
|
-
prompt_tokens:
|
|
541
|
-
completion_tokens:
|
|
554
|
+
object: import_zod3.z.literal("chat.completion"),
|
|
555
|
+
usage: import_zod3.z.object({
|
|
556
|
+
prompt_tokens: import_zod3.z.number(),
|
|
557
|
+
completion_tokens: import_zod3.z.number()
|
|
542
558
|
})
|
|
543
559
|
});
|
|
544
|
-
var mistralChatChunkSchema =
|
|
545
|
-
id:
|
|
546
|
-
created:
|
|
547
|
-
model:
|
|
548
|
-
choices:
|
|
549
|
-
|
|
550
|
-
delta:
|
|
551
|
-
role:
|
|
560
|
+
var mistralChatChunkSchema = import_zod3.z.object({
|
|
561
|
+
id: import_zod3.z.string().nullish(),
|
|
562
|
+
created: import_zod3.z.number().nullish(),
|
|
563
|
+
model: import_zod3.z.string().nullish(),
|
|
564
|
+
choices: import_zod3.z.array(
|
|
565
|
+
import_zod3.z.object({
|
|
566
|
+
delta: import_zod3.z.object({
|
|
567
|
+
role: import_zod3.z.enum(["assistant"]).optional(),
|
|
552
568
|
content: mistralContentSchema,
|
|
553
|
-
tool_calls:
|
|
554
|
-
|
|
555
|
-
id:
|
|
556
|
-
function:
|
|
569
|
+
tool_calls: import_zod3.z.array(
|
|
570
|
+
import_zod3.z.object({
|
|
571
|
+
id: import_zod3.z.string(),
|
|
572
|
+
function: import_zod3.z.object({ name: import_zod3.z.string(), arguments: import_zod3.z.string() })
|
|
557
573
|
})
|
|
558
574
|
).nullish()
|
|
559
575
|
}),
|
|
560
|
-
finish_reason:
|
|
561
|
-
index:
|
|
576
|
+
finish_reason: import_zod3.z.string().nullish(),
|
|
577
|
+
index: import_zod3.z.number()
|
|
562
578
|
})
|
|
563
579
|
),
|
|
564
|
-
usage:
|
|
565
|
-
prompt_tokens:
|
|
566
|
-
completion_tokens:
|
|
580
|
+
usage: import_zod3.z.object({
|
|
581
|
+
prompt_tokens: import_zod3.z.number(),
|
|
582
|
+
completion_tokens: import_zod3.z.number()
|
|
567
583
|
}).nullish()
|
|
568
584
|
});
|
|
569
585
|
|
|
570
586
|
// src/mistral-embedding-model.ts
|
|
571
587
|
var import_provider3 = require("@ai-sdk/provider");
|
|
572
588
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
573
|
-
var
|
|
589
|
+
var import_zod4 = require("zod");
|
|
574
590
|
var MistralEmbeddingModel = class {
|
|
575
591
|
constructor(modelId, settings, config) {
|
|
576
|
-
this.specificationVersion = "
|
|
592
|
+
this.specificationVersion = "v2";
|
|
577
593
|
this.modelId = modelId;
|
|
578
594
|
this.settings = settings;
|
|
579
595
|
this.config = config;
|
|
@@ -602,7 +618,11 @@ var MistralEmbeddingModel = class {
|
|
|
602
618
|
values
|
|
603
619
|
});
|
|
604
620
|
}
|
|
605
|
-
const {
|
|
621
|
+
const {
|
|
622
|
+
responseHeaders,
|
|
623
|
+
value: response,
|
|
624
|
+
rawValue
|
|
625
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
|
606
626
|
url: `${this.config.baseURL}/embeddings`,
|
|
607
627
|
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), headers),
|
|
608
628
|
body: {
|
|
@@ -620,13 +640,13 @@ var MistralEmbeddingModel = class {
|
|
|
620
640
|
return {
|
|
621
641
|
embeddings: response.data.map((item) => item.embedding),
|
|
622
642
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
623
|
-
|
|
643
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
624
644
|
};
|
|
625
645
|
}
|
|
626
646
|
};
|
|
627
|
-
var MistralTextEmbeddingResponseSchema =
|
|
628
|
-
data:
|
|
629
|
-
usage:
|
|
647
|
+
var MistralTextEmbeddingResponseSchema = import_zod4.z.object({
|
|
648
|
+
data: import_zod4.z.array(import_zod4.z.object({ embedding: import_zod4.z.array(import_zod4.z.number()) })),
|
|
649
|
+
usage: import_zod4.z.object({ prompt_tokens: import_zod4.z.number() }).nullish()
|
|
630
650
|
});
|
|
631
651
|
|
|
632
652
|
// src/mistral-provider.ts
|
|
@@ -641,7 +661,7 @@ function createMistral(options = {}) {
|
|
|
641
661
|
})}`,
|
|
642
662
|
...options.headers
|
|
643
663
|
});
|
|
644
|
-
const createChatModel = (modelId
|
|
664
|
+
const createChatModel = (modelId) => new MistralChatLanguageModel(modelId, {
|
|
645
665
|
provider: "mistral.chat",
|
|
646
666
|
baseURL,
|
|
647
667
|
headers: getHeaders,
|
|
@@ -653,13 +673,13 @@ function createMistral(options = {}) {
|
|
|
653
673
|
headers: getHeaders,
|
|
654
674
|
fetch: options.fetch
|
|
655
675
|
});
|
|
656
|
-
const provider = function(modelId
|
|
676
|
+
const provider = function(modelId) {
|
|
657
677
|
if (new.target) {
|
|
658
678
|
throw new Error(
|
|
659
679
|
"The Mistral model function cannot be called with the new keyword."
|
|
660
680
|
);
|
|
661
681
|
}
|
|
662
|
-
return createChatModel(modelId
|
|
682
|
+
return createChatModel(modelId);
|
|
663
683
|
};
|
|
664
684
|
provider.languageModel = createChatModel;
|
|
665
685
|
provider.chat = createChatModel;
|