@ai-sdk/cohere 4.0.89 → 4.0.90
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 +9 -0
- package/dist/index.d.ts +92 -207
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +219 -82
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
- package/src/cohere-model-catalog.ts +223 -89
|
@@ -103,56 +103,139 @@ type CohereModelEntry = ModelEntry<{
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
/**
|
|
107
|
+
* One row of the language model matrix. Every capability that differs between
|
|
108
|
+
* models is one flat cell, and every listed model fills in every cell. Nothing
|
|
109
|
+
* is derived from the model ID.
|
|
110
|
+
*
|
|
111
|
+
* Facts that depend on each other share one cell, so a row cannot contradict
|
|
112
|
+
* itself: a cell is a single value, one of a fixed set of values, or the list
|
|
113
|
+
* of what the model supports.
|
|
114
|
+
*/
|
|
115
|
+
export type CohereLanguageModelRow = {
|
|
116
|
+
image: ModelCapability;
|
|
117
|
+
objectGeneration: ModelCapability;
|
|
118
|
+
/**
|
|
119
|
+
* `false`: the model does not call function tools. Otherwise it does, and
|
|
120
|
+
* the list holds what it supports on top of that: `streaming` means it
|
|
121
|
+
* also calls tools in a streamed response. `'unknown'`: not documented.
|
|
122
|
+
*/
|
|
123
|
+
functionTools: 'unknown' | false | readonly 'streaming'[];
|
|
124
|
+
/** Reasons, and accepts the `thinking` provider option. */
|
|
125
|
+
reasoning: ModelCapability;
|
|
111
126
|
};
|
|
112
127
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
'command-a-03-2025':
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
'command-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
'command-
|
|
131
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Language model matrix: model IDs by capability. To add a model, add a row
|
|
130
|
+
* and fill in every column.
|
|
131
|
+
*/
|
|
132
|
+
const languageModelDefinitions = {
|
|
133
|
+
'command-a-03-2025': {
|
|
134
|
+
image: false,
|
|
135
|
+
objectGeneration: true,
|
|
136
|
+
functionTools: ['streaming'],
|
|
137
|
+
reasoning: 'unknown',
|
|
138
|
+
},
|
|
139
|
+
'command-a-reasoning-08-2025': {
|
|
140
|
+
image: false,
|
|
141
|
+
objectGeneration: true,
|
|
142
|
+
functionTools: ['streaming'],
|
|
143
|
+
reasoning: true,
|
|
144
|
+
},
|
|
145
|
+
'command-a-vision-07-2025': {
|
|
146
|
+
image: true,
|
|
147
|
+
objectGeneration: true,
|
|
148
|
+
functionTools: ['streaming'],
|
|
149
|
+
reasoning: 'unknown',
|
|
150
|
+
},
|
|
151
|
+
'command-r7b-12-2024': {
|
|
152
|
+
image: false,
|
|
153
|
+
objectGeneration: true,
|
|
154
|
+
functionTools: ['streaming'],
|
|
155
|
+
reasoning: 'unknown',
|
|
156
|
+
},
|
|
157
|
+
'command-r-plus-04-2024': {
|
|
158
|
+
image: false,
|
|
159
|
+
objectGeneration: true,
|
|
160
|
+
functionTools: ['streaming'],
|
|
161
|
+
reasoning: 'unknown',
|
|
162
|
+
},
|
|
163
|
+
'command-r-plus': {
|
|
164
|
+
image: false,
|
|
165
|
+
objectGeneration: true,
|
|
166
|
+
functionTools: ['streaming'],
|
|
167
|
+
reasoning: 'unknown',
|
|
168
|
+
},
|
|
169
|
+
'command-r-08-2024': {
|
|
170
|
+
image: false,
|
|
171
|
+
objectGeneration: true,
|
|
172
|
+
functionTools: ['streaming'],
|
|
173
|
+
reasoning: 'unknown',
|
|
174
|
+
},
|
|
175
|
+
'command-r-03-2024': {
|
|
176
|
+
image: false,
|
|
177
|
+
objectGeneration: true,
|
|
178
|
+
functionTools: ['streaming'],
|
|
179
|
+
reasoning: 'unknown',
|
|
180
|
+
},
|
|
181
|
+
'command-r': {
|
|
182
|
+
image: false,
|
|
183
|
+
objectGeneration: true,
|
|
184
|
+
functionTools: ['streaming'],
|
|
185
|
+
reasoning: 'unknown',
|
|
186
|
+
},
|
|
187
|
+
command: {
|
|
188
|
+
image: false,
|
|
189
|
+
objectGeneration: false,
|
|
190
|
+
functionTools: false,
|
|
191
|
+
reasoning: 'unknown',
|
|
192
|
+
},
|
|
193
|
+
'command-nightly': {
|
|
194
|
+
image: false,
|
|
195
|
+
objectGeneration: false,
|
|
196
|
+
functionTools: false,
|
|
197
|
+
reasoning: 'unknown',
|
|
198
|
+
},
|
|
199
|
+
'command-light': {
|
|
200
|
+
image: false,
|
|
201
|
+
objectGeneration: false,
|
|
202
|
+
functionTools: false,
|
|
203
|
+
reasoning: 'unknown',
|
|
204
|
+
},
|
|
205
|
+
'command-light-nightly': {
|
|
206
|
+
image: false,
|
|
207
|
+
objectGeneration: false,
|
|
208
|
+
functionTools: false,
|
|
209
|
+
reasoning: 'unknown',
|
|
210
|
+
},
|
|
211
|
+
} satisfies Record<string, CohereLanguageModelRow>;
|
|
132
212
|
|
|
213
|
+
/** Maps a matrix row to its entry. Nothing here inspects the model ID. */
|
|
133
214
|
function createLanguageModelEntry(
|
|
134
|
-
|
|
215
|
+
row: CohereLanguageModelRow,
|
|
135
216
|
): CohereLanguageModelEntry {
|
|
136
|
-
const reasoningSupport = definition?.reasoning ?? 'unknown';
|
|
137
217
|
return {
|
|
138
218
|
capabilities: {
|
|
139
219
|
language: {
|
|
140
|
-
inputs: { image:
|
|
141
|
-
objectGeneration:
|
|
220
|
+
inputs: { image: row.image, audio: false },
|
|
221
|
+
objectGeneration: row.objectGeneration,
|
|
142
222
|
tools: {
|
|
143
|
-
usage:
|
|
144
|
-
|
|
223
|
+
usage:
|
|
224
|
+
row.functionTools === 'unknown'
|
|
225
|
+
? 'unknown'
|
|
226
|
+
: row.functionTools !== false,
|
|
227
|
+
streaming:
|
|
228
|
+
row.functionTools === 'unknown'
|
|
229
|
+
? 'unknown'
|
|
230
|
+
: row.functionTools !== false &&
|
|
231
|
+
row.functionTools.includes('streaming'),
|
|
145
232
|
},
|
|
146
|
-
reasoning: { support:
|
|
233
|
+
reasoning: { support: row.reasoning, maxBudget: 32768 },
|
|
147
234
|
sampling: { temperature: 'unknown', topP: 'unknown', logprobs: false },
|
|
148
235
|
},
|
|
149
236
|
},
|
|
150
237
|
providerOptions: {
|
|
151
|
-
language:
|
|
152
|
-
cohereProviderOptions.language,
|
|
153
|
-
definition != null ? true : 'unknown',
|
|
154
|
-
{ thinking: reasoningSupport },
|
|
155
|
-
),
|
|
238
|
+
language: { thinking: row.reasoning },
|
|
156
239
|
},
|
|
157
240
|
requestConfig: {
|
|
158
241
|
language: { thinkingType: 'enabled', reasoningMaxOutputTokens: 32768 },
|
|
@@ -160,6 +243,20 @@ function createLanguageModelEntry(
|
|
|
160
243
|
};
|
|
161
244
|
}
|
|
162
245
|
|
|
246
|
+
const listedLanguageModelEntries = Object.fromEntries(
|
|
247
|
+
Object.entries<CohereLanguageModelRow>(languageModelDefinitions).map(
|
|
248
|
+
([modelId, row]) => [modelId, createLanguageModelEntry(row)],
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
/** Row for every model ID that is not listed in the matrix. */
|
|
253
|
+
const unlistedLanguageModelRow: CohereLanguageModelRow = {
|
|
254
|
+
image: 'unknown',
|
|
255
|
+
objectGeneration: 'unknown',
|
|
256
|
+
functionTools: 'unknown',
|
|
257
|
+
reasoning: 'unknown',
|
|
258
|
+
};
|
|
259
|
+
|
|
163
260
|
// These SDK limits apply to custom model IDs as well as catalog models.
|
|
164
261
|
export const cohereEmbeddingModelLimits = {
|
|
165
262
|
maxEmbeddingsPerCall: 96,
|
|
@@ -171,19 +268,21 @@ const embeddingRequestConfig: EmbeddingRequestConfig = {
|
|
|
171
268
|
inputType: 'search_query',
|
|
172
269
|
};
|
|
173
270
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
271
|
+
/**
|
|
272
|
+
* One row of the embedding model matrix. Nothing is derived from the model
|
|
273
|
+
* ID.
|
|
274
|
+
*/
|
|
275
|
+
export type CohereEmbeddingModelRow = {
|
|
276
|
+
defaultDimensions: number;
|
|
277
|
+
/** Output dimensions the model accepts. More than one: custom dimensions. */
|
|
278
|
+
dimensions: readonly number[];
|
|
279
|
+
/** Embedding formats the model returns. */
|
|
280
|
+
embeddingTypes: readonly EmbeddingType[];
|
|
281
|
+
};
|
|
181
282
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
dimensions
|
|
185
|
-
formats: readonly EmbeddingType[] = embeddingTypes,
|
|
186
|
-
) {
|
|
283
|
+
/** Maps a matrix row to its entry. Nothing here inspects the model ID. */
|
|
284
|
+
function createEmbeddingModelEntry(row: CohereEmbeddingModelRow) {
|
|
285
|
+
const { defaultDimensions, dimensions, embeddingTypes } = row;
|
|
187
286
|
const customDimensions = dimensions.length > 1;
|
|
188
287
|
return {
|
|
189
288
|
capabilities: {
|
|
@@ -191,7 +290,7 @@ function createEmbeddingModelEntry(
|
|
|
191
290
|
defaultDimensions,
|
|
192
291
|
customDimensions,
|
|
193
292
|
dimensions,
|
|
194
|
-
embeddingTypes
|
|
293
|
+
embeddingTypes,
|
|
195
294
|
...cohereEmbeddingModelLimits,
|
|
196
295
|
},
|
|
197
296
|
},
|
|
@@ -199,7 +298,7 @@ function createEmbeddingModelEntry(
|
|
|
199
298
|
embedding: declareProviderOptions(cohereProviderOptions.embedding, true, {
|
|
200
299
|
outputDimension: customDimensions,
|
|
201
300
|
embeddingType:
|
|
202
|
-
|
|
301
|
+
embeddingTypes.length === 1
|
|
203
302
|
? { condition: "Only embeddingType: 'float' is supported." }
|
|
204
303
|
: true,
|
|
205
304
|
}),
|
|
@@ -237,28 +336,68 @@ function createRerankingModelEntry(
|
|
|
237
336
|
};
|
|
238
337
|
}
|
|
239
338
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
'embed-v5.0-
|
|
246
|
-
2048,
|
|
247
|
-
[256, 512, 768, 1024, 1536, 2048],
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
'embed-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
'embed-
|
|
256
|
-
|
|
257
|
-
[1024],
|
|
258
|
-
['float'],
|
|
339
|
+
/**
|
|
340
|
+
* Embedding model matrix: model IDs by capability. To add a model, add a row
|
|
341
|
+
* and fill in every column.
|
|
342
|
+
*/
|
|
343
|
+
const embeddingModelDefinitions = {
|
|
344
|
+
'embed-v5.0-pro': {
|
|
345
|
+
defaultDimensions: 2048,
|
|
346
|
+
dimensions: [256, 512, 768, 1024, 1536, 2048],
|
|
347
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
348
|
+
},
|
|
349
|
+
'embed-v5.0-fast': {
|
|
350
|
+
defaultDimensions: 2048,
|
|
351
|
+
dimensions: [256, 512, 768, 1024, 1536, 2048],
|
|
352
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
353
|
+
},
|
|
354
|
+
'embed-v4.0': {
|
|
355
|
+
defaultDimensions: 1536,
|
|
356
|
+
dimensions: [256, 512, 1024, 1536],
|
|
357
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
358
|
+
},
|
|
359
|
+
'embed-english-v3.0': {
|
|
360
|
+
defaultDimensions: 1024,
|
|
361
|
+
dimensions: [1024],
|
|
362
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
363
|
+
},
|
|
364
|
+
'embed-multilingual-v3.0': {
|
|
365
|
+
defaultDimensions: 1024,
|
|
366
|
+
dimensions: [1024],
|
|
367
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
368
|
+
},
|
|
369
|
+
'embed-english-light-v3.0': {
|
|
370
|
+
defaultDimensions: 384,
|
|
371
|
+
dimensions: [384],
|
|
372
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
373
|
+
},
|
|
374
|
+
'embed-multilingual-light-v3.0': {
|
|
375
|
+
defaultDimensions: 384,
|
|
376
|
+
dimensions: [384],
|
|
377
|
+
embeddingTypes: ['float', 'int8', 'uint8', 'binary', 'ubinary'],
|
|
378
|
+
},
|
|
379
|
+
'embed-english-v2.0': {
|
|
380
|
+
defaultDimensions: 4096,
|
|
381
|
+
dimensions: [4096],
|
|
382
|
+
embeddingTypes: ['float'],
|
|
383
|
+
},
|
|
384
|
+
'embed-english-light-v2.0': {
|
|
385
|
+
defaultDimensions: 1024,
|
|
386
|
+
dimensions: [1024],
|
|
387
|
+
embeddingTypes: ['float'],
|
|
388
|
+
},
|
|
389
|
+
'embed-multilingual-v2.0': {
|
|
390
|
+
defaultDimensions: 768,
|
|
391
|
+
dimensions: [768],
|
|
392
|
+
embeddingTypes: ['float'],
|
|
393
|
+
},
|
|
394
|
+
} satisfies Record<string, CohereEmbeddingModelRow>;
|
|
395
|
+
|
|
396
|
+
const cohereEmbeddingModelEntries = Object.fromEntries(
|
|
397
|
+
Object.entries<CohereEmbeddingModelRow>(embeddingModelDefinitions).map(
|
|
398
|
+
([modelId, row]) => [modelId, createEmbeddingModelEntry(row)],
|
|
259
399
|
),
|
|
260
|
-
|
|
261
|
-
};
|
|
400
|
+
);
|
|
262
401
|
|
|
263
402
|
const cohereRerankingModelEntries = {
|
|
264
403
|
'rerank-v4.0-pro': createRerankingModelEntry(true),
|
|
@@ -269,12 +408,7 @@ const cohereRerankingModelEntries = {
|
|
|
269
408
|
};
|
|
270
409
|
|
|
271
410
|
export const cohereModelCatalog: Readonly<Record<string, CohereModelEntry>> = {
|
|
272
|
-
...
|
|
273
|
-
Object.entries(languageDefinitions).map(([modelId, definition]) => [
|
|
274
|
-
modelId,
|
|
275
|
-
createLanguageModelEntry(definition),
|
|
276
|
-
]),
|
|
277
|
-
),
|
|
411
|
+
...listedLanguageModelEntries,
|
|
278
412
|
...cohereEmbeddingModelEntries,
|
|
279
413
|
...cohereRerankingModelEntries,
|
|
280
414
|
};
|
|
@@ -285,19 +419,19 @@ function findModelEntry(modelId: string) {
|
|
|
285
419
|
: undefined;
|
|
286
420
|
}
|
|
287
421
|
|
|
422
|
+
/**
|
|
423
|
+
* Returns the entry of a listed language model ID from its row. Every other
|
|
424
|
+
* model ID uses the row for unlisted IDs.
|
|
425
|
+
*/
|
|
288
426
|
export function getCohereLanguageModelEntry(
|
|
289
427
|
modelId: string,
|
|
290
428
|
): CohereLanguageModelEntry {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
?
|
|
296
|
-
|
|
297
|
-
providerOptions: { language: entry.providerOptions.language },
|
|
298
|
-
requestConfig: { language: entry.requestConfig.language },
|
|
299
|
-
}
|
|
300
|
-
: createLanguageModelEntry();
|
|
429
|
+
return Object.prototype.hasOwnProperty.call(
|
|
430
|
+
listedLanguageModelEntries,
|
|
431
|
+
modelId,
|
|
432
|
+
)
|
|
433
|
+
? listedLanguageModelEntries[modelId]
|
|
434
|
+
: createLanguageModelEntry(unlistedLanguageModelRow);
|
|
301
435
|
}
|
|
302
436
|
|
|
303
437
|
export function getCohereEmbeddingModelEntry(
|
|
@@ -353,7 +487,7 @@ function declareProviderOptions<Option extends string>(
|
|
|
353
487
|
|
|
354
488
|
/** Known model IDs, derived from the declarations used to build the catalog. */
|
|
355
489
|
export type CohereModelIds = {
|
|
356
|
-
language: keyof typeof
|
|
357
|
-
embedding: keyof typeof
|
|
490
|
+
language: keyof typeof languageModelDefinitions;
|
|
491
|
+
embedding: keyof typeof embeddingModelDefinitions;
|
|
358
492
|
reranking: keyof typeof cohereRerankingModelEntries;
|
|
359
493
|
};
|