@ai-sdk/mistral 0.0.0-85f9a635-20240518005312 → 0.0.0-98261322-20260122142521
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 +1795 -0
- package/README.md +10 -48
- package/dist/index.d.mts +41 -84
- package/dist/index.d.ts +41 -84
- package/dist/index.js +611 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +614 -279
- package/dist/index.mjs.map +1 -1
- package/docs/20-mistral.mdx +327 -0
- package/package.json +23 -18
- package/src/__fixtures__/mistral-generate-text.1.json +22 -0
- package/src/__snapshots__/convert-to-mistral-chat-messages.test.ts.snap +57 -0
- package/src/__snapshots__/mistral-embedding-model.test.ts.snap +44 -0
- package/src/convert-mistral-usage.ts +46 -0
- package/src/convert-to-mistral-chat-messages.test.ts +372 -0
- package/src/convert-to-mistral-chat-messages.ts +163 -0
- package/src/get-response-metadata.ts +15 -0
- package/src/index.ts +7 -0
- package/src/map-mistral-finish-reason.ts +17 -0
- package/src/mistral-chat-language-model.test.ts +1755 -0
- package/src/mistral-chat-language-model.ts +580 -0
- package/src/mistral-chat-options.ts +63 -0
- package/src/mistral-chat-prompt.ts +46 -0
- package/src/mistral-embedding-model.test.ts +127 -0
- package/src/mistral-embedding-model.ts +94 -0
- package/src/mistral-embedding-options.ts +1 -0
- package/src/mistral-error.ts +17 -0
- package/src/mistral-prepare-tools.test.ts +178 -0
- package/src/mistral-prepare-tools.ts +97 -0
- package/src/mistral-provider.ts +147 -0
- package/src/version.ts +6 -0
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AI SDK - Mistral Provider
|
|
2
2
|
|
|
3
|
-
The [Mistral](https://
|
|
4
|
-
It creates language model objects that can be used with the `generateText`, `streamText`, `generateObject`, and `streamObject` AI functions.
|
|
3
|
+
The **[Mistral provider](https://ai-sdk.dev/providers/ai-sdk-providers/mistral)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the Mistral chat API.
|
|
5
4
|
|
|
6
5
|
## Setup
|
|
7
6
|
|
|
@@ -19,55 +18,18 @@ You can import the default provider instance `mistral` from `@ai-sdk/mistral`:
|
|
|
19
18
|
import { mistral } from '@ai-sdk/mistral';
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
## Example
|
|
23
22
|
|
|
24
23
|
```ts
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
const mistral = createMistral({
|
|
28
|
-
// custom settings
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
You can use the following optional settings to customize the Mistral provider instance:
|
|
33
|
-
|
|
34
|
-
- **baseURL** _string_
|
|
35
|
-
|
|
36
|
-
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
37
|
-
The default prefix is `https://api.mistral.ai/v1`.
|
|
38
|
-
|
|
39
|
-
- **apiKey** _string_
|
|
40
|
-
|
|
41
|
-
API key that is being send using the `Authorization` header.
|
|
42
|
-
It defaults to the `MISTRAL_API_KEY` environment variable.
|
|
43
|
-
|
|
44
|
-
- **headers** _Record<string,string>_
|
|
45
|
-
|
|
46
|
-
Custom headers to include in the requests.
|
|
47
|
-
|
|
48
|
-
## Models
|
|
49
|
-
|
|
50
|
-
You can create models that call the [Mistral chat API](https://docs.mistral.ai/api/#operation/createChatCompletion) using provider instance.
|
|
51
|
-
The first argument is the model id, e.g. `mistral-large-latest`.
|
|
52
|
-
Some Mistral chat models support tool calls.
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const model = mistral('mistral-large-latest');
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Mistral chat models also support additional model settings that are not part of the [standard call settings](/docs/ai-core/settings).
|
|
59
|
-
You can pass them as an options argument:
|
|
24
|
+
import { mistral } from '@ai-sdk/mistral';
|
|
25
|
+
import { generateText } from 'ai';
|
|
60
26
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
27
|
+
const { text } = await generateText({
|
|
28
|
+
model: mistral('mistral-large-latest'),
|
|
29
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
64
30
|
});
|
|
65
31
|
```
|
|
66
32
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
- **safePrompt** _boolean_
|
|
70
|
-
|
|
71
|
-
Whether to inject a safety prompt before all conversations.
|
|
33
|
+
## Documentation
|
|
72
34
|
|
|
73
|
-
|
|
35
|
+
Please check out the **[Mistral provider](https://ai-sdk.dev/providers/ai-sdk-providers/mistral)** for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,73 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
2
4
|
|
|
3
|
-
type MistralChatModelId = '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type MistralChatConfig = {
|
|
14
|
-
provider: string;
|
|
15
|
-
baseURL: string;
|
|
16
|
-
headers: () => Record<string, string | undefined>;
|
|
17
|
-
generateId: () => string;
|
|
18
|
-
};
|
|
19
|
-
declare class MistralChatLanguageModel implements LanguageModelV1 {
|
|
20
|
-
readonly specificationVersion = "v1";
|
|
21
|
-
readonly defaultObjectGenerationMode = "json";
|
|
22
|
-
readonly modelId: MistralChatModelId;
|
|
23
|
-
readonly settings: MistralChatSettings;
|
|
24
|
-
private readonly config;
|
|
25
|
-
constructor(modelId: MistralChatModelId, settings: MistralChatSettings, config: MistralChatConfig);
|
|
26
|
-
get provider(): string;
|
|
27
|
-
private getArgs;
|
|
28
|
-
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
|
29
|
-
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
|
30
|
-
}
|
|
5
|
+
type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-medium-latest' | 'mistral-medium-2508' | 'mistral-medium-2505' | 'mistral-small-latest' | 'pixtral-large-latest' | 'magistral-small-2507' | 'magistral-medium-2507' | 'magistral-small-2506' | 'magistral-medium-2506' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
|
|
6
|
+
declare const mistralLanguageModelOptions: z.ZodObject<{
|
|
7
|
+
safePrompt: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
documentImageLimit: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
documentPageLimit: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
|
|
31
15
|
|
|
32
16
|
type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
|
|
33
|
-
interface MistralEmbeddingSettings {
|
|
34
|
-
/**
|
|
35
|
-
Override the maximum number of embeddings per call.
|
|
36
|
-
*/
|
|
37
|
-
maxEmbeddingsPerCall?: number;
|
|
38
|
-
/**
|
|
39
|
-
Override the parallelism of embedding calls.
|
|
40
|
-
*/
|
|
41
|
-
supportsParallelCalls?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type MistralEmbeddingConfig = {
|
|
45
|
-
provider: string;
|
|
46
|
-
baseURL: string;
|
|
47
|
-
headers: () => Record<string, string | undefined>;
|
|
48
|
-
};
|
|
49
|
-
declare class MistralEmbeddingModel implements EmbeddingModelV1<string> {
|
|
50
|
-
readonly specificationVersion = "v1";
|
|
51
|
-
readonly modelId: MistralEmbeddingModelId;
|
|
52
|
-
private readonly config;
|
|
53
|
-
private readonly settings;
|
|
54
|
-
get provider(): string;
|
|
55
|
-
get maxEmbeddingsPerCall(): number;
|
|
56
|
-
get supportsParallelCalls(): boolean;
|
|
57
|
-
constructor(modelId: MistralEmbeddingModelId, settings: MistralEmbeddingSettings, config: MistralEmbeddingConfig);
|
|
58
|
-
doEmbed({ values, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
|
|
59
|
-
}
|
|
60
17
|
|
|
61
|
-
interface MistralProvider {
|
|
62
|
-
(modelId: MistralChatModelId
|
|
18
|
+
interface MistralProvider extends ProviderV3 {
|
|
19
|
+
(modelId: MistralChatModelId): LanguageModelV3;
|
|
63
20
|
/**
|
|
64
21
|
Creates a model for text generation.
|
|
65
22
|
*/
|
|
66
|
-
|
|
23
|
+
languageModel(modelId: MistralChatModelId): LanguageModelV3;
|
|
24
|
+
/**
|
|
25
|
+
Creates a model for text generation.
|
|
26
|
+
*/
|
|
27
|
+
chat(modelId: MistralChatModelId): LanguageModelV3;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a model for text embeddings.
|
|
30
|
+
*/
|
|
31
|
+
embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a model for text embeddings.
|
|
34
|
+
*/
|
|
35
|
+
embeddingModel: (modelId: MistralEmbeddingModelId) => EmbeddingModelV3;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `embedding` instead.
|
|
38
|
+
*/
|
|
39
|
+
textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
67
40
|
/**
|
|
68
|
-
|
|
41
|
+
* @deprecated Use `embeddingModel` instead.
|
|
69
42
|
*/
|
|
70
|
-
|
|
43
|
+
textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
71
44
|
}
|
|
72
45
|
interface MistralProviderSettings {
|
|
73
46
|
/**
|
|
@@ -76,10 +49,6 @@ interface MistralProviderSettings {
|
|
|
76
49
|
*/
|
|
77
50
|
baseURL?: string;
|
|
78
51
|
/**
|
|
79
|
-
@deprecated Use `baseURL` instead.
|
|
80
|
-
*/
|
|
81
|
-
baseUrl?: string;
|
|
82
|
-
/**
|
|
83
52
|
API key that is being send using the `Authorization` header.
|
|
84
53
|
It defaults to the `MISTRAL_API_KEY` environment variable.
|
|
85
54
|
*/
|
|
@@ -88,6 +57,11 @@ interface MistralProviderSettings {
|
|
|
88
57
|
Custom headers to include in the requests.
|
|
89
58
|
*/
|
|
90
59
|
headers?: Record<string, string>;
|
|
60
|
+
/**
|
|
61
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
62
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
63
|
+
*/
|
|
64
|
+
fetch?: FetchFunction;
|
|
91
65
|
generateId?: () => string;
|
|
92
66
|
}
|
|
93
67
|
/**
|
|
@@ -99,23 +73,6 @@ Default Mistral provider instance.
|
|
|
99
73
|
*/
|
|
100
74
|
declare const mistral: MistralProvider;
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
* @deprecated Use `createMistral` instead.
|
|
104
|
-
*/
|
|
105
|
-
declare class Mistral {
|
|
106
|
-
/**
|
|
107
|
-
* Base URL for the Mistral API calls.
|
|
108
|
-
*/
|
|
109
|
-
readonly baseURL: string;
|
|
110
|
-
readonly apiKey?: string;
|
|
111
|
-
readonly headers?: Record<string, string>;
|
|
112
|
-
private readonly generateId;
|
|
113
|
-
/**
|
|
114
|
-
* Creates a new Mistral provider instance.
|
|
115
|
-
*/
|
|
116
|
-
constructor(options?: MistralProviderSettings);
|
|
117
|
-
private get baseConfig();
|
|
118
|
-
chat(modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
|
|
119
|
-
}
|
|
76
|
+
declare const VERSION: string;
|
|
120
77
|
|
|
121
|
-
export {
|
|
78
|
+
export { type MistralLanguageModelOptions, type MistralProvider, type MistralProviderSettings, VERSION, createMistral, mistral };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,73 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
2
4
|
|
|
3
|
-
type MistralChatModelId = '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type MistralChatConfig = {
|
|
14
|
-
provider: string;
|
|
15
|
-
baseURL: string;
|
|
16
|
-
headers: () => Record<string, string | undefined>;
|
|
17
|
-
generateId: () => string;
|
|
18
|
-
};
|
|
19
|
-
declare class MistralChatLanguageModel implements LanguageModelV1 {
|
|
20
|
-
readonly specificationVersion = "v1";
|
|
21
|
-
readonly defaultObjectGenerationMode = "json";
|
|
22
|
-
readonly modelId: MistralChatModelId;
|
|
23
|
-
readonly settings: MistralChatSettings;
|
|
24
|
-
private readonly config;
|
|
25
|
-
constructor(modelId: MistralChatModelId, settings: MistralChatSettings, config: MistralChatConfig);
|
|
26
|
-
get provider(): string;
|
|
27
|
-
private getArgs;
|
|
28
|
-
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
|
29
|
-
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
|
30
|
-
}
|
|
5
|
+
type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-medium-latest' | 'mistral-medium-2508' | 'mistral-medium-2505' | 'mistral-small-latest' | 'pixtral-large-latest' | 'magistral-small-2507' | 'magistral-medium-2507' | 'magistral-small-2506' | 'magistral-medium-2506' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
|
|
6
|
+
declare const mistralLanguageModelOptions: z.ZodObject<{
|
|
7
|
+
safePrompt: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
documentImageLimit: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
documentPageLimit: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
structuredOutputs: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
|
|
31
15
|
|
|
32
16
|
type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
|
|
33
|
-
interface MistralEmbeddingSettings {
|
|
34
|
-
/**
|
|
35
|
-
Override the maximum number of embeddings per call.
|
|
36
|
-
*/
|
|
37
|
-
maxEmbeddingsPerCall?: number;
|
|
38
|
-
/**
|
|
39
|
-
Override the parallelism of embedding calls.
|
|
40
|
-
*/
|
|
41
|
-
supportsParallelCalls?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type MistralEmbeddingConfig = {
|
|
45
|
-
provider: string;
|
|
46
|
-
baseURL: string;
|
|
47
|
-
headers: () => Record<string, string | undefined>;
|
|
48
|
-
};
|
|
49
|
-
declare class MistralEmbeddingModel implements EmbeddingModelV1<string> {
|
|
50
|
-
readonly specificationVersion = "v1";
|
|
51
|
-
readonly modelId: MistralEmbeddingModelId;
|
|
52
|
-
private readonly config;
|
|
53
|
-
private readonly settings;
|
|
54
|
-
get provider(): string;
|
|
55
|
-
get maxEmbeddingsPerCall(): number;
|
|
56
|
-
get supportsParallelCalls(): boolean;
|
|
57
|
-
constructor(modelId: MistralEmbeddingModelId, settings: MistralEmbeddingSettings, config: MistralEmbeddingConfig);
|
|
58
|
-
doEmbed({ values, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
|
|
59
|
-
}
|
|
60
17
|
|
|
61
|
-
interface MistralProvider {
|
|
62
|
-
(modelId: MistralChatModelId
|
|
18
|
+
interface MistralProvider extends ProviderV3 {
|
|
19
|
+
(modelId: MistralChatModelId): LanguageModelV3;
|
|
63
20
|
/**
|
|
64
21
|
Creates a model for text generation.
|
|
65
22
|
*/
|
|
66
|
-
|
|
23
|
+
languageModel(modelId: MistralChatModelId): LanguageModelV3;
|
|
24
|
+
/**
|
|
25
|
+
Creates a model for text generation.
|
|
26
|
+
*/
|
|
27
|
+
chat(modelId: MistralChatModelId): LanguageModelV3;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a model for text embeddings.
|
|
30
|
+
*/
|
|
31
|
+
embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a model for text embeddings.
|
|
34
|
+
*/
|
|
35
|
+
embeddingModel: (modelId: MistralEmbeddingModelId) => EmbeddingModelV3;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `embedding` instead.
|
|
38
|
+
*/
|
|
39
|
+
textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
67
40
|
/**
|
|
68
|
-
|
|
41
|
+
* @deprecated Use `embeddingModel` instead.
|
|
69
42
|
*/
|
|
70
|
-
|
|
43
|
+
textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV3;
|
|
71
44
|
}
|
|
72
45
|
interface MistralProviderSettings {
|
|
73
46
|
/**
|
|
@@ -76,10 +49,6 @@ interface MistralProviderSettings {
|
|
|
76
49
|
*/
|
|
77
50
|
baseURL?: string;
|
|
78
51
|
/**
|
|
79
|
-
@deprecated Use `baseURL` instead.
|
|
80
|
-
*/
|
|
81
|
-
baseUrl?: string;
|
|
82
|
-
/**
|
|
83
52
|
API key that is being send using the `Authorization` header.
|
|
84
53
|
It defaults to the `MISTRAL_API_KEY` environment variable.
|
|
85
54
|
*/
|
|
@@ -88,6 +57,11 @@ interface MistralProviderSettings {
|
|
|
88
57
|
Custom headers to include in the requests.
|
|
89
58
|
*/
|
|
90
59
|
headers?: Record<string, string>;
|
|
60
|
+
/**
|
|
61
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
62
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
63
|
+
*/
|
|
64
|
+
fetch?: FetchFunction;
|
|
91
65
|
generateId?: () => string;
|
|
92
66
|
}
|
|
93
67
|
/**
|
|
@@ -99,23 +73,6 @@ Default Mistral provider instance.
|
|
|
99
73
|
*/
|
|
100
74
|
declare const mistral: MistralProvider;
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
* @deprecated Use `createMistral` instead.
|
|
104
|
-
*/
|
|
105
|
-
declare class Mistral {
|
|
106
|
-
/**
|
|
107
|
-
* Base URL for the Mistral API calls.
|
|
108
|
-
*/
|
|
109
|
-
readonly baseURL: string;
|
|
110
|
-
readonly apiKey?: string;
|
|
111
|
-
readonly headers?: Record<string, string>;
|
|
112
|
-
private readonly generateId;
|
|
113
|
-
/**
|
|
114
|
-
* Creates a new Mistral provider instance.
|
|
115
|
-
*/
|
|
116
|
-
constructor(options?: MistralProviderSettings);
|
|
117
|
-
private get baseConfig();
|
|
118
|
-
chat(modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
|
|
119
|
-
}
|
|
76
|
+
declare const VERSION: string;
|
|
120
77
|
|
|
121
|
-
export {
|
|
78
|
+
export { type MistralLanguageModelOptions, type MistralProvider, type MistralProviderSettings, VERSION, createMistral, mistral };
|