@ai-sdk/mistral 0.0.0-85f9a635-20240518005312

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Vercel AI SDK - Mistral Provider
2
+
3
+ The [Mistral](https://mistral.ai/) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the Mistral chat API.
4
+ It creates language model objects that can be used with the `generateText`, `streamText`, `generateObject`, and `streamObject` AI functions.
5
+
6
+ ## Setup
7
+
8
+ The Mistral provider is available in the `@ai-sdk/mistral` module. You can install it with
9
+
10
+ ```bash
11
+ npm i @ai-sdk/mistral
12
+ ```
13
+
14
+ ## Provider Instance
15
+
16
+ You can import the default provider instance `mistral` from `@ai-sdk/mistral`:
17
+
18
+ ```ts
19
+ import { mistral } from '@ai-sdk/mistral';
20
+ ```
21
+
22
+ If you need a customized setup, you can import `createMistral` from `@ai-sdk/mistral` and create a provider instance with your settings:
23
+
24
+ ```ts
25
+ import { createMistral } from '@ai-sdk/mistral';
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:
60
+
61
+ ```ts
62
+ const model = mistral('mistral-large-latest', {
63
+ safePrompt: true, // optional safety prompt injection
64
+ });
65
+ ```
66
+
67
+ The following optional settings are available for Mistral models:
68
+
69
+ - **safePrompt** _boolean_
70
+
71
+ Whether to inject a safety prompt before all conversations.
72
+
73
+ Defaults to `false`.
@@ -0,0 +1,121 @@
1
+ import { LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
2
+
3
+ type MistralChatModelId = 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | 'mistral-small-latest' | 'mistral-medium-latest' | 'mistral-large-latest' | (string & {});
4
+ interface MistralChatSettings {
5
+ /**
6
+ Whether to inject a safety prompt before all conversations.
7
+
8
+ Defaults to `false`.
9
+ */
10
+ safePrompt?: boolean;
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
+ }
31
+
32
+ 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
+
61
+ interface MistralProvider {
62
+ (modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
63
+ /**
64
+ Creates a model for text generation.
65
+ */
66
+ chat(modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
67
+ /**
68
+ Creates a model for text embeddings.
69
+ */
70
+ embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): MistralEmbeddingModel;
71
+ }
72
+ interface MistralProviderSettings {
73
+ /**
74
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
75
+ The default prefix is `https://api.mistral.ai/v1`.
76
+ */
77
+ baseURL?: string;
78
+ /**
79
+ @deprecated Use `baseURL` instead.
80
+ */
81
+ baseUrl?: string;
82
+ /**
83
+ API key that is being send using the `Authorization` header.
84
+ It defaults to the `MISTRAL_API_KEY` environment variable.
85
+ */
86
+ apiKey?: string;
87
+ /**
88
+ Custom headers to include in the requests.
89
+ */
90
+ headers?: Record<string, string>;
91
+ generateId?: () => string;
92
+ }
93
+ /**
94
+ Create a Mistral AI provider instance.
95
+ */
96
+ declare function createMistral(options?: MistralProviderSettings): MistralProvider;
97
+ /**
98
+ Default Mistral provider instance.
99
+ */
100
+ declare const mistral: MistralProvider;
101
+
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
+ }
120
+
121
+ export { Mistral, type MistralProvider, type MistralProviderSettings, createMistral, mistral };
@@ -0,0 +1,121 @@
1
+ import { LanguageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
2
+
3
+ type MistralChatModelId = 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | 'mistral-small-latest' | 'mistral-medium-latest' | 'mistral-large-latest' | (string & {});
4
+ interface MistralChatSettings {
5
+ /**
6
+ Whether to inject a safety prompt before all conversations.
7
+
8
+ Defaults to `false`.
9
+ */
10
+ safePrompt?: boolean;
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
+ }
31
+
32
+ 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
+
61
+ interface MistralProvider {
62
+ (modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
63
+ /**
64
+ Creates a model for text generation.
65
+ */
66
+ chat(modelId: MistralChatModelId, settings?: MistralChatSettings): MistralChatLanguageModel;
67
+ /**
68
+ Creates a model for text embeddings.
69
+ */
70
+ embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): MistralEmbeddingModel;
71
+ }
72
+ interface MistralProviderSettings {
73
+ /**
74
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
75
+ The default prefix is `https://api.mistral.ai/v1`.
76
+ */
77
+ baseURL?: string;
78
+ /**
79
+ @deprecated Use `baseURL` instead.
80
+ */
81
+ baseUrl?: string;
82
+ /**
83
+ API key that is being send using the `Authorization` header.
84
+ It defaults to the `MISTRAL_API_KEY` environment variable.
85
+ */
86
+ apiKey?: string;
87
+ /**
88
+ Custom headers to include in the requests.
89
+ */
90
+ headers?: Record<string, string>;
91
+ generateId?: () => string;
92
+ }
93
+ /**
94
+ Create a Mistral AI provider instance.
95
+ */
96
+ declare function createMistral(options?: MistralProviderSettings): MistralProvider;
97
+ /**
98
+ Default Mistral provider instance.
99
+ */
100
+ declare const mistral: MistralProvider;
101
+
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
+ }
120
+
121
+ export { Mistral, type MistralProvider, type MistralProviderSettings, createMistral, mistral };