@core-ai/mistral 0.17.0 → 0.19.0
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/dist/index.d.ts +1 -1
- package/dist/index.js +98 -18
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ type MistralProvider = {
|
|
|
14
14
|
declare function createMistral(options?: MistralProviderOptions$1): MistralProvider;
|
|
15
15
|
|
|
16
16
|
type MistralModelCapabilities = ModelCapabilities;
|
|
17
|
-
declare function getMistralModelCapabilities(
|
|
17
|
+
declare function getMistralModelCapabilities(modelId: string): MistralModelCapabilities;
|
|
18
18
|
|
|
19
19
|
declare const mistralGenerateProviderOptionsSchema: z.ZodObject<{
|
|
20
20
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
asObject,
|
|
16
16
|
getProviderMetadata,
|
|
17
17
|
safeParseJsonObject,
|
|
18
|
+
ValidationError,
|
|
19
|
+
validateInputModalities,
|
|
18
20
|
zodSchemaToJsonSchema
|
|
19
21
|
} from "@core-ai/core-ai";
|
|
20
22
|
|
|
@@ -51,16 +53,82 @@ function parseMistralEmbedProviderOptions(providerOptions) {
|
|
|
51
53
|
var mistralProviderOptionsSchema = mistralGenerateProviderOptionsSchema;
|
|
52
54
|
|
|
53
55
|
// src/model-capabilities.ts
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
import {
|
|
57
|
+
getRegisteredModelCapabilities,
|
|
58
|
+
MULTIMODAL_INPUT_MODALITIES,
|
|
59
|
+
stripModelDateSuffix,
|
|
60
|
+
TEXT_ONLY_MODALITIES,
|
|
61
|
+
UNKNOWN_MODEL
|
|
62
|
+
} from "@core-ai/core-ai";
|
|
63
|
+
var MISTRAL_VERSION_SUFFIX_PATTERN = /-(?:latest|\d{4})$/;
|
|
64
|
+
function createCapabilities(modalities) {
|
|
65
|
+
return {
|
|
66
|
+
reasoning: {
|
|
67
|
+
mode: "unsupported",
|
|
68
|
+
supportedEfforts: [],
|
|
69
|
+
restrictsSamplingParams: false,
|
|
70
|
+
supportedToolChoices: ["auto", "none", "required", "tool"]
|
|
71
|
+
},
|
|
72
|
+
modalities
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
var VISION_CAPABILITIES = createCapabilities(MULTIMODAL_INPUT_MODALITIES);
|
|
76
|
+
var TEXT_ONLY_CAPABILITIES = createCapabilities(TEXT_ONLY_MODALITIES);
|
|
77
|
+
var FAMILY_CAPABILITIES = {
|
|
78
|
+
"mistral-large": VISION_CAPABILITIES,
|
|
79
|
+
"mistral-medium": VISION_CAPABILITIES,
|
|
80
|
+
"mistral-small": VISION_CAPABILITIES,
|
|
81
|
+
"magistral-medium": VISION_CAPABILITIES,
|
|
82
|
+
"magistral-small": VISION_CAPABILITIES,
|
|
83
|
+
"pixtral-large": VISION_CAPABILITIES,
|
|
84
|
+
"pixtral-12b": VISION_CAPABILITIES,
|
|
85
|
+
"ministral-3b": VISION_CAPABILITIES,
|
|
86
|
+
"ministral-8b": VISION_CAPABILITIES,
|
|
87
|
+
"ministral-14b": VISION_CAPABILITIES,
|
|
88
|
+
codestral: TEXT_ONLY_CAPABILITIES,
|
|
89
|
+
"codestral-mamba": TEXT_ONLY_CAPABILITIES,
|
|
90
|
+
devstral: TEXT_ONLY_CAPABILITIES,
|
|
91
|
+
"devstral-medium": TEXT_ONLY_CAPABILITIES,
|
|
92
|
+
"devstral-small": TEXT_ONLY_CAPABILITIES,
|
|
93
|
+
"open-mistral-7b": TEXT_ONLY_CAPABILITIES,
|
|
94
|
+
"open-mistral-nemo": TEXT_ONLY_CAPABILITIES,
|
|
95
|
+
"open-mixtral-8x7b": TEXT_ONLY_CAPABILITIES,
|
|
96
|
+
"open-mixtral-8x22b": TEXT_ONLY_CAPABILITIES,
|
|
97
|
+
[UNKNOWN_MODEL]: VISION_CAPABILITIES
|
|
98
|
+
};
|
|
99
|
+
var VERSIONED_CAPABILITIES = {
|
|
100
|
+
// Vision arrived with Mistral Large 3 (`-2512`).
|
|
101
|
+
"mistral-large-2402": TEXT_ONLY_CAPABILITIES,
|
|
102
|
+
"mistral-large-2407": TEXT_ONLY_CAPABILITIES,
|
|
103
|
+
"mistral-large-2411": TEXT_ONLY_CAPABILITIES,
|
|
104
|
+
// Vision arrived with Mistral Medium 3 (`-2505`).
|
|
105
|
+
"mistral-medium-2312": TEXT_ONLY_CAPABILITIES,
|
|
106
|
+
// Vision arrived with Mistral Small 3.1 (`-2503`).
|
|
107
|
+
"mistral-small-2402": TEXT_ONLY_CAPABILITIES,
|
|
108
|
+
"mistral-small-2409": TEXT_ONLY_CAPABILITIES,
|
|
109
|
+
"mistral-small-2501": TEXT_ONLY_CAPABILITIES,
|
|
110
|
+
// Vision arrived with Magistral 1.2 (`-2509`).
|
|
111
|
+
"magistral-medium-2506": TEXT_ONLY_CAPABILITIES,
|
|
112
|
+
"magistral-medium-2507": TEXT_ONLY_CAPABILITIES,
|
|
113
|
+
"magistral-small-2506": TEXT_ONLY_CAPABILITIES,
|
|
114
|
+
"magistral-small-2507": TEXT_ONLY_CAPABILITIES,
|
|
115
|
+
// Vision arrived with Ministral 3 (`-2512`).
|
|
116
|
+
"ministral-3b-2410": TEXT_ONLY_CAPABILITIES,
|
|
117
|
+
"ministral-8b-2410": TEXT_ONLY_CAPABILITIES
|
|
118
|
+
};
|
|
119
|
+
var MISTRAL_MODEL_CAPABILITIES = {
|
|
120
|
+
...VERSIONED_CAPABILITIES,
|
|
121
|
+
...FAMILY_CAPABILITIES
|
|
61
122
|
};
|
|
62
|
-
function getMistralModelCapabilities(
|
|
63
|
-
|
|
123
|
+
function getMistralModelCapabilities(modelId) {
|
|
124
|
+
const registry = MISTRAL_MODEL_CAPABILITIES;
|
|
125
|
+
return registry[modelId] ?? getRegisteredModelCapabilities(registry, normalizeModelId(modelId));
|
|
126
|
+
}
|
|
127
|
+
function normalizeModelId(modelId) {
|
|
128
|
+
return stripModelDateSuffix(modelId).replace(
|
|
129
|
+
MISTRAL_VERSION_SUFFIX_PATTERN,
|
|
130
|
+
""
|
|
131
|
+
);
|
|
64
132
|
}
|
|
65
133
|
|
|
66
134
|
// src/chat-adapter.ts
|
|
@@ -153,6 +221,9 @@ function convertUserContentPart(part) {
|
|
|
153
221
|
}
|
|
154
222
|
};
|
|
155
223
|
}
|
|
224
|
+
if (part.type === "audio") {
|
|
225
|
+
throw new ValidationError("Mistral does not support audio input");
|
|
226
|
+
}
|
|
156
227
|
return {
|
|
157
228
|
type: "document_url",
|
|
158
229
|
documentUrl: `data:${part.mimeType};base64,${part.data}`,
|
|
@@ -208,27 +279,34 @@ function createStructuredOutputOptions(options) {
|
|
|
208
279
|
signal: options.signal
|
|
209
280
|
};
|
|
210
281
|
}
|
|
211
|
-
function createGenerateRequest(modelId, options) {
|
|
282
|
+
function createGenerateRequest(modelId, options, adapterOptions = {}) {
|
|
212
283
|
const mistralOptions = parseMistralGenerateProviderOptions(
|
|
213
284
|
options.providerOptions
|
|
214
285
|
);
|
|
215
286
|
const baseRequest = {
|
|
216
|
-
...createRequestBase(modelId, options)
|
|
287
|
+
...createRequestBase(modelId, options, adapterOptions)
|
|
217
288
|
};
|
|
218
289
|
return mapMistralProviderOptionsToRequest(baseRequest, mistralOptions);
|
|
219
290
|
}
|
|
220
|
-
function createStreamRequest(modelId, options) {
|
|
291
|
+
function createStreamRequest(modelId, options, adapterOptions = {}) {
|
|
221
292
|
const mistralOptions = parseMistralGenerateProviderOptions(
|
|
222
293
|
options.providerOptions
|
|
223
294
|
);
|
|
224
295
|
const baseRequest = {
|
|
225
|
-
...createRequestBase(modelId, options),
|
|
296
|
+
...createRequestBase(modelId, options, adapterOptions),
|
|
226
297
|
stream: true
|
|
227
298
|
};
|
|
228
299
|
return mapMistralProviderOptionsToRequest(baseRequest, mistralOptions);
|
|
229
300
|
}
|
|
230
|
-
function createRequestBase(modelId, options) {
|
|
231
|
-
const capabilities = getMistralModelCapabilities(modelId);
|
|
301
|
+
function createRequestBase(modelId, options, adapterOptions) {
|
|
302
|
+
const capabilities = adapterOptions.capabilities ?? getMistralModelCapabilities(modelId);
|
|
303
|
+
const providerId = adapterOptions.providerId ?? "mistral";
|
|
304
|
+
validateInputModalities({
|
|
305
|
+
messages: options.messages,
|
|
306
|
+
capabilities,
|
|
307
|
+
modelId,
|
|
308
|
+
providerId
|
|
309
|
+
});
|
|
232
310
|
return {
|
|
233
311
|
model: modelId,
|
|
234
312
|
messages: convertMessages(options.messages, {
|
|
@@ -747,6 +825,8 @@ function parseErrorBody(error) {
|
|
|
747
825
|
// src/chat-model.ts
|
|
748
826
|
function createMistralChatModel(client, modelId) {
|
|
749
827
|
const provider = "mistral";
|
|
828
|
+
const capabilities = getMistralModelCapabilities(modelId);
|
|
829
|
+
const adapterOptions = { capabilities, providerId: provider };
|
|
750
830
|
async function callMistralChatApi(call) {
|
|
751
831
|
try {
|
|
752
832
|
return await call();
|
|
@@ -755,14 +835,14 @@ function createMistralChatModel(client, modelId) {
|
|
|
755
835
|
}
|
|
756
836
|
}
|
|
757
837
|
async function generateChat(options) {
|
|
758
|
-
const request = createGenerateRequest(modelId, options);
|
|
838
|
+
const request = createGenerateRequest(modelId, options, adapterOptions);
|
|
759
839
|
const response = await callMistralChatApi(
|
|
760
840
|
() => client.chat.complete(request, { signal: options.signal })
|
|
761
841
|
);
|
|
762
842
|
return mapGenerateResponse(response);
|
|
763
843
|
}
|
|
764
844
|
async function streamChat(options) {
|
|
765
|
-
const request = createStreamRequest(modelId, options);
|
|
845
|
+
const request = createStreamRequest(modelId, options, adapterOptions);
|
|
766
846
|
return createChatStream(
|
|
767
847
|
async () => transformStream(
|
|
768
848
|
await callMistralChatApi(
|
|
@@ -777,7 +857,7 @@ function createMistralChatModel(client, modelId) {
|
|
|
777
857
|
return {
|
|
778
858
|
provider,
|
|
779
859
|
modelId,
|
|
780
|
-
capabilities
|
|
860
|
+
capabilities,
|
|
781
861
|
generate: generateChat,
|
|
782
862
|
stream: streamChat,
|
|
783
863
|
async generateObject(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/mistral",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Mistral provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:watch": "vitest"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@core-ai/core-ai": "^0.
|
|
46
|
+
"@core-ai/core-ai": "^0.19.0",
|
|
47
47
|
"@mistralai/mistralai": "^2.4.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|