@ai-sdk/cohere 4.0.0-beta.9 → 4.0.0-canary.34
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 +219 -0
- package/README.md +2 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +360 -264
- package/dist/index.js.map +1 -1
- package/docs/25-cohere.mdx +59 -2
- package/package.json +11 -9
- package/src/{cohere-chat-options.ts → cohere-chat-language-model-options.ts} +17 -3
- package/src/cohere-chat-language-model.ts +36 -16
- package/src/cohere-chat-prompt.ts +8 -1
- 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 +119 -54
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
LanguageModelV4,
|
|
3
3
|
LanguageModelV4CallOptions,
|
|
4
4
|
LanguageModelV4Content,
|
|
@@ -9,32 +9,38 @@ import {
|
|
|
9
9
|
SharedV4Warning,
|
|
10
10
|
} from '@ai-sdk/provider';
|
|
11
11
|
import {
|
|
12
|
-
FetchFunction,
|
|
13
|
-
ParseResult,
|
|
14
12
|
combineHeaders,
|
|
15
13
|
createEventSourceResponseHandler,
|
|
16
14
|
createJsonResponseHandler,
|
|
17
|
-
type InferSchema,
|
|
18
15
|
isCustomReasoning,
|
|
19
16
|
mapReasoningToProviderBudget,
|
|
20
17
|
parseProviderOptions,
|
|
21
18
|
postJsonToApi,
|
|
19
|
+
serializeModelOptions,
|
|
20
|
+
WORKFLOW_SERIALIZE,
|
|
21
|
+
WORKFLOW_DESERIALIZE,
|
|
22
|
+
type InferSchema,
|
|
23
|
+
type FetchFunction,
|
|
24
|
+
type ParseResult,
|
|
22
25
|
} from '@ai-sdk/provider-utils';
|
|
23
26
|
import { z } from 'zod/v4';
|
|
24
27
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from './cohere-chat-options';
|
|
28
|
+
cohereLanguageModelChatOptions,
|
|
29
|
+
type CohereChatModelId,
|
|
30
|
+
} from './cohere-chat-language-model-options';
|
|
28
31
|
import { cohereFailedResponseHandler } from './cohere-error';
|
|
29
32
|
import { prepareTools } from './cohere-prepare-tools';
|
|
30
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
convertCohereUsage,
|
|
35
|
+
type CohereUsageTokens,
|
|
36
|
+
} from './convert-cohere-usage';
|
|
31
37
|
import { convertToCohereChatPrompt } from './convert-to-cohere-chat-prompt';
|
|
32
38
|
import { mapCohereFinishReason } from './map-cohere-finish-reason';
|
|
33
39
|
|
|
34
40
|
type CohereChatConfig = {
|
|
35
41
|
provider: string;
|
|
36
42
|
baseURL: string;
|
|
37
|
-
headers
|
|
43
|
+
headers?: () => Record<string, string | undefined>;
|
|
38
44
|
fetch?: FetchFunction;
|
|
39
45
|
generateId: () => string;
|
|
40
46
|
};
|
|
@@ -44,12 +50,26 @@ export class CohereChatLanguageModel implements LanguageModelV4 {
|
|
|
44
50
|
|
|
45
51
|
readonly modelId: CohereChatModelId;
|
|
46
52
|
|
|
47
|
-
readonly supportedUrls = {
|
|
48
|
-
|
|
53
|
+
readonly supportedUrls: Record<string, RegExp[]> = {
|
|
54
|
+
'image/*': [/^https?:\/\/.*$/],
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
private readonly config: CohereChatConfig;
|
|
52
58
|
|
|
59
|
+
static [WORKFLOW_SERIALIZE](model: CohereChatLanguageModel) {
|
|
60
|
+
return serializeModelOptions({
|
|
61
|
+
modelId: model.modelId,
|
|
62
|
+
config: model.config,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
67
|
+
modelId: CohereChatModelId;
|
|
68
|
+
config: CohereChatConfig;
|
|
69
|
+
}) {
|
|
70
|
+
return new CohereChatLanguageModel(options.modelId, options.config);
|
|
71
|
+
}
|
|
72
|
+
|
|
53
73
|
constructor(modelId: CohereChatModelId, config: CohereChatConfig) {
|
|
54
74
|
this.modelId = modelId;
|
|
55
75
|
this.config = config;
|
|
@@ -81,14 +101,14 @@ export class CohereChatLanguageModel implements LanguageModelV4 {
|
|
|
81
101
|
(await parseProviderOptions({
|
|
82
102
|
provider: 'cohere',
|
|
83
103
|
providerOptions,
|
|
84
|
-
schema:
|
|
104
|
+
schema: cohereLanguageModelChatOptions,
|
|
85
105
|
})) ?? {};
|
|
86
106
|
|
|
87
107
|
const {
|
|
88
108
|
messages: chatPrompt,
|
|
89
109
|
documents: cohereDocuments,
|
|
90
110
|
warnings: promptWarnings,
|
|
91
|
-
} = convertToCohereChatPrompt(prompt);
|
|
111
|
+
} = await convertToCohereChatPrompt(prompt);
|
|
92
112
|
|
|
93
113
|
const {
|
|
94
114
|
tools: cohereTools,
|
|
@@ -151,7 +171,7 @@ export class CohereChatLanguageModel implements LanguageModelV4 {
|
|
|
151
171
|
rawValue: rawResponse,
|
|
152
172
|
} = await postJsonToApi({
|
|
153
173
|
url: `${this.config.baseURL}/chat`,
|
|
154
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
174
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
155
175
|
body: args,
|
|
156
176
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
157
177
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -232,7 +252,7 @@ export class CohereChatLanguageModel implements LanguageModelV4 {
|
|
|
232
252
|
|
|
233
253
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
234
254
|
url: `${this.config.baseURL}/chat`,
|
|
235
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
255
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
236
256
|
body: { ...args, stream: true },
|
|
237
257
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
238
258
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -446,7 +466,7 @@ function resolveCohereThinking({
|
|
|
446
466
|
warnings,
|
|
447
467
|
}: {
|
|
448
468
|
reasoning: LanguageModelV4CallOptions['reasoning'];
|
|
449
|
-
cohereOptions: InferSchema<typeof
|
|
469
|
+
cohereOptions: InferSchema<typeof cohereLanguageModelChatOptions>;
|
|
450
470
|
warnings: SharedV4Warning[];
|
|
451
471
|
}): { thinking?: { type: string; token_budget?: number } } {
|
|
452
472
|
if (cohereOptions.thinking) {
|
|
@@ -13,9 +13,16 @@ export interface CohereSystemMessage {
|
|
|
13
13
|
|
|
14
14
|
export interface CohereUserMessage {
|
|
15
15
|
role: 'user';
|
|
16
|
-
content: string
|
|
16
|
+
content: string | Array<CohereUserMessageContent>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export type CohereUserMessageContent =
|
|
20
|
+
| { type: 'text'; text: string }
|
|
21
|
+
| {
|
|
22
|
+
type: 'image_url';
|
|
23
|
+
image_url: { url: string; detail?: 'auto' | 'low' | 'high' };
|
|
24
|
+
};
|
|
25
|
+
|
|
19
26
|
export interface CohereAssistantMessage {
|
|
20
27
|
role: 'assistant';
|
|
21
28
|
content: string | undefined;
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EmbeddingModelV4,
|
|
3
2
|
TooManyEmbeddingValuesForCallError,
|
|
3
|
+
type EmbeddingModelV4,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import {
|
|
6
6
|
combineHeaders,
|
|
7
7
|
createJsonResponseHandler,
|
|
8
|
-
FetchFunction,
|
|
9
8
|
parseProviderOptions,
|
|
10
9
|
postJsonToApi,
|
|
10
|
+
serializeModelOptions,
|
|
11
|
+
WORKFLOW_SERIALIZE,
|
|
12
|
+
WORKFLOW_DESERIALIZE,
|
|
13
|
+
type FetchFunction,
|
|
11
14
|
} from '@ai-sdk/provider-utils';
|
|
12
15
|
import { z } from 'zod/v4';
|
|
13
16
|
import {
|
|
14
|
-
CohereEmbeddingModelId,
|
|
15
17
|
cohereEmbeddingModelOptions,
|
|
16
|
-
|
|
18
|
+
type CohereEmbeddingModelId,
|
|
19
|
+
} from './cohere-embedding-model-options';
|
|
17
20
|
import { cohereFailedResponseHandler } from './cohere-error';
|
|
18
21
|
|
|
19
22
|
type CohereEmbeddingConfig = {
|
|
20
23
|
provider: string;
|
|
21
24
|
baseURL: string;
|
|
22
|
-
headers
|
|
25
|
+
headers?: () => Record<string, string | undefined>;
|
|
23
26
|
fetch?: FetchFunction;
|
|
24
27
|
};
|
|
25
28
|
|
|
@@ -32,6 +35,20 @@ export class CohereEmbeddingModel implements EmbeddingModelV4 {
|
|
|
32
35
|
|
|
33
36
|
private readonly config: CohereEmbeddingConfig;
|
|
34
37
|
|
|
38
|
+
static [WORKFLOW_SERIALIZE](model: CohereEmbeddingModel) {
|
|
39
|
+
return serializeModelOptions({
|
|
40
|
+
modelId: model.modelId,
|
|
41
|
+
config: model.config,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
46
|
+
modelId: CohereEmbeddingModelId;
|
|
47
|
+
config: CohereEmbeddingConfig;
|
|
48
|
+
}) {
|
|
49
|
+
return new CohereEmbeddingModel(options.modelId, options.config);
|
|
50
|
+
}
|
|
51
|
+
|
|
35
52
|
constructor(modelId: CohereEmbeddingModelId, config: CohereEmbeddingConfig) {
|
|
36
53
|
this.modelId = modelId;
|
|
37
54
|
this.config = config;
|
|
@@ -70,7 +87,7 @@ export class CohereEmbeddingModel implements EmbeddingModelV4 {
|
|
|
70
87
|
rawValue,
|
|
71
88
|
} = await postJsonToApi({
|
|
72
89
|
url: `${this.config.baseURL}/embed`,
|
|
73
|
-
headers: combineHeaders(this.config.headers(), headers),
|
|
90
|
+
headers: combineHeaders(this.config.headers?.(), headers),
|
|
74
91
|
body: {
|
|
75
92
|
model: this.modelId,
|
|
76
93
|
// The AI SDK only supports 'float' embeddings. Note that the Cohere API
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV4CallOptions,
|
|
3
|
-
SharedV4Warning,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4CallOptions,
|
|
4
|
+
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import { CohereToolChoice } from './cohere-chat-prompt';
|
|
6
|
+
import type { CohereToolChoice } from './cohere-chat-prompt';
|
|
7
7
|
|
|
8
8
|
export function prepareTools({
|
|
9
9
|
tools,
|
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,17 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SharedV4Warning,
|
|
3
|
-
LanguageModelV4Prompt,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4FilePart,
|
|
4
|
+
type LanguageModelV4Prompt,
|
|
5
|
+
type SharedV4Warning,
|
|
5
6
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
convertToBase64,
|
|
9
|
+
getTopLevelMediaType,
|
|
10
|
+
parseProviderOptions,
|
|
11
|
+
resolveFullMediaType,
|
|
12
|
+
} from '@ai-sdk/provider-utils';
|
|
13
|
+
import { cohereImagePartProviderOptions } from './cohere-chat-language-model-options';
|
|
14
|
+
import type {
|
|
15
|
+
CohereAssistantMessage,
|
|
16
|
+
CohereChatPrompt,
|
|
17
|
+
CohereUserMessageContent,
|
|
18
|
+
} from './cohere-chat-prompt';
|
|
7
19
|
|
|
8
|
-
export function convertToCohereChatPrompt(
|
|
20
|
+
export async function convertToCohereChatPrompt(
|
|
21
|
+
prompt: LanguageModelV4Prompt,
|
|
22
|
+
): Promise<{
|
|
9
23
|
messages: CohereChatPrompt;
|
|
10
24
|
documents: Array<{
|
|
11
25
|
data: { text: string; title?: string };
|
|
12
26
|
}>;
|
|
13
27
|
warnings: SharedV4Warning[];
|
|
14
|
-
} {
|
|
28
|
+
}> {
|
|
15
29
|
const messages: CohereChatPrompt = [];
|
|
16
30
|
const documents: Array<{ data: { text: string; title?: string } }> = [];
|
|
17
31
|
const warnings: SharedV4Warning[] = [];
|
|
@@ -24,58 +38,88 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
case 'user': {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
const userContentParts: Array<CohereUserMessageContent> = [];
|
|
42
|
+
let hasImage = false;
|
|
43
|
+
|
|
44
|
+
for (const part of content) {
|
|
45
|
+
switch (part.type) {
|
|
46
|
+
case 'text': {
|
|
47
|
+
if (part.text.length > 0) {
|
|
48
|
+
userContentParts.push({ type: 'text', text: part.text });
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'file': {
|
|
53
|
+
if (getTopLevelMediaType(part.mediaType) === 'image') {
|
|
54
|
+
hasImage = true;
|
|
55
|
+
const url = buildImageUrl({ part });
|
|
56
|
+
const cohereOptions =
|
|
57
|
+
(await parseProviderOptions({
|
|
58
|
+
provider: 'cohere',
|
|
59
|
+
providerOptions: part.providerOptions,
|
|
60
|
+
schema: cohereImagePartProviderOptions,
|
|
61
|
+
})) ?? {};
|
|
62
|
+
|
|
63
|
+
userContentParts.push({
|
|
64
|
+
type: 'image_url',
|
|
65
|
+
image_url: {
|
|
66
|
+
url,
|
|
67
|
+
...(cohereOptions.detail
|
|
68
|
+
? { detail: cohereOptions.detail }
|
|
69
|
+
: {}),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let textContent: string;
|
|
76
|
+
switch (part.data.type) {
|
|
77
|
+
case 'reference': {
|
|
78
|
+
throw new UnsupportedFunctionalityError({
|
|
79
|
+
functionality: 'file parts with provider references',
|
|
80
|
+
});
|
|
34
81
|
}
|
|
35
|
-
case '
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// Base64 or text data
|
|
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
|
-
) {
|
|
50
|
-
throw new UnsupportedFunctionalityError({
|
|
51
|
-
functionality: `document media type: ${part.mediaType}`,
|
|
52
|
-
message: `Media type '${part.mediaType}' is not supported. Supported media types are: text/* and application/json.`,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
textContent = new TextDecoder().decode(part.data);
|
|
56
|
-
} else {
|
|
57
|
-
throw new UnsupportedFunctionalityError({
|
|
58
|
-
functionality: 'File URL data',
|
|
59
|
-
message:
|
|
60
|
-
'URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue.',
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
documents.push({
|
|
65
|
-
data: {
|
|
66
|
-
text: textContent,
|
|
67
|
-
title: part.filename,
|
|
68
|
-
},
|
|
82
|
+
case 'url': {
|
|
83
|
+
throw new UnsupportedFunctionalityError({
|
|
84
|
+
functionality: 'File URL data',
|
|
85
|
+
message:
|
|
86
|
+
'URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue.',
|
|
69
87
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
}
|
|
89
|
+
case 'text': {
|
|
90
|
+
textContent = part.data.text;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case 'data': {
|
|
94
|
+
textContent =
|
|
95
|
+
typeof part.data.data === 'string'
|
|
96
|
+
? part.data.data
|
|
97
|
+
: new TextDecoder().decode(part.data.data);
|
|
98
|
+
break;
|
|
74
99
|
}
|
|
75
100
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
|
|
102
|
+
documents.push({
|
|
103
|
+
data: {
|
|
104
|
+
text: textContent,
|
|
105
|
+
title: part.filename,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (hasImage) {
|
|
114
|
+
messages.push({ role: 'user', content: userContentParts });
|
|
115
|
+
} else {
|
|
116
|
+
messages.push({
|
|
117
|
+
role: 'user',
|
|
118
|
+
content: userContentParts
|
|
119
|
+
.map(p => (p.type === 'text' ? p.text : ''))
|
|
120
|
+
.join(''),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
79
123
|
break;
|
|
80
124
|
}
|
|
81
125
|
|
|
@@ -126,7 +170,7 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
126
170
|
contentValue = output.value;
|
|
127
171
|
break;
|
|
128
172
|
case 'execution-denied':
|
|
129
|
-
contentValue = output.reason ?? 'Tool execution denied.';
|
|
173
|
+
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
130
174
|
break;
|
|
131
175
|
case 'content':
|
|
132
176
|
case 'json':
|
|
@@ -154,3 +198,24 @@ export function convertToCohereChatPrompt(prompt: LanguageModelV4Prompt): {
|
|
|
154
198
|
|
|
155
199
|
return { messages, documents, warnings };
|
|
156
200
|
}
|
|
201
|
+
|
|
202
|
+
function buildImageUrl({ part }: { part: LanguageModelV4FilePart }): string {
|
|
203
|
+
switch (part.data.type) {
|
|
204
|
+
case 'url': {
|
|
205
|
+
return part.data.url.toString();
|
|
206
|
+
}
|
|
207
|
+
case 'data': {
|
|
208
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
209
|
+
}
|
|
210
|
+
case 'reference': {
|
|
211
|
+
throw new UnsupportedFunctionalityError({
|
|
212
|
+
functionality: 'image file parts with provider references',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
case 'text': {
|
|
216
|
+
throw new UnsupportedFunctionalityError({
|
|
217
|
+
functionality: 'image file parts with text data',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
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 };
|