@ai-sdk/mistral 4.0.0-beta.1 → 4.0.0-beta.10

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.
@@ -1,12 +1,12 @@
1
1
  import {
2
- LanguageModelV3,
3
- LanguageModelV3CallOptions,
4
- LanguageModelV3Content,
5
- LanguageModelV3FinishReason,
6
- LanguageModelV3GenerateResult,
7
- LanguageModelV3StreamPart,
8
- LanguageModelV3StreamResult,
9
- SharedV3Warning,
2
+ LanguageModelV4,
3
+ LanguageModelV4CallOptions,
4
+ LanguageModelV4Content,
5
+ LanguageModelV4FinishReason,
6
+ LanguageModelV4GenerateResult,
7
+ LanguageModelV4StreamPart,
8
+ LanguageModelV4StreamResult,
9
+ SharedV4Warning,
10
10
  } from '@ai-sdk/provider';
11
11
  import {
12
12
  combineHeaders,
@@ -15,6 +15,8 @@ import {
15
15
  FetchFunction,
16
16
  generateId,
17
17
  injectJsonInstructionIntoMessages,
18
+ isCustomReasoning,
19
+ mapReasoningToProviderEffort,
18
20
  parseProviderOptions,
19
21
  ParseResult,
20
22
  postJsonToApi,
@@ -39,8 +41,8 @@ type MistralChatConfig = {
39
41
  generateId?: () => string;
40
42
  };
41
43
 
42
- export class MistralChatLanguageModel implements LanguageModelV3 {
43
- readonly specificationVersion = 'v3';
44
+ export class MistralChatLanguageModel implements LanguageModelV4 {
45
+ readonly specificationVersion = 'v4';
44
46
 
45
47
  readonly modelId: MistralChatModelId;
46
48
 
@@ -69,14 +71,15 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
69
71
  topK,
70
72
  frequencyPenalty,
71
73
  presencePenalty,
74
+ reasoning,
72
75
  stopSequences,
73
76
  responseFormat,
74
77
  seed,
75
78
  providerOptions,
76
79
  tools,
77
80
  toolChoice,
78
- }: LanguageModelV3CallOptions) {
79
- const warnings: SharedV3Warning[] = [];
81
+ }: LanguageModelV4CallOptions) {
82
+ const warnings: SharedV4Warning[] = [];
80
83
 
81
84
  const options =
82
85
  (await parseProviderOptions({
@@ -101,6 +104,37 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
101
104
  warnings.push({ type: 'unsupported', feature: 'stopSequences' });
102
105
  }
103
106
 
107
+ const supportsReasoningEffort =
108
+ this.modelId === 'mistral-small-latest' ||
109
+ this.modelId === 'mistral-small-2603';
110
+
111
+ let resolvedReasoningEffort: string | undefined;
112
+ if (supportsReasoningEffort) {
113
+ resolvedReasoningEffort =
114
+ options.reasoningEffort ??
115
+ (isCustomReasoning(reasoning)
116
+ ? reasoning === 'none'
117
+ ? 'none'
118
+ : mapReasoningToProviderEffort({
119
+ reasoning,
120
+ effortMap: {
121
+ minimal: 'high',
122
+ low: 'high',
123
+ medium: 'high',
124
+ high: 'high',
125
+ xhigh: 'high',
126
+ },
127
+ warnings,
128
+ })
129
+ : undefined);
130
+ } else if (isCustomReasoning(reasoning)) {
131
+ warnings.push({
132
+ type: 'unsupported',
133
+ feature: 'reasoning',
134
+ details: 'This model does not support reasoning configuration.',
135
+ });
136
+ }
137
+
104
138
  const structuredOutputs = options.structuredOutputs ?? true;
105
139
  const strictJsonSchema = options.strictJsonSchema ?? false;
106
140
 
@@ -125,6 +159,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
125
159
  temperature,
126
160
  top_p: topP,
127
161
  random_seed: seed,
162
+ reasoning_effort: resolvedReasoningEffort,
128
163
 
129
164
  // response format:
130
165
  response_format:
@@ -173,8 +208,8 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
173
208
  }
174
209
 
175
210
  async doGenerate(
176
- options: LanguageModelV3CallOptions,
177
- ): Promise<LanguageModelV3GenerateResult> {
211
+ options: LanguageModelV4CallOptions,
212
+ ): Promise<LanguageModelV4GenerateResult> {
178
213
  const { args: body, warnings } = await this.getArgs(options);
179
214
 
180
215
  const {
@@ -194,7 +229,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
194
229
  });
195
230
 
196
231
  const choice = response.choices[0];
197
- const content: Array<LanguageModelV3Content> = [];
232
+ const content: Array<LanguageModelV4Content> = [];
198
233
 
199
234
  // process content parts in order to preserve sequence
200
235
  if (
@@ -255,8 +290,8 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
255
290
  }
256
291
 
257
292
  async doStream(
258
- options: LanguageModelV3CallOptions,
259
- ): Promise<LanguageModelV3StreamResult> {
293
+ options: LanguageModelV4CallOptions,
294
+ ): Promise<LanguageModelV4StreamResult> {
260
295
  const { args, warnings } = await this.getArgs(options);
261
296
  const body = { ...args, stream: true };
262
297
 
@@ -272,7 +307,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
272
307
  fetch: this.config.fetch,
273
308
  });
274
309
 
275
- let finishReason: LanguageModelV3FinishReason = {
310
+ let finishReason: LanguageModelV4FinishReason = {
276
311
  unified: 'other',
277
312
  raw: undefined,
278
313
  };
@@ -288,7 +323,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
288
323
  stream: response.pipeThrough(
289
324
  new TransformStream<
290
325
  ParseResult<z.infer<typeof mistralChatChunkSchema>>,
291
- LanguageModelV3StreamPart
326
+ LanguageModelV4StreamPart
292
327
  >({
293
328
  start(controller) {
294
329
  controller.enqueue({ type: 'stream-start', warnings });
@@ -2,26 +2,24 @@ import { z } from 'zod/v4';
2
2
 
3
3
  // https://docs.mistral.ai/getting-started/models/models_overview/
4
4
  export type MistralChatModelId =
5
- // premier
6
5
  | 'ministral-3b-latest'
7
6
  | 'ministral-8b-latest'
7
+ | 'ministral-14b-latest'
8
8
  | 'mistral-large-latest'
9
9
  | 'mistral-medium-latest'
10
+ | 'mistral-large-2512'
10
11
  | 'mistral-medium-2508'
11
12
  | 'mistral-medium-2505'
12
- | 'mistral-small-latest'
13
+ | 'mistral-small-2506'
13
14
  | 'pixtral-large-latest'
15
+ // reasoning config support models
16
+ | 'mistral-small-latest'
17
+ | 'mistral-small-2603'
14
18
  // reasoning models
15
- | 'magistral-small-2507'
16
- | 'magistral-medium-2507'
17
- | 'magistral-small-2506'
18
- | 'magistral-medium-2506'
19
- // free
20
- | 'pixtral-12b-2409'
21
- // legacy
22
- | 'open-mistral-7b'
23
- | 'open-mixtral-8x7b'
24
- | 'open-mixtral-8x22b'
19
+ | 'magistral-medium-latest'
20
+ | 'magistral-small-latest'
21
+ | 'magistral-medium-2509'
22
+ | 'magistral-small-2509'
25
23
  | (string & {});
26
24
 
27
25
  export const mistralLanguageModelOptions = z.object({
@@ -56,6 +54,14 @@ export const mistralLanguageModelOptions = z.object({
56
54
  * @default true
57
55
  */
58
56
  parallelToolCalls: z.boolean().optional(),
57
+
58
+ /**
59
+ * Controls the reasoning effort for models that support adjustable reasoning.
60
+ *
61
+ * - `'high'`: Enable reasoning
62
+ * - `'none'`: Disable reasoning
63
+ */
64
+ reasoningEffort: z.enum(['high', 'none']).optional(),
59
65
  });
60
66
 
61
67
  export type MistralLanguageModelOptions = z.infer<
@@ -1,5 +1,5 @@
1
1
  import {
2
- EmbeddingModelV3,
2
+ EmbeddingModelV4,
3
3
  TooManyEmbeddingValuesForCallError,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
@@ -19,8 +19,8 @@ type MistralEmbeddingConfig = {
19
19
  fetch?: FetchFunction;
20
20
  };
21
21
 
22
- export class MistralEmbeddingModel implements EmbeddingModelV3 {
23
- readonly specificationVersion = 'v3';
22
+ export class MistralEmbeddingModel implements EmbeddingModelV4 {
23
+ readonly specificationVersion = 'v4';
24
24
  readonly modelId: MistralEmbeddingModelId;
25
25
  readonly maxEmbeddingsPerCall = 32;
26
26
  readonly supportsParallelCalls = false;
@@ -43,8 +43,8 @@ export class MistralEmbeddingModel implements EmbeddingModelV3 {
43
43
  values,
44
44
  abortSignal,
45
45
  headers,
46
- }: Parameters<EmbeddingModelV3['doEmbed']>[0]): Promise<
47
- Awaited<ReturnType<EmbeddingModelV3['doEmbed']>>
46
+ }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<
47
+ Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>
48
48
  > {
49
49
  if (values.length > this.maxEmbeddingsPerCall) {
50
50
  throw new TooManyEmbeddingValuesForCallError({
@@ -1,6 +1,6 @@
1
1
  import {
2
- LanguageModelV3CallOptions,
3
- SharedV3Warning,
2
+ LanguageModelV4CallOptions,
3
+ SharedV4Warning,
4
4
  UnsupportedFunctionalityError,
5
5
  } from '@ai-sdk/provider';
6
6
  import { MistralToolChoice } from './mistral-chat-prompt';
@@ -9,8 +9,8 @@ export function prepareTools({
9
9
  tools,
10
10
  toolChoice,
11
11
  }: {
12
- tools: LanguageModelV3CallOptions['tools'];
13
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
12
+ tools: LanguageModelV4CallOptions['tools'];
13
+ toolChoice?: LanguageModelV4CallOptions['toolChoice'];
14
14
  }): {
15
15
  tools:
16
16
  | Array<{
@@ -24,12 +24,12 @@ export function prepareTools({
24
24
  }>
25
25
  | undefined;
26
26
  toolChoice: MistralToolChoice | undefined;
27
- toolWarnings: SharedV3Warning[];
27
+ toolWarnings: SharedV4Warning[];
28
28
  } {
29
29
  // when the tools array is empty, change it to undefined to prevent errors:
30
30
  tools = tools?.length ? tools : undefined;
31
31
 
32
- const toolWarnings: SharedV3Warning[] = [];
32
+ const toolWarnings: SharedV4Warning[] = [];
33
33
 
34
34
  if (tools == null) {
35
35
  return { tools: undefined, toolChoice: undefined, toolWarnings };
@@ -1,8 +1,8 @@
1
1
  import {
2
- EmbeddingModelV3,
3
- LanguageModelV3,
2
+ EmbeddingModelV4,
3
+ LanguageModelV4,
4
4
  NoSuchModelError,
5
- ProviderV3,
5
+ ProviderV4,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
8
  FetchFunction,
@@ -16,38 +16,38 @@ import { MistralEmbeddingModel } from './mistral-embedding-model';
16
16
  import { MistralEmbeddingModelId } from './mistral-embedding-options';
17
17
  import { VERSION } from './version';
18
18
 
19
- export interface MistralProvider extends ProviderV3 {
20
- (modelId: MistralChatModelId): LanguageModelV3;
19
+ export interface MistralProvider extends ProviderV4 {
20
+ (modelId: MistralChatModelId): LanguageModelV4;
21
21
 
22
22
  /**
23
23
  * Creates a model for text generation.
24
24
  */
25
- languageModel(modelId: MistralChatModelId): LanguageModelV3;
25
+ languageModel(modelId: MistralChatModelId): LanguageModelV4;
26
26
 
27
27
  /**
28
28
  * Creates a model for text generation.
29
29
  */
30
- chat(modelId: MistralChatModelId): LanguageModelV3;
30
+ chat(modelId: MistralChatModelId): LanguageModelV4;
31
31
 
32
32
  /**
33
33
  * Creates a model for text embeddings.
34
34
  */
35
- embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
35
+ embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
36
36
 
37
37
  /**
38
38
  * Creates a model for text embeddings.
39
39
  */
40
- embeddingModel: (modelId: MistralEmbeddingModelId) => EmbeddingModelV3;
40
+ embeddingModel: (modelId: MistralEmbeddingModelId) => EmbeddingModelV4;
41
41
 
42
42
  /**
43
43
  * @deprecated Use `embedding` instead.
44
44
  */
45
- textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
45
+ textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
46
46
 
47
47
  /**
48
48
  * @deprecated Use `embeddingModel` instead.
49
49
  */
50
- textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
50
+ textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
51
51
  }
52
52
 
53
53
  export interface MistralProviderSettings {
@@ -126,7 +126,7 @@ export function createMistral(
126
126
  return createChatModel(modelId);
127
127
  };
128
128
 
129
- provider.specificationVersion = 'v3' as const;
129
+ provider.specificationVersion = 'v4' as const;
130
130
  provider.languageModel = createChatModel;
131
131
  provider.chat = createChatModel;
132
132
  provider.embedding = createEmbeddingModel;