@ai-sdk/cohere 4.0.0-beta.8 → 4.0.0-canary.33
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 +221 -0
- package/README.md +2 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +279 -245
- package/dist/index.js.map +1 -1
- package/docs/25-cohere.mdx +2 -2
- package/package.json +11 -9
- package/src/{cohere-chat-options.ts → cohere-chat-language-model-options.ts} +3 -3
- package/src/cohere-chat-language-model.ts +33 -13
- package/src/cohere-embedding-model.ts +23 -6
- package/src/cohere-prepare-tools.ts +3 -3
- package/src/cohere-provider.ts +8 -9
- package/src/convert-cohere-usage.ts +1 -1
- package/src/convert-to-cohere-chat-prompt.ts +28 -27
- package/src/index.ts +8 -6
- package/src/map-cohere-finish-reason.ts +1 -1
- package/src/reranking/{cohere-reranking-options.ts → cohere-reranking-model-options.ts} +5 -1
- package/src/reranking/cohere-reranking-model.ts +5 -6
- package/dist/index.d.mts +0 -117
- package/dist/index.mjs +0 -1102
- package/dist/index.mjs.map +0 -1
- /package/src/{cohere-embedding-options.ts → cohere-embedding-model-options.ts} +0 -0
package/src/cohere-provider.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EmbeddingModelV4,
|
|
3
|
-
LanguageModelV4,
|
|
4
2
|
NoSuchModelError,
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type EmbeddingModelV4,
|
|
4
|
+
type LanguageModelV4,
|
|
5
|
+
type RerankingModelV4,
|
|
6
|
+
type ProviderV4,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
|
-
|
|
9
8
|
import {
|
|
10
|
-
FetchFunction,
|
|
11
9
|
generateId,
|
|
12
10
|
loadApiKey,
|
|
13
11
|
withoutTrailingSlash,
|
|
14
12
|
withUserAgentSuffix,
|
|
13
|
+
type FetchFunction,
|
|
15
14
|
} from '@ai-sdk/provider-utils';
|
|
16
15
|
import { CohereChatLanguageModel } from './cohere-chat-language-model';
|
|
17
|
-
import { CohereChatModelId } from './cohere-chat-options';
|
|
16
|
+
import type { CohereChatModelId } from './cohere-chat-language-model-options';
|
|
18
17
|
import { CohereEmbeddingModel } from './cohere-embedding-model';
|
|
19
|
-
import { CohereRerankingModelId } from './reranking/cohere-reranking-options';
|
|
18
|
+
import type { CohereRerankingModelId } from './reranking/cohere-reranking-model-options';
|
|
20
19
|
import { CohereRerankingModel } from './reranking/cohere-reranking-model';
|
|
21
|
-
import { CohereEmbeddingModelId } from './cohere-embedding-options';
|
|
20
|
+
import type { CohereEmbeddingModelId } from './cohere-embedding-model-options';
|
|
22
21
|
import { VERSION } from './version';
|
|
23
22
|
|
|
24
23
|
export interface CohereProvider extends ProviderV4 {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SharedV4Warning,
|
|
3
|
-
LanguageModelV4Prompt,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type SharedV4Warning,
|
|
4
|
+
type LanguageModelV4Prompt,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
|
+
CohereAssistantMessage,
|
|
8
|
+
CohereChatPrompt,
|
|
9
|
+
} from './cohere-chat-prompt';
|
|
7
10
|
|
|
8
11
|
export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
9
12
|
messages: CohereChatPrompt;
|
|
@@ -33,32 +36,32 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
33
36
|
return part.text;
|
|
34
37
|
}
|
|
35
38
|
case 'file': {
|
|
36
|
-
// Extract documents for RAG
|
|
37
39
|
let textContent: string;
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
textContent = part.data;
|
|
42
|
-
} else if (part.data instanceof Uint8Array) {
|
|
43
|
-
// Check if the media type is supported for text extraction
|
|
44
|
-
if (
|
|
45
|
-
!(
|
|
46
|
-
part.mediaType?.startsWith('text/') ||
|
|
47
|
-
part.mediaType === 'application/json'
|
|
48
|
-
)
|
|
49
|
-
) {
|
|
41
|
+
switch (part.data.type) {
|
|
42
|
+
case 'reference': {
|
|
50
43
|
throw new UnsupportedFunctionalityError({
|
|
51
|
-
functionality:
|
|
52
|
-
message: `Media type '${part.mediaType}' is not supported. Supported media types are: text/* and application/json.`,
|
|
44
|
+
functionality: 'file parts with provider references',
|
|
53
45
|
});
|
|
54
46
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
47
|
+
case 'url': {
|
|
48
|
+
throw new UnsupportedFunctionalityError({
|
|
49
|
+
functionality: 'File URL data',
|
|
50
|
+
message:
|
|
51
|
+
'URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue.',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
case 'text': {
|
|
55
|
+
textContent = part.data.text;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'data': {
|
|
59
|
+
textContent =
|
|
60
|
+
typeof part.data.data === 'string'
|
|
61
|
+
? part.data.data
|
|
62
|
+
: new TextDecoder().decode(part.data.data);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
documents.push({
|
|
@@ -68,8 +71,6 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
68
71
|
},
|
|
69
72
|
});
|
|
70
73
|
|
|
71
|
-
// Files are handled separately via the documents parameter
|
|
72
|
-
// Return empty string to not include file content in message text
|
|
73
74
|
return '';
|
|
74
75
|
}
|
|
75
76
|
}
|
|
@@ -126,7 +127,7 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
126
127
|
contentValue = output.value;
|
|
127
128
|
break;
|
|
128
129
|
case 'execution-denied':
|
|
129
|
-
contentValue = output.reason ?? 'Tool execution denied.';
|
|
130
|
+
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
130
131
|
break;
|
|
131
132
|
case 'content':
|
|
132
133
|
case 'json':
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export type {
|
|
2
|
-
|
|
3
|
-
/** @deprecated Use `
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
CohereLanguageModelChatOptions,
|
|
3
|
+
/** @deprecated Use `CohereLanguageModelChatOptions` instead. */
|
|
4
|
+
CohereLanguageModelChatOptions as CohereLanguageModelOptions,
|
|
5
|
+
/** @deprecated Use `CohereLanguageModelChatOptions` instead. */
|
|
6
|
+
CohereLanguageModelChatOptions as CohereChatModelOptions,
|
|
7
|
+
} from './cohere-chat-language-model-options';
|
|
6
8
|
export { cohere, createCohere } from './cohere-provider';
|
|
7
9
|
export type { CohereProvider, CohereProviderSettings } from './cohere-provider';
|
|
8
|
-
export type { CohereEmbeddingModelOptions } from './cohere-embedding-options';
|
|
10
|
+
export type { CohereEmbeddingModelOptions } from './cohere-embedding-model-options';
|
|
9
11
|
export type {
|
|
10
12
|
CohereRerankingModelOptions,
|
|
11
13
|
/** @deprecated Use `CohereRerankingModelOptions` instead. */
|
|
12
14
|
CohereRerankingModelOptions as CohereRerankingOptions,
|
|
13
|
-
} from './reranking/cohere-reranking-options';
|
|
15
|
+
} from './reranking/cohere-reranking-model-options';
|
|
14
16
|
export { VERSION } from './version';
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { RerankingModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
1
|
+
import type { RerankingModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
4
|
createJsonResponseHandler,
|
|
5
|
-
FetchFunction,
|
|
6
5
|
parseProviderOptions,
|
|
7
6
|
postJsonToApi,
|
|
7
|
+
type FetchFunction,
|
|
8
8
|
} from '@ai-sdk/provider-utils';
|
|
9
9
|
import { cohereFailedResponseHandler } from '../cohere-error';
|
|
10
10
|
import {
|
|
11
|
-
CohereRerankingInput,
|
|
12
11
|
cohereRerankingResponseSchema,
|
|
12
|
+
type CohereRerankingInput,
|
|
13
13
|
} from './cohere-reranking-api';
|
|
14
14
|
import {
|
|
15
|
-
CohereRerankingModelId,
|
|
16
15
|
cohereRerankingModelOptionsSchema,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
type CohereRerankingModelId,
|
|
17
|
+
} from './cohere-reranking-model-options';
|
|
19
18
|
type CohereRerankingConfig = {
|
|
20
19
|
provider: string;
|
|
21
20
|
baseURL: string;
|
package/dist/index.d.mts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
|
-
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, RerankingModelV4 } from '@ai-sdk/provider';
|
|
3
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
-
|
|
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 & {});
|
|
6
|
-
declare const cohereLanguageModelOptions: z.ZodObject<{
|
|
7
|
-
thinking: z.ZodOptional<z.ZodObject<{
|
|
8
|
-
type: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
enabled: "enabled";
|
|
10
|
-
disabled: "disabled";
|
|
11
|
-
}>>;
|
|
12
|
-
tokenBudget: z.ZodOptional<z.ZodNumber>;
|
|
13
|
-
}, z.core.$strip>>;
|
|
14
|
-
}, z.core.$strip>;
|
|
15
|
-
type CohereLanguageModelOptions = z.infer<typeof cohereLanguageModelOptions>;
|
|
16
|
-
|
|
17
|
-
type CohereRerankingModelId = 'rerank-v3.5' | 'rerank-english-v3.0' | 'rerank-multilingual-v3.0' | (string & {});
|
|
18
|
-
type CohereRerankingModelOptions = {
|
|
19
|
-
/**
|
|
20
|
-
* Long documents will be automatically truncated to the specified number of tokens.
|
|
21
|
-
*
|
|
22
|
-
* @default 4096
|
|
23
|
-
*/
|
|
24
|
-
maxTokensPerDoc?: number;
|
|
25
|
-
/**
|
|
26
|
-
* The priority of the request.
|
|
27
|
-
*
|
|
28
|
-
* @default 0
|
|
29
|
-
*/
|
|
30
|
-
priority?: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type CohereEmbeddingModelId = 'embed-english-v3.0' | 'embed-multilingual-v3.0' | 'embed-english-light-v3.0' | 'embed-multilingual-light-v3.0' | 'embed-english-v2.0' | 'embed-english-light-v2.0' | 'embed-multilingual-v2.0' | (string & {});
|
|
34
|
-
declare const cohereEmbeddingModelOptions: z.ZodObject<{
|
|
35
|
-
inputType: z.ZodOptional<z.ZodEnum<{
|
|
36
|
-
search_document: "search_document";
|
|
37
|
-
search_query: "search_query";
|
|
38
|
-
classification: "classification";
|
|
39
|
-
clustering: "clustering";
|
|
40
|
-
}>>;
|
|
41
|
-
truncate: z.ZodOptional<z.ZodEnum<{
|
|
42
|
-
NONE: "NONE";
|
|
43
|
-
START: "START";
|
|
44
|
-
END: "END";
|
|
45
|
-
}>>;
|
|
46
|
-
outputDimension: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<256>, z.ZodLiteral<512>, z.ZodLiteral<1024>, z.ZodLiteral<1536>]>>;
|
|
47
|
-
}, z.core.$strip>;
|
|
48
|
-
type CohereEmbeddingModelOptions = z.infer<typeof cohereEmbeddingModelOptions>;
|
|
49
|
-
|
|
50
|
-
interface CohereProvider extends ProviderV4 {
|
|
51
|
-
(modelId: CohereChatModelId): LanguageModelV4;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a model for text generation.
|
|
54
|
-
*/
|
|
55
|
-
languageModel(modelId: CohereChatModelId): LanguageModelV4;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a model for text embeddings.
|
|
58
|
-
*/
|
|
59
|
-
embedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
60
|
-
/**
|
|
61
|
-
* Creates a model for text embeddings.
|
|
62
|
-
*/
|
|
63
|
-
embeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
64
|
-
/**
|
|
65
|
-
* @deprecated Use `embedding` instead.
|
|
66
|
-
*/
|
|
67
|
-
textEmbedding(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Use `embeddingModel` instead.
|
|
70
|
-
*/
|
|
71
|
-
textEmbeddingModel(modelId: CohereEmbeddingModelId): EmbeddingModelV4;
|
|
72
|
-
/**
|
|
73
|
-
* Creates a model for reranking.
|
|
74
|
-
*/
|
|
75
|
-
reranking(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a model for reranking.
|
|
78
|
-
*/
|
|
79
|
-
rerankingModel(modelId: CohereRerankingModelId): RerankingModelV4;
|
|
80
|
-
}
|
|
81
|
-
interface CohereProviderSettings {
|
|
82
|
-
/**
|
|
83
|
-
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
84
|
-
* The default prefix is `https://api.cohere.com/v2`.
|
|
85
|
-
*/
|
|
86
|
-
baseURL?: string;
|
|
87
|
-
/**
|
|
88
|
-
* API key that is being send using the `Authorization` header.
|
|
89
|
-
* It defaults to the `COHERE_API_KEY` environment variable.
|
|
90
|
-
*/
|
|
91
|
-
apiKey?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Custom headers to include in the requests.
|
|
94
|
-
*/
|
|
95
|
-
headers?: Record<string, string>;
|
|
96
|
-
/**
|
|
97
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
98
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
99
|
-
*/
|
|
100
|
-
fetch?: FetchFunction;
|
|
101
|
-
/**
|
|
102
|
-
* Optional function to generate a unique ID for each request.
|
|
103
|
-
*/
|
|
104
|
-
generateId?: () => string;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create a Cohere AI provider instance.
|
|
108
|
-
*/
|
|
109
|
-
declare function createCohere(options?: CohereProviderSettings): CohereProvider;
|
|
110
|
-
/**
|
|
111
|
-
* Default Cohere provider instance.
|
|
112
|
-
*/
|
|
113
|
-
declare const cohere: CohereProvider;
|
|
114
|
-
|
|
115
|
-
declare const VERSION: string;
|
|
116
|
-
|
|
117
|
-
export { type CohereLanguageModelOptions as CohereChatModelOptions, type CohereEmbeddingModelOptions, type CohereLanguageModelOptions, type CohereProvider, type CohereProviderSettings, type CohereRerankingModelOptions, type CohereRerankingModelOptions as CohereRerankingOptions, VERSION, cohere, createCohere };
|