@ai-sdk/mistral 4.0.68 → 4.0.70
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 +26 -0
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -45
- package/dist/index.js.map +1 -1
- package/docs/20-mistral.mdx +113 -23
- package/package.json +3 -3
- package/src/mistral-chat-language-model-options.ts +47 -42
- package/src/mistral-chat-language-model.ts +107 -88
- package/src/mistral-conversation-language-model-options.ts +4 -2
- package/src/mistral-conversation-language-model.ts +107 -90
- package/src/mistral-embedding-model.ts +10 -4
- package/src/mistral-error.ts +18 -9
- package/src/mistral-speech-model-options.ts +34 -9
- package/src/mistral-speech-model.ts +11 -3
- package/src/mistral-transcription-model-options.ts +17 -14
- package/src/mistral-transcription-model.ts +52 -28
package/docs/20-mistral.mdx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Mistral AI
|
|
3
|
-
description: Learn how to use Mistral.
|
|
3
|
+
description: Learn how to use Mistral AI with AI Gateway and the direct provider.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Mistral AI Provider
|
|
@@ -8,12 +8,56 @@ description: Learn how to use Mistral.
|
|
|
8
8
|
The [Mistral AI](https://mistral.ai/) provider contains language model,
|
|
9
9
|
embedding model, speech model, and transcription model support for Mistral
|
|
10
10
|
APIs.
|
|
11
|
+
You can use Mistral AI models through [AI Gateway](/providers/ai-sdk-providers/ai-gateway) (recommended) or connect directly with `@ai-sdk/mistral`.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
```ts provider="mistral" model="mistral/mistral-medium-3.5"
|
|
14
|
+
import { generateText } from 'ai';
|
|
15
|
+
__PROVIDER_IMPORT__;
|
|
16
|
+
|
|
17
|
+
const { text } = await generateText({
|
|
18
|
+
model: __MODEL__,
|
|
19
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log(text);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Using AI Gateway
|
|
26
|
+
|
|
27
|
+
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install `ai`:
|
|
28
|
+
|
|
29
|
+
<InstallPackages packages="ai" />
|
|
30
|
+
|
|
31
|
+
Set an [AI Gateway API key](https://vercel.com/docs/ai-gateway/getting-started) in your environment:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export AI_GATEWAY_API_KEY=your_api_key_here
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Vercel deployments can also use [OIDC authentication](/providers/ai-sdk-providers/ai-gateway#oidc-authentication-vercel-deployments).
|
|
38
|
+
See the [AI Gateway provider documentation](/providers/ai-sdk-providers/ai-gateway) for configuration and the [model catalog](https://vercel.com/ai-gateway/models) for available models.
|
|
39
|
+
|
|
40
|
+
Gateway feature and provider-option support depends on the model and the provider serving the request. See [Gateway provider options](https://vercel.com/docs/ai-gateway/models-and-providers/provider-options).
|
|
41
|
+
|
|
42
|
+
## Using `@ai-sdk/mistral`
|
|
43
|
+
|
|
44
|
+
For direct access to Mistral AI, install `ai` and `@ai-sdk/mistral`:
|
|
45
|
+
|
|
46
|
+
<InstallPackages packages="ai @ai-sdk/mistral" />
|
|
47
|
+
|
|
48
|
+
Set your Mistral AI API credential in the `MISTRAL_API_KEY` environment variable:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export MISTRAL_API_KEY=your_api_key_here
|
|
52
|
+
```
|
|
13
53
|
|
|
14
|
-
|
|
54
|
+
AI Gateway does not expose every API in `@ai-sdk/mistral`. Use the direct provider for provider-specific APIs or custom connection settings.
|
|
15
55
|
|
|
16
|
-
<
|
|
56
|
+
<Note>
|
|
57
|
+
The following sections document the direct `@ai-sdk/mistral` provider,
|
|
58
|
+
including its model factories and settings. Gateway model and feature
|
|
59
|
+
availability can differ.
|
|
60
|
+
</Note>
|
|
17
61
|
|
|
18
62
|
## Provider Instance
|
|
19
63
|
|
|
@@ -452,7 +496,7 @@ You can create models that call the
|
|
|
452
496
|
using the `.transcription()` factory method:
|
|
453
497
|
|
|
454
498
|
```ts
|
|
455
|
-
const model = mistral.transcription('voxtral-mini-
|
|
499
|
+
const model = mistral.transcription('voxtral-mini-transcribe-3-0');
|
|
456
500
|
```
|
|
457
501
|
|
|
458
502
|
Use Mistral transcription models with [`transcribe`](/docs/reference/ai-sdk-core/transcribe):
|
|
@@ -463,7 +507,7 @@ import { transcribe } from 'ai';
|
|
|
463
507
|
import { readFile } from 'node:fs/promises';
|
|
464
508
|
|
|
465
509
|
const result = await transcribe({
|
|
466
|
-
model: mistral.transcription('voxtral-mini-
|
|
510
|
+
model: mistral.transcription('voxtral-mini-transcribe-3-0'),
|
|
467
511
|
audio: await readFile('audio.mp3'),
|
|
468
512
|
});
|
|
469
513
|
```
|
|
@@ -481,13 +525,14 @@ import { transcribe } from 'ai';
|
|
|
481
525
|
import { readFile } from 'node:fs/promises';
|
|
482
526
|
|
|
483
527
|
const result = await transcribe({
|
|
484
|
-
model: mistral.transcription('voxtral-mini-
|
|
528
|
+
model: mistral.transcription('voxtral-mini-transcribe-3-0'),
|
|
485
529
|
audio: await readFile('audio.mp3'),
|
|
486
530
|
providerOptions: {
|
|
487
531
|
mistral: {
|
|
488
532
|
timestampGranularities: ['segment'],
|
|
489
533
|
diarize: true,
|
|
490
|
-
|
|
534
|
+
returnLanguage: true,
|
|
535
|
+
contextBias: ['Vercel', 'AI SDK', 'A discussion about TypeScript.'],
|
|
491
536
|
} satisfies MistralTranscriptionModelOptions,
|
|
492
537
|
},
|
|
493
538
|
});
|
|
@@ -499,25 +544,36 @@ The following optional provider options are available:
|
|
|
499
544
|
|
|
500
545
|
The language of the audio, such as `en`. Providing it can improve accuracy.
|
|
501
546
|
|
|
547
|
+
- **returnLanguage** _boolean_
|
|
548
|
+
|
|
549
|
+
Return the detected language with Voxtral 3. Without this option, the response
|
|
550
|
+
language is normally absent. Cannot be `true` when `language` is provided.
|
|
551
|
+
|
|
502
552
|
- **temperature** _number_
|
|
503
553
|
|
|
504
554
|
The sampling temperature for the transcription.
|
|
505
555
|
|
|
506
556
|
- **timestampGranularities** _Array<'segment' | 'word'>_
|
|
507
557
|
|
|
508
|
-
Timestamp granularities to include in the response.
|
|
509
|
-
|
|
510
|
-
|
|
558
|
+
Timestamp granularities to include in the response. Voxtral 3 supports only
|
|
559
|
+
`segment` and allows it to be combined with `language`. The SDK rejects this
|
|
560
|
+
combination for the legacy IDs `voxtral-mini-2507`, `voxtral-mini-2602`, and
|
|
561
|
+
`voxtral-mini-latest`, throwing an `InvalidArgumentError`. Other model IDs are
|
|
562
|
+
allowed to send the combination to Mistral. Model-specific timestamp and
|
|
563
|
+
diarization requirements are validated by the Mistral API.
|
|
511
564
|
|
|
512
565
|
- **diarize** _boolean_
|
|
513
566
|
|
|
514
|
-
Whether to identify speakers in the transcription.
|
|
567
|
+
Whether to identify speakers in the transcription. Voxtral 3 requires
|
|
568
|
+
`timestampGranularities: ['segment']` when this option is `true`.
|
|
515
569
|
|
|
516
570
|
- **contextBias** _string[]_
|
|
517
571
|
|
|
518
|
-
|
|
519
|
-
or domain-specific vocabulary.
|
|
520
|
-
|
|
572
|
+
Words, phrases, or descriptions of the recording that guide spelling for
|
|
573
|
+
names, technical terms, or domain-specific vocabulary. Voxtral 3 accepts spaces
|
|
574
|
+
and punctuation and has no fixed entry limit; entries share the context window
|
|
575
|
+
with the audio. Earlier models require entries without commas or whitespace
|
|
576
|
+
and support up to 100 entries.
|
|
521
577
|
|
|
522
578
|
The normalized result includes transcript text, language, timed segments, and
|
|
523
579
|
duration when returned by Mistral. Mistral token and prompt-audio usage is
|
|
@@ -533,9 +589,11 @@ speaker IDs from diarization are available under
|
|
|
533
589
|
|
|
534
590
|
### Model Capabilities
|
|
535
591
|
|
|
536
|
-
| Model
|
|
537
|
-
|
|
|
538
|
-
| `voxtral-mini-
|
|
592
|
+
| Model | Timestamps | Diarization | Context Bias |
|
|
593
|
+
| ------------------------------ | ---------- | ----------- | ------------ |
|
|
594
|
+
| `voxtral-mini-transcribe-3-0` | <Check /> | <Check /> | <Check /> |
|
|
595
|
+
| `voxtral-small-transcribe-3-0` | <Check /> | <Check /> | <Check /> |
|
|
596
|
+
| `voxtral-mini-latest` | <Check /> | <Check /> | <Check /> |
|
|
539
597
|
|
|
540
598
|
## Speech Models
|
|
541
599
|
|
|
@@ -544,7 +602,7 @@ You can create models that call the
|
|
|
544
602
|
the `.speech()` factory method:
|
|
545
603
|
|
|
546
604
|
```ts
|
|
547
|
-
const model = mistral.speech('voxtral-mini-tts-
|
|
605
|
+
const model = mistral.speech('voxtral-mini-tts-3-0');
|
|
548
606
|
```
|
|
549
607
|
|
|
550
608
|
Use a preset or saved voice ID with [`generateSpeech`](/docs/reference/ai-sdk-core/generate-speech):
|
|
@@ -554,9 +612,9 @@ import { mistral } from '@ai-sdk/mistral';
|
|
|
554
612
|
import { generateSpeech } from 'ai';
|
|
555
613
|
|
|
556
614
|
const result = await generateSpeech({
|
|
557
|
-
model: mistral.speech('voxtral-mini-tts-
|
|
615
|
+
model: mistral.speech('voxtral-mini-tts-3-0'),
|
|
558
616
|
text: 'Hello from the AI SDK!',
|
|
559
|
-
voice: '
|
|
617
|
+
voice: 'gb_jane_neutral',
|
|
560
618
|
outputFormat: 'mp3',
|
|
561
619
|
});
|
|
562
620
|
|
|
@@ -566,7 +624,38 @@ const audio = result.audio.uint8Array;
|
|
|
566
624
|
The Mistral speech model maps `voice` to Mistral's `voice_id`. It supports
|
|
567
625
|
`mp3`, `wav`, `pcm`, `flac`, and `opus` output formats and defaults to `mp3`.
|
|
568
626
|
The `instructions`, `speed`, and `language` settings are not supported and
|
|
569
|
-
produce warnings when provided.
|
|
627
|
+
produce warnings when provided. Voxtral 3 style instructions are not available
|
|
628
|
+
at launch. To control emotion and pace, include tags such as `[emotion=happy]`
|
|
629
|
+
and `[pace=slow]` directly in `text`.
|
|
630
|
+
|
|
631
|
+
Voxtral 3 supports additional delivery controls through `providerOptions.mistral`:
|
|
632
|
+
|
|
633
|
+
- **expressiveness** _number_
|
|
634
|
+
|
|
635
|
+
A value from 1 to 5 controlling expressiveness. Higher values trade voice
|
|
636
|
+
similarity and stability for stronger delivery. Omit it to use the service default.
|
|
637
|
+
|
|
638
|
+
- **phonemeHints** _Record<string, string[]>_
|
|
639
|
+
|
|
640
|
+
Map words in the input to lists of IPA phonemes. Mistral validates the supported
|
|
641
|
+
phoneme inventory. See [custom pronunciation](https://docs.mistral.ai/studio/audio/text-to-speech/custom-pronunciation).
|
|
642
|
+
|
|
643
|
+
```ts
|
|
644
|
+
import { mistral, type MistralSpeechModelOptions } from '@ai-sdk/mistral';
|
|
645
|
+
import { generateSpeech } from 'ai';
|
|
646
|
+
|
|
647
|
+
const result = await generateSpeech({
|
|
648
|
+
model: mistral.speech('voxtral-mini-tts-3-0'),
|
|
649
|
+
text: '[emotion=happy] I like tomato soup.',
|
|
650
|
+
voice: 'gb_jane_neutral',
|
|
651
|
+
providerOptions: {
|
|
652
|
+
mistral: {
|
|
653
|
+
expressiveness: 1.5,
|
|
654
|
+
phonemeHints: { tomato: ['t', 'ə', 'm', 'ɑ', 't', 'oʊ'] },
|
|
655
|
+
} satisfies MistralSpeechModelOptions,
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
```
|
|
570
659
|
|
|
571
660
|
Mistral also supports one-off voice cloning with base64-encoded reference
|
|
572
661
|
audio. Pass it through `providerOptions.mistral.refAudio` and use
|
|
@@ -580,7 +669,7 @@ import { generateSpeech } from 'ai';
|
|
|
580
669
|
const referenceAudio = await readFile('./reference.mp3');
|
|
581
670
|
|
|
582
671
|
const result = await generateSpeech({
|
|
583
|
-
model: mistral.speech('voxtral-mini-tts-
|
|
672
|
+
model: mistral.speech('voxtral-mini-tts-3-0'),
|
|
584
673
|
text: 'Hello from the AI SDK!',
|
|
585
674
|
providerOptions: {
|
|
586
675
|
mistral: {
|
|
@@ -604,6 +693,7 @@ is redacted from request metadata and API call errors returned by the provider.
|
|
|
604
693
|
|
|
605
694
|
| Model | Saved Voices | Reference Audio | Non-Streaming |
|
|
606
695
|
| ----------------------- | ------------ | --------------- | ------------- |
|
|
696
|
+
| `voxtral-mini-tts-3-0` | <Check /> | <Check /> | <Check /> |
|
|
607
697
|
| `voxtral-mini-tts-2603` | <Check /> | <Check /> | <Check /> |
|
|
608
698
|
|
|
609
699
|
## Embedding Models
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mistral",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.70",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider": "4.0.
|
|
33
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/provider": "4.0.32",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.66"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
3
|
|
|
3
4
|
// https://docs.mistral.ai/models
|
|
@@ -37,54 +38,58 @@ export type MistralChatModelId =
|
|
|
37
38
|
| 'zai-glm-5-2'
|
|
38
39
|
| (string & {});
|
|
39
40
|
|
|
40
|
-
export const mistralLanguageModelChatOptions =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
export const mistralLanguageModelChatOptions = () =>
|
|
42
|
+
z.object({
|
|
43
|
+
/**
|
|
44
|
+
* Whether to inject a safety prompt before all conversations.
|
|
45
|
+
*
|
|
46
|
+
* Defaults to `false`.
|
|
47
|
+
*/
|
|
48
|
+
safePrompt: z.boolean().optional(),
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
documentImageLimit: z.number().optional(),
|
|
51
|
+
documentPageLimit: z.number().optional(),
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Whether to use structured outputs.
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
structuredOutputs: z.boolean().optional(),
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Whether to use strict JSON schema validation.
|
|
62
|
+
*
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
strictJsonSchema: z.boolean().optional(),
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Whether to enable parallel function calling during tool use.
|
|
69
|
+
* When set to false, the model will use at most one tool per response.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
parallelToolCalls: z.boolean().optional(),
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
/**
|
|
76
|
+
* A stable identifier used to route requests with shared prompt prefixes to
|
|
77
|
+
* the same cache.
|
|
78
|
+
*/
|
|
79
|
+
promptCacheKey: z.string().optional(),
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
81
|
+
/**
|
|
82
|
+
* Controls the reasoning effort for models that support adjustable reasoning.
|
|
83
|
+
*
|
|
84
|
+
* - `'high'`: Enable reasoning
|
|
85
|
+
* - `'none'`: Disable reasoning
|
|
86
|
+
*/
|
|
87
|
+
reasoningEffort: z.enum(['high', 'none']).optional(),
|
|
88
|
+
});
|
|
89
|
+
export const mistralLanguageModelChatOptionsValidator = lazySchema(() =>
|
|
90
|
+
zodSchema(mistralLanguageModelChatOptions()),
|
|
91
|
+
);
|
|
87
92
|
|
|
88
93
|
export type MistralLanguageModelChatOptions = z.infer<
|
|
89
|
-
typeof mistralLanguageModelChatOptions
|
|
94
|
+
ReturnType<typeof mistralLanguageModelChatOptions>
|
|
90
95
|
>;
|
|
@@ -9,6 +9,9 @@ import type {
|
|
|
9
9
|
SharedV4Warning,
|
|
10
10
|
} from '@ai-sdk/provider';
|
|
11
11
|
import {
|
|
12
|
+
lazySchema,
|
|
13
|
+
zodSchema,
|
|
14
|
+
type InferSchema,
|
|
12
15
|
combineHeaders,
|
|
13
16
|
createEventSourceResponseHandler,
|
|
14
17
|
createJsonResponseHandler,
|
|
@@ -36,7 +39,7 @@ import { convertToMistralChatMessages } from './convert-to-mistral-chat-messages
|
|
|
36
39
|
import { getResponseMetadata } from './get-response-metadata';
|
|
37
40
|
import { mapMistralFinishReason } from './map-mistral-finish-reason';
|
|
38
41
|
import {
|
|
39
|
-
|
|
42
|
+
mistralLanguageModelChatOptionsValidator,
|
|
40
43
|
type MistralChatModelId,
|
|
41
44
|
} from './mistral-chat-language-model-options';
|
|
42
45
|
import { mistralFailedResponseHandler } from './mistral-error';
|
|
@@ -127,7 +130,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
|
|
|
127
130
|
(await parseProviderOptions({
|
|
128
131
|
provider: 'mistral',
|
|
129
132
|
providerOptions,
|
|
130
|
-
schema:
|
|
133
|
+
schema: mistralLanguageModelChatOptionsValidator,
|
|
131
134
|
})) ?? {};
|
|
132
135
|
|
|
133
136
|
if (topK != null) {
|
|
@@ -349,8 +352,9 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
|
|
|
349
352
|
fetch: this.config.fetch,
|
|
350
353
|
});
|
|
351
354
|
|
|
355
|
+
// A clean end without the provider's completion signal is interrupted.
|
|
352
356
|
let finishReason: LanguageModelV4FinishReason = {
|
|
353
|
-
unified: '
|
|
357
|
+
unified: 'interrupted',
|
|
354
358
|
raw: undefined,
|
|
355
359
|
};
|
|
356
360
|
let usage: MistralUsage | undefined = undefined;
|
|
@@ -365,7 +369,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
|
|
|
365
369
|
return {
|
|
366
370
|
stream: response.pipeThrough(
|
|
367
371
|
new TransformStream<
|
|
368
|
-
ParseResult<
|
|
372
|
+
ParseResult<InferSchema<typeof mistralChatChunkSchema>>,
|
|
369
373
|
LanguageModelV4StreamPart
|
|
370
374
|
>({
|
|
371
375
|
start(controller) {
|
|
@@ -382,6 +386,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
|
|
|
382
386
|
}
|
|
383
387
|
|
|
384
388
|
if (!chunk.success) {
|
|
389
|
+
finishReason = { unified: 'error', raw: undefined };
|
|
385
390
|
controller.enqueue({ type: 'error', error: chunk.error });
|
|
386
391
|
return;
|
|
387
392
|
}
|
|
@@ -505,7 +510,9 @@ function extractReasoningContent(
|
|
|
505
510
|
.join('');
|
|
506
511
|
}
|
|
507
512
|
|
|
508
|
-
function extractTextContent(
|
|
513
|
+
function extractTextContent(
|
|
514
|
+
content: z.infer<ReturnType<typeof mistralContentSchema>>,
|
|
515
|
+
) {
|
|
509
516
|
if (typeof content === 'string') {
|
|
510
517
|
return content;
|
|
511
518
|
}
|
|
@@ -538,98 +545,110 @@ function extractTextContent(content: z.infer<typeof mistralContentSchema>) {
|
|
|
538
545
|
return textContent.length ? textContent.join('') : undefined;
|
|
539
546
|
}
|
|
540
547
|
|
|
541
|
-
const mistralContentSchema =
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
z.
|
|
546
|
-
z.
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
z.
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
z.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
548
|
+
const mistralContentSchema = () =>
|
|
549
|
+
z
|
|
550
|
+
.union([
|
|
551
|
+
z.string(),
|
|
552
|
+
z.array(
|
|
553
|
+
z.discriminatedUnion('type', [
|
|
554
|
+
z.object({
|
|
555
|
+
type: z.literal('text'),
|
|
556
|
+
text: z.string(),
|
|
557
|
+
}),
|
|
558
|
+
z.object({
|
|
559
|
+
type: z.literal('image_url'),
|
|
560
|
+
image_url: z.union([
|
|
561
|
+
z.string(),
|
|
562
|
+
z.object({
|
|
563
|
+
url: z.string(),
|
|
564
|
+
detail: z.string().nullable(),
|
|
565
|
+
}),
|
|
566
|
+
]),
|
|
567
|
+
}),
|
|
568
|
+
z.object({
|
|
569
|
+
type: z.literal('reference'),
|
|
570
|
+
reference_ids: z.array(z.union([z.string(), z.number()])),
|
|
571
|
+
}),
|
|
572
|
+
z.object({
|
|
573
|
+
type: z.literal('thinking'),
|
|
574
|
+
thinking: z.array(
|
|
575
|
+
z.object({
|
|
576
|
+
type: z.literal('text'),
|
|
577
|
+
text: z.string(),
|
|
578
|
+
}),
|
|
579
|
+
),
|
|
580
|
+
}),
|
|
581
|
+
]),
|
|
582
|
+
),
|
|
583
|
+
])
|
|
584
|
+
.nullish();
|
|
577
585
|
|
|
578
586
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
579
587
|
// this approach limits breakages when the API changes and increases efficiency
|
|
580
|
-
const mistralChatResponseSchema =
|
|
581
|
-
|
|
582
|
-
created: z.number().nullish(),
|
|
583
|
-
model: z.string().nullish(),
|
|
584
|
-
choices: z.array(
|
|
588
|
+
const mistralChatResponseSchema = lazySchema(() =>
|
|
589
|
+
zodSchema(
|
|
585
590
|
z.object({
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
591
|
+
id: z.string().nullish(),
|
|
592
|
+
created: z.number().nullish(),
|
|
593
|
+
model: z.string().nullish(),
|
|
594
|
+
choices: z.array(
|
|
595
|
+
z.object({
|
|
596
|
+
message: z.object({
|
|
597
|
+
role: z.literal('assistant'),
|
|
598
|
+
content: mistralContentSchema(),
|
|
599
|
+
tool_calls: z
|
|
600
|
+
.array(
|
|
601
|
+
z.object({
|
|
602
|
+
id: z.string(),
|
|
603
|
+
function: z.object({
|
|
604
|
+
name: z.string(),
|
|
605
|
+
arguments: z.string(),
|
|
606
|
+
}),
|
|
607
|
+
}),
|
|
608
|
+
)
|
|
609
|
+
.nullish(),
|
|
610
|
+
}),
|
|
611
|
+
index: z.number(),
|
|
612
|
+
finish_reason: z.string().nullish(),
|
|
613
|
+
}),
|
|
614
|
+
),
|
|
615
|
+
object: z.literal('chat.completion'),
|
|
616
|
+
usage: mistralUsageSchema,
|
|
600
617
|
}),
|
|
601
618
|
),
|
|
602
|
-
|
|
603
|
-
usage: mistralUsageSchema,
|
|
604
|
-
});
|
|
619
|
+
);
|
|
605
620
|
|
|
606
621
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
607
622
|
// this approach limits breakages when the API changes and increases efficiency
|
|
608
|
-
const mistralChatChunkSchema =
|
|
609
|
-
|
|
610
|
-
created: z.number().nullish(),
|
|
611
|
-
model: z.string().nullish(),
|
|
612
|
-
choices: z.array(
|
|
623
|
+
const mistralChatChunkSchema = lazySchema(() =>
|
|
624
|
+
zodSchema(
|
|
613
625
|
z.object({
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
626
|
+
id: z.string().nullish(),
|
|
627
|
+
created: z.number().nullish(),
|
|
628
|
+
model: z.string().nullish(),
|
|
629
|
+
choices: z.array(
|
|
630
|
+
z.object({
|
|
631
|
+
delta: z.object({
|
|
632
|
+
role: z.enum(['assistant']).optional(),
|
|
633
|
+
content: mistralContentSchema(),
|
|
634
|
+
tool_calls: z
|
|
635
|
+
.array(
|
|
636
|
+
z.object({
|
|
637
|
+
index: z.number().nullish(),
|
|
638
|
+
id: z.string().nullish(),
|
|
639
|
+
function: z.object({
|
|
640
|
+
name: z.string().nullish(),
|
|
641
|
+
arguments: z.string().nullish(),
|
|
642
|
+
}),
|
|
643
|
+
}),
|
|
644
|
+
)
|
|
645
|
+
.nullish(),
|
|
646
|
+
}),
|
|
647
|
+
finish_reason: z.string().nullish(),
|
|
648
|
+
index: z.number(),
|
|
649
|
+
}),
|
|
650
|
+
),
|
|
651
|
+
usage: mistralUsageSchema.nullish(),
|
|
632
652
|
}),
|
|
633
653
|
),
|
|
634
|
-
|
|
635
|
-
});
|
|
654
|
+
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
1
2
|
import {
|
|
2
3
|
mistralLanguageModelChatOptions,
|
|
3
4
|
type MistralChatModelId,
|
|
@@ -6,8 +7,9 @@ import {
|
|
|
6
7
|
|
|
7
8
|
export type MistralConversationModelId = MistralChatModelId;
|
|
8
9
|
|
|
9
|
-
export const mistralLanguageModelConversationOptions =
|
|
10
|
-
mistralLanguageModelChatOptions
|
|
10
|
+
export const mistralLanguageModelConversationOptions = lazySchema(() =>
|
|
11
|
+
zodSchema(mistralLanguageModelChatOptions()),
|
|
12
|
+
);
|
|
11
13
|
|
|
12
14
|
export type MistralLanguageModelConversationOptions =
|
|
13
15
|
MistralLanguageModelChatOptions;
|