@ai-sdk/mistral 3.0.11 → 3.0.13
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 +16 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -5
- package/src/__fixtures__/mistral-generate-text.1.json +0 -22
- package/src/__snapshots__/convert-to-mistral-chat-messages.test.ts.snap +0 -57
- package/src/__snapshots__/mistral-embedding-model.test.ts.snap +0 -44
- package/src/convert-to-mistral-chat-messages.test.ts +0 -372
- package/src/mistral-chat-language-model.test.ts +0 -1755
- package/src/mistral-embedding-model.test.ts +0 -127
- package/src/mistral-prepare-tools.test.ts +0 -178
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { EmbeddingModelV3Embedding } from '@ai-sdk/provider';
|
|
2
|
-
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
3
|
-
import { createMistral } from './mistral-provider';
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
vi.mock('./version', () => ({
|
|
7
|
-
VERSION: '0.0.0-test',
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
const dummyEmbeddings = [
|
|
11
|
-
[0.1, 0.2, 0.3, 0.4, 0.5],
|
|
12
|
-
[0.6, 0.7, 0.8, 0.9, 1.0],
|
|
13
|
-
];
|
|
14
|
-
const testValues = ['sunny day at the beach', 'rainy day in the city'];
|
|
15
|
-
|
|
16
|
-
const provider = createMistral({ apiKey: 'test-api-key' });
|
|
17
|
-
const model = provider.embeddingModel('mistral-embed');
|
|
18
|
-
|
|
19
|
-
const server = createTestServer({
|
|
20
|
-
'https://api.mistral.ai/v1/embeddings': {},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('doEmbed', () => {
|
|
24
|
-
function prepareJsonResponse({
|
|
25
|
-
embeddings = dummyEmbeddings,
|
|
26
|
-
usage = { prompt_tokens: 8, total_tokens: 8 },
|
|
27
|
-
headers,
|
|
28
|
-
}: {
|
|
29
|
-
embeddings?: EmbeddingModelV3Embedding[];
|
|
30
|
-
usage?: { prompt_tokens: number; total_tokens: number };
|
|
31
|
-
headers?: Record<string, string>;
|
|
32
|
-
} = {}) {
|
|
33
|
-
server.urls['https://api.mistral.ai/v1/embeddings'].response = {
|
|
34
|
-
type: 'json-value',
|
|
35
|
-
headers,
|
|
36
|
-
body: {
|
|
37
|
-
id: 'b322cfc2b9d34e2f8e14fc99874faee5',
|
|
38
|
-
object: 'list',
|
|
39
|
-
data: embeddings.map((embedding, i) => ({
|
|
40
|
-
object: 'embedding',
|
|
41
|
-
embedding,
|
|
42
|
-
index: i,
|
|
43
|
-
})),
|
|
44
|
-
model: 'mistral-embed',
|
|
45
|
-
usage,
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
it('should extract embedding', async () => {
|
|
51
|
-
prepareJsonResponse();
|
|
52
|
-
|
|
53
|
-
const { embeddings } = await model.doEmbed({ values: testValues });
|
|
54
|
-
|
|
55
|
-
expect(embeddings).toStrictEqual(dummyEmbeddings);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should extract usage', async () => {
|
|
59
|
-
prepareJsonResponse({
|
|
60
|
-
usage: { prompt_tokens: 20, total_tokens: 20 },
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const { usage } = await model.doEmbed({ values: testValues });
|
|
64
|
-
|
|
65
|
-
expect(usage).toStrictEqual({ tokens: 20 });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should expose the raw response', async () => {
|
|
69
|
-
prepareJsonResponse({
|
|
70
|
-
headers: { 'test-header': 'test-value' },
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const { response } = await model.doEmbed({ values: testValues });
|
|
74
|
-
|
|
75
|
-
expect(response?.headers).toStrictEqual({
|
|
76
|
-
// default headers:
|
|
77
|
-
'content-length': '267',
|
|
78
|
-
'content-type': 'application/json',
|
|
79
|
-
|
|
80
|
-
// custom header
|
|
81
|
-
'test-header': 'test-value',
|
|
82
|
-
});
|
|
83
|
-
expect(response).toMatchSnapshot();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should pass the model and the values', async () => {
|
|
87
|
-
prepareJsonResponse();
|
|
88
|
-
|
|
89
|
-
await model.doEmbed({ values: testValues });
|
|
90
|
-
|
|
91
|
-
expect(await server.calls[0].requestBodyJson).toStrictEqual({
|
|
92
|
-
model: 'mistral-embed',
|
|
93
|
-
input: testValues,
|
|
94
|
-
encoding_format: 'float',
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should pass headers', async () => {
|
|
99
|
-
prepareJsonResponse();
|
|
100
|
-
|
|
101
|
-
const provider = createMistral({
|
|
102
|
-
apiKey: 'test-api-key',
|
|
103
|
-
headers: {
|
|
104
|
-
'Custom-Provider-Header': 'provider-header-value',
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
await provider.embedding('mistral-embed').doEmbed({
|
|
109
|
-
values: testValues,
|
|
110
|
-
headers: {
|
|
111
|
-
'Custom-Request-Header': 'request-header-value',
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const requestHeaders = server.calls[0].requestHeaders;
|
|
116
|
-
|
|
117
|
-
expect(requestHeaders).toStrictEqual({
|
|
118
|
-
authorization: 'Bearer test-api-key',
|
|
119
|
-
'content-type': 'application/json',
|
|
120
|
-
'custom-provider-header': 'provider-header-value',
|
|
121
|
-
'custom-request-header': 'request-header-value',
|
|
122
|
-
});
|
|
123
|
-
expect(server.calls[0].requestUserAgent).toContain(
|
|
124
|
-
`ai-sdk/mistral/0.0.0-test`,
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { prepareTools } from './mistral-prepare-tools';
|
|
3
|
-
|
|
4
|
-
describe('prepareTools', () => {
|
|
5
|
-
it('should pass through strict mode when strict is true', () => {
|
|
6
|
-
const result = prepareTools({
|
|
7
|
-
tools: [
|
|
8
|
-
{
|
|
9
|
-
type: 'function',
|
|
10
|
-
name: 'testFunction',
|
|
11
|
-
description: 'A test function',
|
|
12
|
-
inputSchema: { type: 'object', properties: {} },
|
|
13
|
-
strict: true,
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(result).toMatchInlineSnapshot(`
|
|
19
|
-
{
|
|
20
|
-
"toolChoice": undefined,
|
|
21
|
-
"toolWarnings": [],
|
|
22
|
-
"tools": [
|
|
23
|
-
{
|
|
24
|
-
"function": {
|
|
25
|
-
"description": "A test function",
|
|
26
|
-
"name": "testFunction",
|
|
27
|
-
"parameters": {
|
|
28
|
-
"properties": {},
|
|
29
|
-
"type": "object",
|
|
30
|
-
},
|
|
31
|
-
"strict": true,
|
|
32
|
-
},
|
|
33
|
-
"type": "function",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
}
|
|
37
|
-
`);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should pass through strict mode when strict is false', () => {
|
|
41
|
-
const result = prepareTools({
|
|
42
|
-
tools: [
|
|
43
|
-
{
|
|
44
|
-
type: 'function',
|
|
45
|
-
name: 'testFunction',
|
|
46
|
-
description: 'A test function',
|
|
47
|
-
inputSchema: { type: 'object', properties: {} },
|
|
48
|
-
strict: false,
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(result).toMatchInlineSnapshot(`
|
|
54
|
-
{
|
|
55
|
-
"toolChoice": undefined,
|
|
56
|
-
"toolWarnings": [],
|
|
57
|
-
"tools": [
|
|
58
|
-
{
|
|
59
|
-
"function": {
|
|
60
|
-
"description": "A test function",
|
|
61
|
-
"name": "testFunction",
|
|
62
|
-
"parameters": {
|
|
63
|
-
"properties": {},
|
|
64
|
-
"type": "object",
|
|
65
|
-
},
|
|
66
|
-
"strict": false,
|
|
67
|
-
},
|
|
68
|
-
"type": "function",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
}
|
|
72
|
-
`);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should not include strict mode when strict is undefined', () => {
|
|
76
|
-
const result = prepareTools({
|
|
77
|
-
tools: [
|
|
78
|
-
{
|
|
79
|
-
type: 'function',
|
|
80
|
-
name: 'testFunction',
|
|
81
|
-
description: 'A test function',
|
|
82
|
-
inputSchema: { type: 'object', properties: {} },
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
expect(result).toMatchInlineSnapshot(`
|
|
88
|
-
{
|
|
89
|
-
"toolChoice": undefined,
|
|
90
|
-
"toolWarnings": [],
|
|
91
|
-
"tools": [
|
|
92
|
-
{
|
|
93
|
-
"function": {
|
|
94
|
-
"description": "A test function",
|
|
95
|
-
"name": "testFunction",
|
|
96
|
-
"parameters": {
|
|
97
|
-
"properties": {},
|
|
98
|
-
"type": "object",
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
"type": "function",
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
}
|
|
105
|
-
`);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should pass through strict mode for multiple tools with different strict settings', () => {
|
|
109
|
-
const result = prepareTools({
|
|
110
|
-
tools: [
|
|
111
|
-
{
|
|
112
|
-
type: 'function',
|
|
113
|
-
name: 'strictTool',
|
|
114
|
-
description: 'A strict tool',
|
|
115
|
-
inputSchema: { type: 'object', properties: {} },
|
|
116
|
-
strict: true,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
type: 'function',
|
|
120
|
-
name: 'nonStrictTool',
|
|
121
|
-
description: 'A non-strict tool',
|
|
122
|
-
inputSchema: { type: 'object', properties: {} },
|
|
123
|
-
strict: false,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
type: 'function',
|
|
127
|
-
name: 'defaultTool',
|
|
128
|
-
description: 'A tool without strict setting',
|
|
129
|
-
inputSchema: { type: 'object', properties: {} },
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(result).toMatchInlineSnapshot(`
|
|
135
|
-
{
|
|
136
|
-
"toolChoice": undefined,
|
|
137
|
-
"toolWarnings": [],
|
|
138
|
-
"tools": [
|
|
139
|
-
{
|
|
140
|
-
"function": {
|
|
141
|
-
"description": "A strict tool",
|
|
142
|
-
"name": "strictTool",
|
|
143
|
-
"parameters": {
|
|
144
|
-
"properties": {},
|
|
145
|
-
"type": "object",
|
|
146
|
-
},
|
|
147
|
-
"strict": true,
|
|
148
|
-
},
|
|
149
|
-
"type": "function",
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
"function": {
|
|
153
|
-
"description": "A non-strict tool",
|
|
154
|
-
"name": "nonStrictTool",
|
|
155
|
-
"parameters": {
|
|
156
|
-
"properties": {},
|
|
157
|
-
"type": "object",
|
|
158
|
-
},
|
|
159
|
-
"strict": false,
|
|
160
|
-
},
|
|
161
|
-
"type": "function",
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
"function": {
|
|
165
|
-
"description": "A tool without strict setting",
|
|
166
|
-
"name": "defaultTool",
|
|
167
|
-
"parameters": {
|
|
168
|
-
"properties": {},
|
|
169
|
-
"type": "object",
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
"type": "function",
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
}
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
});
|