@ai-sdk/cohere 4.0.0-beta.1 → 4.0.0-beta.11
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 +78 -4
- package/README.md +2 -0
- package/dist/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
- package/src/cohere-chat-language-model.ts +72 -25
- package/src/cohere-embedding-model.ts +5 -5
- package/src/cohere-prepare-tools.ts +6 -6
- package/src/cohere-provider.ts +14 -14
- package/src/convert-cohere-usage.ts +2 -2
- package/src/convert-to-cohere-chat-prompt.ts +5 -5
- package/src/map-cohere-finish-reason.ts +2 -2
- package/src/reranking/cohere-reranking-model.ts +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
# @ai-sdk/cohere
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 38fc777: Add AI Gateway hint to provider READMEs
|
|
8
|
+
|
|
9
|
+
## 4.0.0-beta.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [2e17091]
|
|
14
|
+
- @ai-sdk/provider-utils@5.0.0-beta.9
|
|
15
|
+
|
|
16
|
+
## 4.0.0-beta.9
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [986c6fd]
|
|
21
|
+
- Updated dependencies [493295c]
|
|
22
|
+
- @ai-sdk/provider-utils@5.0.0-beta.8
|
|
23
|
+
|
|
24
|
+
## 4.0.0-beta.8
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [1f509d4]
|
|
29
|
+
- @ai-sdk/provider-utils@5.0.0-beta.7
|
|
30
|
+
- @ai-sdk/provider@4.0.0-beta.5
|
|
31
|
+
|
|
32
|
+
## 4.0.0-beta.7
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 74d520f: feat: migrate providers to support new top-level `reasoning` parameter
|
|
37
|
+
|
|
38
|
+
## 4.0.0-beta.6
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [3887c70]
|
|
43
|
+
- @ai-sdk/provider-utils@5.0.0-beta.6
|
|
44
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
45
|
+
|
|
46
|
+
## 4.0.0-beta.5
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [776b617]
|
|
51
|
+
- @ai-sdk/provider-utils@5.0.0-beta.5
|
|
52
|
+
- @ai-sdk/provider@4.0.0-beta.3
|
|
53
|
+
|
|
54
|
+
## 4.0.0-beta.4
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [61753c3]
|
|
59
|
+
- @ai-sdk/provider-utils@5.0.0-beta.4
|
|
60
|
+
|
|
61
|
+
## 4.0.0-beta.3
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [f7d4f01]
|
|
66
|
+
- @ai-sdk/provider-utils@5.0.0-beta.3
|
|
67
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
68
|
+
|
|
69
|
+
## 4.0.0-beta.2
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies [5c2a5a2]
|
|
74
|
+
- @ai-sdk/provider@4.0.0-beta.1
|
|
75
|
+
- @ai-sdk/provider-utils@5.0.0-beta.2
|
|
76
|
+
|
|
3
77
|
## 4.0.0-beta.1
|
|
4
78
|
|
|
5
79
|
### Patch Changes
|
|
@@ -216,13 +290,13 @@
|
|
|
216
290
|
Before
|
|
217
291
|
|
|
218
292
|
```ts
|
|
219
|
-
model.textEmbeddingModel(
|
|
293
|
+
model.textEmbeddingModel("my-model-id");
|
|
220
294
|
```
|
|
221
295
|
|
|
222
296
|
After
|
|
223
297
|
|
|
224
298
|
```ts
|
|
225
|
-
model.embeddingModel(
|
|
299
|
+
model.embeddingModel("my-model-id");
|
|
226
300
|
```
|
|
227
301
|
|
|
228
302
|
- 2625a04: feat(openai); update spec for mcp approval
|
|
@@ -434,13 +508,13 @@
|
|
|
434
508
|
Before
|
|
435
509
|
|
|
436
510
|
```ts
|
|
437
|
-
model.textEmbeddingModel(
|
|
511
|
+
model.textEmbeddingModel("my-model-id");
|
|
438
512
|
```
|
|
439
513
|
|
|
440
514
|
After
|
|
441
515
|
|
|
442
516
|
```ts
|
|
443
|
-
model.embeddingModel(
|
|
517
|
+
model.embeddingModel("my-model-id");
|
|
444
518
|
```
|
|
445
519
|
|
|
446
520
|
- Updated dependencies [8d9e8ad]
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The **[Cohere provider](https://ai-sdk.dev/providers/ai-sdk-providers/cohere)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the Cohere API.
|
|
4
4
|
|
|
5
|
+
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Cohere (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
6
|
+
|
|
5
7
|
## Setup
|
|
6
8
|
|
|
7
9
|
The Cohere provider is available in the `@ai-sdk/cohere` module. You can install it with
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, RerankingModelV4 } from '@ai-sdk/provider';
|
|
3
3
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
5
|
type CohereChatModelId = 'command-a-03-2025' | 'command-a-reasoning-08-2025' | 'command-r7b-12-2024' | 'command-r-plus-04-2024' | 'command-r-plus' | 'command-r-08-2024' | 'command-r-03-2024' | 'command-r' | 'command' | 'command-nightly' | 'command-light' | 'command-light-nightly' | (string & {});
|
|
@@ -47,36 +47,36 @@ declare const cohereEmbeddingModelOptions: z.ZodObject<{
|
|
|
47
47
|
}, z.core.$strip>;
|
|
48
48
|
type CohereEmbeddingModelOptions = z.infer<typeof cohereEmbeddingModelOptions>;
|
|
49
49
|
|
|
50
|
-
interface CohereProvider extends
|
|
51
|
-
(modelId: CohereChatModelId):
|
|
50
|
+
interface CohereProvider extends ProviderV4 {
|
|
51
|
+
(modelId: CohereChatModelId): LanguageModelV4;
|
|
52
52
|
/**
|
|
53
53
|
* Creates a model for text generation.
|
|
54
54
|
*/
|
|
55
|
-
languageModel(modelId: CohereChatModelId):
|
|
55
|
+
languageModel(modelId: CohereChatModelId): LanguageModelV4;
|
|
56
56
|
/**
|
|
57
57
|
* Creates a model for text embeddings.
|
|
58
58
|
*/
|
|
59
|
-
embedding(modelId: CohereEmbeddingModelId):
|
|
59
|
+
embedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
60
60
|
/**
|
|
61
61
|
* Creates a model for text embeddings.
|
|
62
62
|
*/
|
|
63
|
-
embeddingModel(modelId: CohereEmbeddingModelId):
|
|
63
|
+
embeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
64
64
|
/**
|
|
65
65
|
* @deprecated Use `embedding` instead.
|
|
66
66
|
*/
|
|
67
|
-
textEmbedding(modelId: CohereEmbeddingModelId):
|
|
67
|
+
textEmbedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
68
68
|
/**
|
|
69
69
|
* @deprecated Use `embeddingModel` instead.
|
|
70
70
|
*/
|
|
71
|
-
textEmbeddingModel(modelId: CohereEmbeddingModelId):
|
|
71
|
+
textEmbeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
72
72
|
/**
|
|
73
73
|
* Creates a model for reranking.
|
|
74
74
|
*/
|
|
75
|
-
reranking(modelId: CohereRerankingModelId):
|
|
75
|
+
reranking(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
76
76
|
/**
|
|
77
77
|
* Creates a model for reranking.
|
|
78
78
|
*/
|
|
79
|
-
rerankingModel(modelId: CohereRerankingModelId):
|
|
79
|
+
rerankingModel(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
80
80
|
}
|
|
81
81
|
interface CohereProviderSettings {
|
|
82
82
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, RerankingModelV4 } from '@ai-sdk/provider';
|
|
3
3
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
5
|
type CohereChatModelId = 'command-a-03-2025' | 'command-a-reasoning-08-2025' | 'command-r7b-12-2024' | 'command-r-plus-04-2024' | 'command-r-plus' | 'command-r-08-2024' | 'command-r-03-2024' | 'command-r' | 'command' | 'command-nightly' | 'command-light' | 'command-light-nightly' | (string & {});
|
|
@@ -47,36 +47,36 @@ declare const cohereEmbeddingModelOptions: z.ZodObject<{
|
|
|
47
47
|
}, z.core.$strip>;
|
|
48
48
|
type CohereEmbeddingModelOptions = z.infer<typeof cohereEmbeddingModelOptions>;
|
|
49
49
|
|
|
50
|
-
interface CohereProvider extends
|
|
51
|
-
(modelId: CohereChatModelId):
|
|
50
|
+
interface CohereProvider extends ProviderV4 {
|
|
51
|
+
(modelId: CohereChatModelId): LanguageModelV4;
|
|
52
52
|
/**
|
|
53
53
|
* Creates a model for text generation.
|
|
54
54
|
*/
|
|
55
|
-
languageModel(modelId: CohereChatModelId):
|
|
55
|
+
languageModel(modelId: CohereChatModelId): LanguageModelV4;
|
|
56
56
|
/**
|
|
57
57
|
* Creates a model for text embeddings.
|
|
58
58
|
*/
|
|
59
|
-
embedding(modelId: CohereEmbeddingModelId):
|
|
59
|
+
embedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
60
60
|
/**
|
|
61
61
|
* Creates a model for text embeddings.
|
|
62
62
|
*/
|
|
63
|
-
embeddingModel(modelId: CohereEmbeddingModelId):
|
|
63
|
+
embeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
64
64
|
/**
|
|
65
65
|
* @deprecated Use `embedding` instead.
|
|
66
66
|
*/
|
|
67
|
-
textEmbedding(modelId: CohereEmbeddingModelId):
|
|
67
|
+
textEmbedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
68
68
|
/**
|
|
69
69
|
* @deprecated Use `embeddingModel` instead.
|
|
70
70
|
*/
|
|
71
|
-
textEmbeddingModel(modelId: CohereEmbeddingModelId):
|
|
71
|
+
textEmbeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
72
72
|
/**
|
|
73
73
|
* Creates a model for reranking.
|
|
74
74
|
*/
|
|
75
|
-
reranking(modelId: CohereRerankingModelId):
|
|
75
|
+
reranking(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
76
76
|
/**
|
|
77
77
|
* Creates a model for reranking.
|
|
78
78
|
*/
|
|
79
|
-
rerankingModel(modelId: CohereRerankingModelId):
|
|
79
|
+
rerankingModel(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
80
80
|
}
|
|
81
81
|
interface CohereProviderSettings {
|
|
82
82
|
/**
|
package/dist/index.js
CHANGED
|
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
cohere: () => cohere,
|
|
25
25
|
createCohere: () => createCohere
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/cohere-provider.ts
|
|
30
30
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -295,7 +295,7 @@ function mapCohereFinishReason(finishReason) {
|
|
|
295
295
|
// src/cohere-chat-language-model.ts
|
|
296
296
|
var CohereChatLanguageModel = class {
|
|
297
297
|
constructor(modelId, config) {
|
|
298
|
-
this.specificationVersion = "
|
|
298
|
+
this.specificationVersion = "v4";
|
|
299
299
|
this.supportedUrls = {
|
|
300
300
|
// No URLs are supported.
|
|
301
301
|
};
|
|
@@ -316,11 +316,13 @@ var CohereChatLanguageModel = class {
|
|
|
316
316
|
stopSequences,
|
|
317
317
|
responseFormat,
|
|
318
318
|
seed,
|
|
319
|
+
reasoning,
|
|
319
320
|
tools,
|
|
320
321
|
toolChoice,
|
|
321
322
|
providerOptions
|
|
322
323
|
}) {
|
|
323
|
-
var _a
|
|
324
|
+
var _a;
|
|
325
|
+
const warnings = [];
|
|
324
326
|
const cohereOptions = (_a = await (0, import_provider_utils2.parseProviderOptions)({
|
|
325
327
|
provider: "cohere",
|
|
326
328
|
providerOptions,
|
|
@@ -336,6 +338,7 @@ var CohereChatLanguageModel = class {
|
|
|
336
338
|
toolChoice: cohereToolChoice,
|
|
337
339
|
toolWarnings
|
|
338
340
|
} = prepareTools({ tools, toolChoice });
|
|
341
|
+
warnings.push(...toolWarnings, ...promptWarnings);
|
|
339
342
|
return {
|
|
340
343
|
args: {
|
|
341
344
|
// model id:
|
|
@@ -358,15 +361,14 @@ var CohereChatLanguageModel = class {
|
|
|
358
361
|
tool_choice: cohereToolChoice,
|
|
359
362
|
// documents for RAG:
|
|
360
363
|
...cohereDocuments.length > 0 && { documents: cohereDocuments },
|
|
361
|
-
// reasoning
|
|
362
|
-
...
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
364
|
+
// reasoning:
|
|
365
|
+
...resolveCohereThinking({
|
|
366
|
+
reasoning,
|
|
367
|
+
cohereOptions,
|
|
368
|
+
warnings
|
|
369
|
+
})
|
|
368
370
|
},
|
|
369
|
-
warnings
|
|
371
|
+
warnings
|
|
370
372
|
};
|
|
371
373
|
}
|
|
372
374
|
async doGenerate(options) {
|
|
@@ -617,6 +619,37 @@ var CohereChatLanguageModel = class {
|
|
|
617
619
|
};
|
|
618
620
|
}
|
|
619
621
|
};
|
|
622
|
+
function resolveCohereThinking({
|
|
623
|
+
reasoning,
|
|
624
|
+
cohereOptions,
|
|
625
|
+
warnings
|
|
626
|
+
}) {
|
|
627
|
+
var _a;
|
|
628
|
+
if (cohereOptions.thinking) {
|
|
629
|
+
return {
|
|
630
|
+
thinking: {
|
|
631
|
+
type: (_a = cohereOptions.thinking.type) != null ? _a : "enabled",
|
|
632
|
+
token_budget: cohereOptions.thinking.tokenBudget
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
if (!(0, import_provider_utils2.isCustomReasoning)(reasoning)) {
|
|
637
|
+
return {};
|
|
638
|
+
}
|
|
639
|
+
if (reasoning === "none") {
|
|
640
|
+
return { thinking: { type: "disabled" } };
|
|
641
|
+
}
|
|
642
|
+
const tokenBudget = (0, import_provider_utils2.mapReasoningToProviderBudget)({
|
|
643
|
+
reasoning,
|
|
644
|
+
maxOutputTokens: 32768,
|
|
645
|
+
maxReasoningBudget: 32768,
|
|
646
|
+
warnings
|
|
647
|
+
});
|
|
648
|
+
if (tokenBudget == null) {
|
|
649
|
+
return {};
|
|
650
|
+
}
|
|
651
|
+
return { thinking: { type: "enabled", token_budget: tokenBudget } };
|
|
652
|
+
}
|
|
620
653
|
var cohereChatResponseSchema = import_v43.z.object({
|
|
621
654
|
generation_id: import_v43.z.string().nullish(),
|
|
622
655
|
message: import_v43.z.object({
|
|
@@ -820,7 +853,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
820
853
|
// src/cohere-embedding-model.ts
|
|
821
854
|
var CohereEmbeddingModel = class {
|
|
822
855
|
constructor(modelId, config) {
|
|
823
|
-
this.specificationVersion = "
|
|
856
|
+
this.specificationVersion = "v4";
|
|
824
857
|
this.maxEmbeddingsPerCall = 96;
|
|
825
858
|
this.supportsParallelCalls = true;
|
|
826
859
|
this.modelId = modelId;
|
|
@@ -929,7 +962,7 @@ var cohereRerankingModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
|
|
|
929
962
|
// src/reranking/cohere-reranking-model.ts
|
|
930
963
|
var CohereRerankingModel = class {
|
|
931
964
|
constructor(modelId, config) {
|
|
932
|
-
this.specificationVersion = "
|
|
965
|
+
this.specificationVersion = "v4";
|
|
933
966
|
this.modelId = modelId;
|
|
934
967
|
this.config = config;
|
|
935
968
|
}
|
|
@@ -997,7 +1030,7 @@ var CohereRerankingModel = class {
|
|
|
997
1030
|
};
|
|
998
1031
|
|
|
999
1032
|
// src/version.ts
|
|
1000
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1033
|
+
var VERSION = true ? "4.0.0-beta.11" : "0.0.0-test";
|
|
1001
1034
|
|
|
1002
1035
|
// src/cohere-provider.ts
|
|
1003
1036
|
function createCohere(options = {}) {
|
|
@@ -1044,7 +1077,7 @@ function createCohere(options = {}) {
|
|
|
1044
1077
|
}
|
|
1045
1078
|
return createChatModel(modelId);
|
|
1046
1079
|
};
|
|
1047
|
-
provider.specificationVersion = "
|
|
1080
|
+
provider.specificationVersion = "v4";
|
|
1048
1081
|
provider.languageModel = createChatModel;
|
|
1049
1082
|
provider.embedding = createEmbeddingModel;
|
|
1050
1083
|
provider.embeddingModel = createEmbeddingModel;
|