@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
package/dist/index.js
CHANGED
|
@@ -1,42 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
cohere: () => cohere,
|
|
25
|
-
createCohere: () => createCohere
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/cohere-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
withUserAgentSuffix
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
32
11
|
|
|
33
12
|
// src/cohere-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
import {
|
|
14
|
+
combineHeaders,
|
|
15
|
+
createEventSourceResponseHandler,
|
|
16
|
+
createJsonResponseHandler,
|
|
17
|
+
isCustomReasoning,
|
|
18
|
+
mapReasoningToProviderBudget,
|
|
19
|
+
parseProviderOptions as parseProviderOptions2,
|
|
20
|
+
postJsonToApi,
|
|
21
|
+
serializeModelOptions,
|
|
22
|
+
WORKFLOW_SERIALIZE,
|
|
23
|
+
WORKFLOW_DESERIALIZE
|
|
24
|
+
} from "@ai-sdk/provider-utils";
|
|
25
|
+
import { z as z3 } from "zod/v4";
|
|
36
26
|
|
|
37
|
-
// src/cohere-chat-options.ts
|
|
38
|
-
|
|
39
|
-
var
|
|
27
|
+
// src/cohere-chat-language-model-options.ts
|
|
28
|
+
import { z } from "zod/v4";
|
|
29
|
+
var cohereLanguageModelChatOptions = z.object({
|
|
40
30
|
/**
|
|
41
31
|
* Configuration for reasoning features (optional)
|
|
42
32
|
*
|
|
@@ -45,25 +35,35 @@ var cohereLanguageModelOptions = import_v4.z.object({
|
|
|
45
35
|
*
|
|
46
36
|
* @see https://docs.cohere.com/reference/chat#request.body.thinking
|
|
47
37
|
*/
|
|
48
|
-
thinking:
|
|
49
|
-
type:
|
|
50
|
-
tokenBudget:
|
|
38
|
+
thinking: z.object({
|
|
39
|
+
type: z.enum(["enabled", "disabled"]).optional(),
|
|
40
|
+
tokenBudget: z.number().optional()
|
|
51
41
|
}).optional()
|
|
52
42
|
});
|
|
43
|
+
var cohereImagePartProviderOptions = z.object({
|
|
44
|
+
/**
|
|
45
|
+
* Image fidelity level passed through as `image_url.detail` on the Cohere chat API.
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.cohere.com/docs/image-inputs
|
|
48
|
+
*/
|
|
49
|
+
detail: z.enum(["auto", "low", "high"]).optional()
|
|
50
|
+
});
|
|
53
51
|
|
|
54
52
|
// src/cohere-error.ts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var cohereErrorDataSchema =
|
|
58
|
-
message:
|
|
53
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
54
|
+
import { z as z2 } from "zod/v4";
|
|
55
|
+
var cohereErrorDataSchema = z2.object({
|
|
56
|
+
message: z2.string()
|
|
59
57
|
});
|
|
60
|
-
var cohereFailedResponseHandler =
|
|
58
|
+
var cohereFailedResponseHandler = createJsonErrorResponseHandler({
|
|
61
59
|
errorSchema: cohereErrorDataSchema,
|
|
62
60
|
errorToMessage: (data) => data.message
|
|
63
61
|
});
|
|
64
62
|
|
|
65
63
|
// src/cohere-prepare-tools.ts
|
|
66
|
-
|
|
64
|
+
import {
|
|
65
|
+
UnsupportedFunctionalityError
|
|
66
|
+
} from "@ai-sdk/provider";
|
|
67
67
|
function prepareTools({
|
|
68
68
|
tools,
|
|
69
69
|
toolChoice
|
|
@@ -112,7 +112,7 @@ function prepareTools({
|
|
|
112
112
|
};
|
|
113
113
|
default: {
|
|
114
114
|
const _exhaustiveCheck = type;
|
|
115
|
-
throw new
|
|
115
|
+
throw new UnsupportedFunctionalityError({
|
|
116
116
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -156,8 +156,17 @@ function convertCohereUsage(tokens) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// src/convert-to-cohere-chat-prompt.ts
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
import {
|
|
160
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
161
|
+
} from "@ai-sdk/provider";
|
|
162
|
+
import {
|
|
163
|
+
convertToBase64,
|
|
164
|
+
getTopLevelMediaType,
|
|
165
|
+
parseProviderOptions,
|
|
166
|
+
resolveFullMediaType
|
|
167
|
+
} from "@ai-sdk/provider-utils";
|
|
168
|
+
async function convertToCohereChatPrompt(prompt) {
|
|
169
|
+
var _a;
|
|
161
170
|
const messages = [];
|
|
162
171
|
const documents = [];
|
|
163
172
|
const warnings = [];
|
|
@@ -168,43 +177,74 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
168
177
|
break;
|
|
169
178
|
}
|
|
170
179
|
case "user": {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
const userContentParts = [];
|
|
181
|
+
let hasImage = false;
|
|
182
|
+
for (const part of content) {
|
|
183
|
+
switch (part.type) {
|
|
184
|
+
case "text": {
|
|
185
|
+
if (part.text.length > 0) {
|
|
186
|
+
userContentParts.push({ type: "text", text: part.text });
|
|
178
187
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "file": {
|
|
191
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
192
|
+
hasImage = true;
|
|
193
|
+
const url = buildImageUrl({ part });
|
|
194
|
+
const cohereOptions = (_a = await parseProviderOptions({
|
|
195
|
+
provider: "cohere",
|
|
196
|
+
providerOptions: part.providerOptions,
|
|
197
|
+
schema: cohereImagePartProviderOptions
|
|
198
|
+
})) != null ? _a : {};
|
|
199
|
+
userContentParts.push({
|
|
200
|
+
type: "image_url",
|
|
201
|
+
image_url: {
|
|
202
|
+
url,
|
|
203
|
+
...cohereOptions.detail ? { detail: cohereOptions.detail } : {}
|
|
189
204
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
205
|
+
});
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
let textContent;
|
|
209
|
+
switch (part.data.type) {
|
|
210
|
+
case "reference": {
|
|
211
|
+
throw new UnsupportedFunctionalityError2({
|
|
212
|
+
functionality: "file parts with provider references"
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
case "url": {
|
|
216
|
+
throw new UnsupportedFunctionalityError2({
|
|
193
217
|
functionality: "File URL data",
|
|
194
218
|
message: "URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue."
|
|
195
219
|
});
|
|
196
220
|
}
|
|
197
|
-
|
|
198
|
-
data
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
221
|
+
case "text": {
|
|
222
|
+
textContent = part.data.text;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case "data": {
|
|
226
|
+
textContent = typeof part.data.data === "string" ? part.data.data : new TextDecoder().decode(part.data.data);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
204
229
|
}
|
|
230
|
+
documents.push({
|
|
231
|
+
data: {
|
|
232
|
+
text: textContent,
|
|
233
|
+
title: part.filename
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
break;
|
|
205
237
|
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (hasImage) {
|
|
241
|
+
messages.push({ role: "user", content: userContentParts });
|
|
242
|
+
} else {
|
|
243
|
+
messages.push({
|
|
244
|
+
role: "user",
|
|
245
|
+
content: userContentParts.map((p) => p.type === "text" ? p.text : "").join("")
|
|
246
|
+
});
|
|
247
|
+
}
|
|
208
248
|
break;
|
|
209
249
|
}
|
|
210
250
|
case "assistant": {
|
|
@@ -240,7 +280,7 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
240
280
|
case "tool": {
|
|
241
281
|
messages.push(
|
|
242
282
|
...content.filter((toolResult) => toolResult.type !== "tool-approval-response").map((toolResult) => {
|
|
243
|
-
var
|
|
283
|
+
var _a2;
|
|
244
284
|
const output = toolResult.output;
|
|
245
285
|
let contentValue;
|
|
246
286
|
switch (output.type) {
|
|
@@ -249,7 +289,7 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
249
289
|
contentValue = output.value;
|
|
250
290
|
break;
|
|
251
291
|
case "execution-denied":
|
|
252
|
-
contentValue = (
|
|
292
|
+
contentValue = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
253
293
|
break;
|
|
254
294
|
case "content":
|
|
255
295
|
case "json":
|
|
@@ -274,6 +314,26 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
274
314
|
}
|
|
275
315
|
return { messages, documents, warnings };
|
|
276
316
|
}
|
|
317
|
+
function buildImageUrl({ part }) {
|
|
318
|
+
switch (part.data.type) {
|
|
319
|
+
case "url": {
|
|
320
|
+
return part.data.url.toString();
|
|
321
|
+
}
|
|
322
|
+
case "data": {
|
|
323
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
324
|
+
}
|
|
325
|
+
case "reference": {
|
|
326
|
+
throw new UnsupportedFunctionalityError2({
|
|
327
|
+
functionality: "image file parts with provider references"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
case "text": {
|
|
331
|
+
throw new UnsupportedFunctionalityError2({
|
|
332
|
+
functionality: "image file parts with text data"
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
277
337
|
|
|
278
338
|
// src/map-cohere-finish-reason.ts
|
|
279
339
|
function mapCohereFinishReason(finishReason) {
|
|
@@ -293,15 +353,24 @@ function mapCohereFinishReason(finishReason) {
|
|
|
293
353
|
}
|
|
294
354
|
|
|
295
355
|
// src/cohere-chat-language-model.ts
|
|
296
|
-
var CohereChatLanguageModel = class {
|
|
356
|
+
var CohereChatLanguageModel = class _CohereChatLanguageModel {
|
|
297
357
|
constructor(modelId, config) {
|
|
298
358
|
this.specificationVersion = "v4";
|
|
299
359
|
this.supportedUrls = {
|
|
300
|
-
|
|
360
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
301
361
|
};
|
|
302
362
|
this.modelId = modelId;
|
|
303
363
|
this.config = config;
|
|
304
364
|
}
|
|
365
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
366
|
+
return serializeModelOptions({
|
|
367
|
+
modelId: model.modelId,
|
|
368
|
+
config: model.config
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
372
|
+
return new _CohereChatLanguageModel(options.modelId, options.config);
|
|
373
|
+
}
|
|
305
374
|
get provider() {
|
|
306
375
|
return this.config.provider;
|
|
307
376
|
}
|
|
@@ -323,16 +392,16 @@ var CohereChatLanguageModel = class {
|
|
|
323
392
|
}) {
|
|
324
393
|
var _a;
|
|
325
394
|
const warnings = [];
|
|
326
|
-
const cohereOptions = (_a = await (
|
|
395
|
+
const cohereOptions = (_a = await parseProviderOptions2({
|
|
327
396
|
provider: "cohere",
|
|
328
397
|
providerOptions,
|
|
329
|
-
schema:
|
|
398
|
+
schema: cohereLanguageModelChatOptions
|
|
330
399
|
})) != null ? _a : {};
|
|
331
400
|
const {
|
|
332
401
|
messages: chatPrompt,
|
|
333
402
|
documents: cohereDocuments,
|
|
334
403
|
warnings: promptWarnings
|
|
335
|
-
} = convertToCohereChatPrompt(prompt);
|
|
404
|
+
} = await convertToCohereChatPrompt(prompt);
|
|
336
405
|
const {
|
|
337
406
|
tools: cohereTools,
|
|
338
407
|
toolChoice: cohereToolChoice,
|
|
@@ -372,25 +441,25 @@ var CohereChatLanguageModel = class {
|
|
|
372
441
|
};
|
|
373
442
|
}
|
|
374
443
|
async doGenerate(options) {
|
|
375
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
444
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
376
445
|
const { args, warnings } = await this.getArgs(options);
|
|
377
446
|
const {
|
|
378
447
|
responseHeaders,
|
|
379
448
|
value: response,
|
|
380
449
|
rawValue: rawResponse
|
|
381
|
-
} = await
|
|
450
|
+
} = await postJsonToApi({
|
|
382
451
|
url: `${this.config.baseURL}/chat`,
|
|
383
|
-
headers: (
|
|
452
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
384
453
|
body: args,
|
|
385
454
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
386
|
-
successfulResponseHandler:
|
|
455
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
387
456
|
cohereChatResponseSchema
|
|
388
457
|
),
|
|
389
458
|
abortSignal: options.abortSignal,
|
|
390
459
|
fetch: this.config.fetch
|
|
391
460
|
});
|
|
392
461
|
const content = [];
|
|
393
|
-
for (const item of (
|
|
462
|
+
for (const item of (_c = response.message.content) != null ? _c : []) {
|
|
394
463
|
if (item.type === "text" && item.text.length > 0) {
|
|
395
464
|
content.push({ type: "text", text: item.text });
|
|
396
465
|
continue;
|
|
@@ -400,13 +469,13 @@ var CohereChatLanguageModel = class {
|
|
|
400
469
|
continue;
|
|
401
470
|
}
|
|
402
471
|
}
|
|
403
|
-
for (const citation of (
|
|
472
|
+
for (const citation of (_d = response.message.citations) != null ? _d : []) {
|
|
404
473
|
content.push({
|
|
405
474
|
type: "source",
|
|
406
475
|
sourceType: "document",
|
|
407
476
|
id: this.config.generateId(),
|
|
408
477
|
mediaType: "text/plain",
|
|
409
|
-
title: ((
|
|
478
|
+
title: ((_f = (_e = citation.sources[0]) == null ? void 0 : _e.document) == null ? void 0 : _f.title) || "Document",
|
|
410
479
|
providerMetadata: {
|
|
411
480
|
cohere: {
|
|
412
481
|
start: citation.start,
|
|
@@ -418,7 +487,7 @@ var CohereChatLanguageModel = class {
|
|
|
418
487
|
}
|
|
419
488
|
});
|
|
420
489
|
}
|
|
421
|
-
for (const toolCall of (
|
|
490
|
+
for (const toolCall of (_g = response.message.tool_calls) != null ? _g : []) {
|
|
422
491
|
content.push({
|
|
423
492
|
type: "tool-call",
|
|
424
493
|
toolCallId: toolCall.id,
|
|
@@ -432,13 +501,13 @@ var CohereChatLanguageModel = class {
|
|
|
432
501
|
content,
|
|
433
502
|
finishReason: {
|
|
434
503
|
unified: mapCohereFinishReason(response.finish_reason),
|
|
435
|
-
raw: (
|
|
504
|
+
raw: (_h = response.finish_reason) != null ? _h : void 0
|
|
436
505
|
},
|
|
437
506
|
usage: convertCohereUsage(response.usage.tokens),
|
|
438
507
|
request: { body: args },
|
|
439
508
|
response: {
|
|
440
509
|
// TODO timestamp, model id
|
|
441
|
-
id: (
|
|
510
|
+
id: (_i = response.generation_id) != null ? _i : void 0,
|
|
442
511
|
headers: responseHeaders,
|
|
443
512
|
body: rawResponse
|
|
444
513
|
},
|
|
@@ -446,13 +515,14 @@ var CohereChatLanguageModel = class {
|
|
|
446
515
|
};
|
|
447
516
|
}
|
|
448
517
|
async doStream(options) {
|
|
518
|
+
var _a, _b;
|
|
449
519
|
const { args, warnings } = await this.getArgs(options);
|
|
450
|
-
const { responseHeaders, value: response } = await
|
|
520
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
451
521
|
url: `${this.config.baseURL}/chat`,
|
|
452
|
-
headers: (
|
|
522
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
453
523
|
body: { ...args, stream: true },
|
|
454
524
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
455
|
-
successfulResponseHandler:
|
|
525
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
456
526
|
cohereChatChunkSchema
|
|
457
527
|
),
|
|
458
528
|
abortSignal: options.abortSignal,
|
|
@@ -472,7 +542,7 @@ var CohereChatLanguageModel = class {
|
|
|
472
542
|
controller.enqueue({ type: "stream-start", warnings });
|
|
473
543
|
},
|
|
474
544
|
transform(chunk, controller) {
|
|
475
|
-
var
|
|
545
|
+
var _a2, _b2;
|
|
476
546
|
if (options.includeRawChunks) {
|
|
477
547
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
478
548
|
}
|
|
@@ -577,7 +647,7 @@ var CohereChatLanguageModel = class {
|
|
|
577
647
|
toolCallId: pendingToolCall.id,
|
|
578
648
|
toolName: pendingToolCall.name,
|
|
579
649
|
input: JSON.stringify(
|
|
580
|
-
JSON.parse(((
|
|
650
|
+
JSON.parse(((_a2 = pendingToolCall.arguments) == null ? void 0 : _a2.trim()) || "{}")
|
|
581
651
|
)
|
|
582
652
|
});
|
|
583
653
|
pendingToolCall.hasFinished = true;
|
|
@@ -588,7 +658,7 @@ var CohereChatLanguageModel = class {
|
|
|
588
658
|
case "message-start": {
|
|
589
659
|
controller.enqueue({
|
|
590
660
|
type: "response-metadata",
|
|
591
|
-
id: (
|
|
661
|
+
id: (_b2 = value.id) != null ? _b2 : void 0
|
|
592
662
|
});
|
|
593
663
|
return;
|
|
594
664
|
}
|
|
@@ -633,13 +703,13 @@ function resolveCohereThinking({
|
|
|
633
703
|
}
|
|
634
704
|
};
|
|
635
705
|
}
|
|
636
|
-
if (!
|
|
706
|
+
if (!isCustomReasoning(reasoning)) {
|
|
637
707
|
return {};
|
|
638
708
|
}
|
|
639
709
|
if (reasoning === "none") {
|
|
640
710
|
return { thinking: { type: "disabled" } };
|
|
641
711
|
}
|
|
642
|
-
const tokenBudget =
|
|
712
|
+
const tokenBudget = mapReasoningToProviderBudget({
|
|
643
713
|
reasoning,
|
|
644
714
|
maxOutputTokens: 32768,
|
|
645
715
|
maxReasoningBudget: 32768,
|
|
@@ -650,145 +720,145 @@ function resolveCohereThinking({
|
|
|
650
720
|
}
|
|
651
721
|
return { thinking: { type: "enabled", token_budget: tokenBudget } };
|
|
652
722
|
}
|
|
653
|
-
var cohereChatResponseSchema =
|
|
654
|
-
generation_id:
|
|
655
|
-
message:
|
|
656
|
-
role:
|
|
657
|
-
content:
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
type:
|
|
661
|
-
text:
|
|
723
|
+
var cohereChatResponseSchema = z3.object({
|
|
724
|
+
generation_id: z3.string().nullish(),
|
|
725
|
+
message: z3.object({
|
|
726
|
+
role: z3.string(),
|
|
727
|
+
content: z3.array(
|
|
728
|
+
z3.union([
|
|
729
|
+
z3.object({
|
|
730
|
+
type: z3.literal("text"),
|
|
731
|
+
text: z3.string()
|
|
662
732
|
}),
|
|
663
|
-
|
|
664
|
-
type:
|
|
665
|
-
thinking:
|
|
733
|
+
z3.object({
|
|
734
|
+
type: z3.literal("thinking"),
|
|
735
|
+
thinking: z3.string()
|
|
666
736
|
})
|
|
667
737
|
])
|
|
668
738
|
).nullish(),
|
|
669
|
-
tool_plan:
|
|
670
|
-
tool_calls:
|
|
671
|
-
|
|
672
|
-
id:
|
|
673
|
-
type:
|
|
674
|
-
function:
|
|
675
|
-
name:
|
|
676
|
-
arguments:
|
|
739
|
+
tool_plan: z3.string().nullish(),
|
|
740
|
+
tool_calls: z3.array(
|
|
741
|
+
z3.object({
|
|
742
|
+
id: z3.string(),
|
|
743
|
+
type: z3.literal("function"),
|
|
744
|
+
function: z3.object({
|
|
745
|
+
name: z3.string(),
|
|
746
|
+
arguments: z3.string()
|
|
677
747
|
})
|
|
678
748
|
})
|
|
679
749
|
).nullish(),
|
|
680
|
-
citations:
|
|
681
|
-
|
|
682
|
-
start:
|
|
683
|
-
end:
|
|
684
|
-
text:
|
|
685
|
-
sources:
|
|
686
|
-
|
|
687
|
-
type:
|
|
688
|
-
id:
|
|
689
|
-
document:
|
|
690
|
-
id:
|
|
691
|
-
text:
|
|
692
|
-
title:
|
|
750
|
+
citations: z3.array(
|
|
751
|
+
z3.object({
|
|
752
|
+
start: z3.number(),
|
|
753
|
+
end: z3.number(),
|
|
754
|
+
text: z3.string(),
|
|
755
|
+
sources: z3.array(
|
|
756
|
+
z3.object({
|
|
757
|
+
type: z3.string().optional(),
|
|
758
|
+
id: z3.string().optional(),
|
|
759
|
+
document: z3.object({
|
|
760
|
+
id: z3.string().optional(),
|
|
761
|
+
text: z3.string(),
|
|
762
|
+
title: z3.string()
|
|
693
763
|
})
|
|
694
764
|
})
|
|
695
765
|
),
|
|
696
|
-
type:
|
|
766
|
+
type: z3.string().optional()
|
|
697
767
|
})
|
|
698
768
|
).nullish()
|
|
699
769
|
}),
|
|
700
|
-
finish_reason:
|
|
701
|
-
usage:
|
|
702
|
-
billed_units:
|
|
703
|
-
input_tokens:
|
|
704
|
-
output_tokens:
|
|
770
|
+
finish_reason: z3.string(),
|
|
771
|
+
usage: z3.object({
|
|
772
|
+
billed_units: z3.object({
|
|
773
|
+
input_tokens: z3.number(),
|
|
774
|
+
output_tokens: z3.number()
|
|
705
775
|
}),
|
|
706
|
-
tokens:
|
|
707
|
-
input_tokens:
|
|
708
|
-
output_tokens:
|
|
776
|
+
tokens: z3.object({
|
|
777
|
+
input_tokens: z3.number(),
|
|
778
|
+
output_tokens: z3.number()
|
|
709
779
|
})
|
|
710
780
|
})
|
|
711
781
|
});
|
|
712
|
-
var cohereChatChunkSchema =
|
|
713
|
-
|
|
714
|
-
type:
|
|
782
|
+
var cohereChatChunkSchema = z3.discriminatedUnion("type", [
|
|
783
|
+
z3.object({
|
|
784
|
+
type: z3.literal("citation-start")
|
|
715
785
|
}),
|
|
716
|
-
|
|
717
|
-
type:
|
|
786
|
+
z3.object({
|
|
787
|
+
type: z3.literal("citation-end")
|
|
718
788
|
}),
|
|
719
|
-
|
|
720
|
-
type:
|
|
721
|
-
index:
|
|
722
|
-
delta:
|
|
723
|
-
message:
|
|
724
|
-
content:
|
|
725
|
-
|
|
726
|
-
type:
|
|
727
|
-
text:
|
|
789
|
+
z3.object({
|
|
790
|
+
type: z3.literal("content-start"),
|
|
791
|
+
index: z3.number(),
|
|
792
|
+
delta: z3.object({
|
|
793
|
+
message: z3.object({
|
|
794
|
+
content: z3.union([
|
|
795
|
+
z3.object({
|
|
796
|
+
type: z3.literal("text"),
|
|
797
|
+
text: z3.string()
|
|
728
798
|
}),
|
|
729
|
-
|
|
730
|
-
type:
|
|
731
|
-
thinking:
|
|
799
|
+
z3.object({
|
|
800
|
+
type: z3.literal("thinking"),
|
|
801
|
+
thinking: z3.string()
|
|
732
802
|
})
|
|
733
803
|
])
|
|
734
804
|
})
|
|
735
805
|
})
|
|
736
806
|
}),
|
|
737
|
-
|
|
738
|
-
type:
|
|
739
|
-
index:
|
|
740
|
-
delta:
|
|
741
|
-
message:
|
|
742
|
-
content:
|
|
743
|
-
|
|
744
|
-
text:
|
|
807
|
+
z3.object({
|
|
808
|
+
type: z3.literal("content-delta"),
|
|
809
|
+
index: z3.number(),
|
|
810
|
+
delta: z3.object({
|
|
811
|
+
message: z3.object({
|
|
812
|
+
content: z3.union([
|
|
813
|
+
z3.object({
|
|
814
|
+
text: z3.string()
|
|
745
815
|
}),
|
|
746
|
-
|
|
747
|
-
thinking:
|
|
816
|
+
z3.object({
|
|
817
|
+
thinking: z3.string()
|
|
748
818
|
})
|
|
749
819
|
])
|
|
750
820
|
})
|
|
751
821
|
})
|
|
752
822
|
}),
|
|
753
|
-
|
|
754
|
-
type:
|
|
755
|
-
index:
|
|
823
|
+
z3.object({
|
|
824
|
+
type: z3.literal("content-end"),
|
|
825
|
+
index: z3.number()
|
|
756
826
|
}),
|
|
757
|
-
|
|
758
|
-
type:
|
|
759
|
-
id:
|
|
827
|
+
z3.object({
|
|
828
|
+
type: z3.literal("message-start"),
|
|
829
|
+
id: z3.string().nullish()
|
|
760
830
|
}),
|
|
761
|
-
|
|
762
|
-
type:
|
|
763
|
-
delta:
|
|
764
|
-
finish_reason:
|
|
765
|
-
usage:
|
|
766
|
-
tokens:
|
|
767
|
-
input_tokens:
|
|
768
|
-
output_tokens:
|
|
831
|
+
z3.object({
|
|
832
|
+
type: z3.literal("message-end"),
|
|
833
|
+
delta: z3.object({
|
|
834
|
+
finish_reason: z3.string(),
|
|
835
|
+
usage: z3.object({
|
|
836
|
+
tokens: z3.object({
|
|
837
|
+
input_tokens: z3.number(),
|
|
838
|
+
output_tokens: z3.number()
|
|
769
839
|
})
|
|
770
840
|
})
|
|
771
841
|
})
|
|
772
842
|
}),
|
|
773
843
|
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
774
|
-
|
|
775
|
-
type:
|
|
776
|
-
delta:
|
|
777
|
-
message:
|
|
778
|
-
tool_plan:
|
|
844
|
+
z3.object({
|
|
845
|
+
type: z3.literal("tool-plan-delta"),
|
|
846
|
+
delta: z3.object({
|
|
847
|
+
message: z3.object({
|
|
848
|
+
tool_plan: z3.string()
|
|
779
849
|
})
|
|
780
850
|
})
|
|
781
851
|
}),
|
|
782
|
-
|
|
783
|
-
type:
|
|
784
|
-
delta:
|
|
785
|
-
message:
|
|
786
|
-
tool_calls:
|
|
787
|
-
id:
|
|
788
|
-
type:
|
|
789
|
-
function:
|
|
790
|
-
name:
|
|
791
|
-
arguments:
|
|
852
|
+
z3.object({
|
|
853
|
+
type: z3.literal("tool-call-start"),
|
|
854
|
+
delta: z3.object({
|
|
855
|
+
message: z3.object({
|
|
856
|
+
tool_calls: z3.object({
|
|
857
|
+
id: z3.string(),
|
|
858
|
+
type: z3.literal("function"),
|
|
859
|
+
function: z3.object({
|
|
860
|
+
name: z3.string(),
|
|
861
|
+
arguments: z3.string()
|
|
792
862
|
})
|
|
793
863
|
})
|
|
794
864
|
})
|
|
@@ -797,31 +867,41 @@ var cohereChatChunkSchema = import_v43.z.discriminatedUnion("type", [
|
|
|
797
867
|
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
798
868
|
// in a string and so the full tool object info can only be parsed once we see
|
|
799
869
|
// `tool-call-end`.
|
|
800
|
-
|
|
801
|
-
type:
|
|
802
|
-
delta:
|
|
803
|
-
message:
|
|
804
|
-
tool_calls:
|
|
805
|
-
function:
|
|
806
|
-
arguments:
|
|
870
|
+
z3.object({
|
|
871
|
+
type: z3.literal("tool-call-delta"),
|
|
872
|
+
delta: z3.object({
|
|
873
|
+
message: z3.object({
|
|
874
|
+
tool_calls: z3.object({
|
|
875
|
+
function: z3.object({
|
|
876
|
+
arguments: z3.string()
|
|
807
877
|
})
|
|
808
878
|
})
|
|
809
879
|
})
|
|
810
880
|
})
|
|
811
881
|
}),
|
|
812
|
-
|
|
813
|
-
type:
|
|
882
|
+
z3.object({
|
|
883
|
+
type: z3.literal("tool-call-end")
|
|
814
884
|
})
|
|
815
885
|
]);
|
|
816
886
|
|
|
817
887
|
// src/cohere-embedding-model.ts
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
888
|
+
import {
|
|
889
|
+
TooManyEmbeddingValuesForCallError
|
|
890
|
+
} from "@ai-sdk/provider";
|
|
891
|
+
import {
|
|
892
|
+
combineHeaders as combineHeaders2,
|
|
893
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
894
|
+
parseProviderOptions as parseProviderOptions3,
|
|
895
|
+
postJsonToApi as postJsonToApi2,
|
|
896
|
+
serializeModelOptions as serializeModelOptions2,
|
|
897
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
898
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
899
|
+
} from "@ai-sdk/provider-utils";
|
|
900
|
+
import { z as z5 } from "zod/v4";
|
|
821
901
|
|
|
822
|
-
// src/cohere-embedding-options.ts
|
|
823
|
-
|
|
824
|
-
var cohereEmbeddingModelOptions =
|
|
902
|
+
// src/cohere-embedding-model-options.ts
|
|
903
|
+
import { z as z4 } from "zod/v4";
|
|
904
|
+
var cohereEmbeddingModelOptions = z4.object({
|
|
825
905
|
/**
|
|
826
906
|
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
827
907
|
*
|
|
@@ -830,7 +910,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
830
910
|
* - "classification": Used for embeddings passed through a text classifier.
|
|
831
911
|
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
832
912
|
*/
|
|
833
|
-
inputType:
|
|
913
|
+
inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
834
914
|
/**
|
|
835
915
|
* Specifies how the API will handle inputs longer than the maximum token length.
|
|
836
916
|
* Default is `END`.
|
|
@@ -839,7 +919,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
839
919
|
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
840
920
|
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
841
921
|
*/
|
|
842
|
-
truncate:
|
|
922
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional(),
|
|
843
923
|
/**
|
|
844
924
|
* The number of dimensions of the output embedding.
|
|
845
925
|
* Only available for `embed-v4.0` and newer models.
|
|
@@ -847,11 +927,11 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
847
927
|
* Possible values are `256`, `512`, `1024`, and `1536`.
|
|
848
928
|
* The default is `1536`.
|
|
849
929
|
*/
|
|
850
|
-
outputDimension:
|
|
930
|
+
outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
|
|
851
931
|
});
|
|
852
932
|
|
|
853
933
|
// src/cohere-embedding-model.ts
|
|
854
|
-
var CohereEmbeddingModel = class {
|
|
934
|
+
var CohereEmbeddingModel = class _CohereEmbeddingModel {
|
|
855
935
|
constructor(modelId, config) {
|
|
856
936
|
this.specificationVersion = "v4";
|
|
857
937
|
this.maxEmbeddingsPerCall = 96;
|
|
@@ -859,6 +939,15 @@ var CohereEmbeddingModel = class {
|
|
|
859
939
|
this.modelId = modelId;
|
|
860
940
|
this.config = config;
|
|
861
941
|
}
|
|
942
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
943
|
+
return serializeModelOptions2({
|
|
944
|
+
modelId: model.modelId,
|
|
945
|
+
config: model.config
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
949
|
+
return new _CohereEmbeddingModel(options.modelId, options.config);
|
|
950
|
+
}
|
|
862
951
|
get provider() {
|
|
863
952
|
return this.config.provider;
|
|
864
953
|
}
|
|
@@ -868,14 +957,14 @@ var CohereEmbeddingModel = class {
|
|
|
868
957
|
abortSignal,
|
|
869
958
|
providerOptions
|
|
870
959
|
}) {
|
|
871
|
-
var _a;
|
|
872
|
-
const embeddingOptions = await (
|
|
960
|
+
var _a, _b, _c;
|
|
961
|
+
const embeddingOptions = await parseProviderOptions3({
|
|
873
962
|
provider: "cohere",
|
|
874
963
|
providerOptions,
|
|
875
964
|
schema: cohereEmbeddingModelOptions
|
|
876
965
|
});
|
|
877
966
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
878
|
-
throw new
|
|
967
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
879
968
|
provider: this.provider,
|
|
880
969
|
modelId: this.modelId,
|
|
881
970
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -886,9 +975,9 @@ var CohereEmbeddingModel = class {
|
|
|
886
975
|
responseHeaders,
|
|
887
976
|
value: response,
|
|
888
977
|
rawValue
|
|
889
|
-
} = await (
|
|
978
|
+
} = await postJsonToApi2({
|
|
890
979
|
url: `${this.config.baseURL}/embed`,
|
|
891
|
-
headers: (
|
|
980
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
892
981
|
body: {
|
|
893
982
|
model: this.modelId,
|
|
894
983
|
// The AI SDK only supports 'float' embeddings. Note that the Cohere API
|
|
@@ -896,12 +985,12 @@ var CohereEmbeddingModel = class {
|
|
|
896
985
|
// https://docs.cohere.com/v2/reference/embed#request.body.embedding_types
|
|
897
986
|
embedding_types: ["float"],
|
|
898
987
|
texts: values,
|
|
899
|
-
input_type: (
|
|
988
|
+
input_type: (_c = embeddingOptions == null ? void 0 : embeddingOptions.inputType) != null ? _c : "search_query",
|
|
900
989
|
truncate: embeddingOptions == null ? void 0 : embeddingOptions.truncate,
|
|
901
990
|
output_dimension: embeddingOptions == null ? void 0 : embeddingOptions.outputDimension
|
|
902
991
|
},
|
|
903
992
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
904
|
-
successfulResponseHandler: (
|
|
993
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
905
994
|
cohereTextEmbeddingResponseSchema
|
|
906
995
|
),
|
|
907
996
|
abortSignal,
|
|
@@ -915,46 +1004,54 @@ var CohereEmbeddingModel = class {
|
|
|
915
1004
|
};
|
|
916
1005
|
}
|
|
917
1006
|
};
|
|
918
|
-
var cohereTextEmbeddingResponseSchema =
|
|
919
|
-
embeddings:
|
|
920
|
-
float:
|
|
1007
|
+
var cohereTextEmbeddingResponseSchema = z5.object({
|
|
1008
|
+
embeddings: z5.object({
|
|
1009
|
+
float: z5.array(z5.array(z5.number()))
|
|
921
1010
|
}),
|
|
922
|
-
meta:
|
|
923
|
-
billed_units:
|
|
924
|
-
input_tokens:
|
|
1011
|
+
meta: z5.object({
|
|
1012
|
+
billed_units: z5.object({
|
|
1013
|
+
input_tokens: z5.number()
|
|
925
1014
|
})
|
|
926
1015
|
})
|
|
927
1016
|
});
|
|
928
1017
|
|
|
929
1018
|
// src/reranking/cohere-reranking-model.ts
|
|
930
|
-
|
|
1019
|
+
import {
|
|
1020
|
+
combineHeaders as combineHeaders3,
|
|
1021
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1022
|
+
parseProviderOptions as parseProviderOptions4,
|
|
1023
|
+
postJsonToApi as postJsonToApi3
|
|
1024
|
+
} from "@ai-sdk/provider-utils";
|
|
931
1025
|
|
|
932
1026
|
// src/reranking/cohere-reranking-api.ts
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
var cohereRerankingResponseSchema =
|
|
936
|
-
() =>
|
|
937
|
-
|
|
938
|
-
id:
|
|
939
|
-
results:
|
|
940
|
-
|
|
941
|
-
index:
|
|
942
|
-
relevance_score:
|
|
1027
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
1028
|
+
import { z as z6 } from "zod/v4";
|
|
1029
|
+
var cohereRerankingResponseSchema = lazySchema(
|
|
1030
|
+
() => zodSchema(
|
|
1031
|
+
z6.object({
|
|
1032
|
+
id: z6.string().nullish(),
|
|
1033
|
+
results: z6.array(
|
|
1034
|
+
z6.object({
|
|
1035
|
+
index: z6.number(),
|
|
1036
|
+
relevance_score: z6.number()
|
|
943
1037
|
})
|
|
944
1038
|
),
|
|
945
|
-
meta:
|
|
1039
|
+
meta: z6.any()
|
|
946
1040
|
})
|
|
947
1041
|
)
|
|
948
1042
|
);
|
|
949
1043
|
|
|
950
|
-
// src/reranking/cohere-reranking-options.ts
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1044
|
+
// src/reranking/cohere-reranking-model-options.ts
|
|
1045
|
+
import {
|
|
1046
|
+
lazySchema as lazySchema2,
|
|
1047
|
+
zodSchema as zodSchema2
|
|
1048
|
+
} from "@ai-sdk/provider-utils";
|
|
1049
|
+
import { z as z7 } from "zod/v4";
|
|
1050
|
+
var cohereRerankingModelOptionsSchema = lazySchema2(
|
|
1051
|
+
() => zodSchema2(
|
|
1052
|
+
z7.object({
|
|
1053
|
+
maxTokensPerDoc: z7.number().optional(),
|
|
1054
|
+
priority: z7.number().optional()
|
|
958
1055
|
})
|
|
959
1056
|
)
|
|
960
1057
|
);
|
|
@@ -979,7 +1076,7 @@ var CohereRerankingModel = class {
|
|
|
979
1076
|
providerOptions
|
|
980
1077
|
}) {
|
|
981
1078
|
var _a;
|
|
982
|
-
const rerankingOptions = await (
|
|
1079
|
+
const rerankingOptions = await parseProviderOptions4({
|
|
983
1080
|
provider: "cohere",
|
|
984
1081
|
providerOptions,
|
|
985
1082
|
schema: cohereRerankingModelOptionsSchema
|
|
@@ -996,9 +1093,9 @@ var CohereRerankingModel = class {
|
|
|
996
1093
|
responseHeaders,
|
|
997
1094
|
value: response,
|
|
998
1095
|
rawValue
|
|
999
|
-
} = await (
|
|
1096
|
+
} = await postJsonToApi3({
|
|
1000
1097
|
url: `${this.config.baseURL}/rerank`,
|
|
1001
|
-
headers: (
|
|
1098
|
+
headers: combineHeaders3(this.config.headers(), headers),
|
|
1002
1099
|
body: {
|
|
1003
1100
|
model: this.modelId,
|
|
1004
1101
|
query,
|
|
@@ -1008,7 +1105,7 @@ var CohereRerankingModel = class {
|
|
|
1008
1105
|
priority: rerankingOptions == null ? void 0 : rerankingOptions.priority
|
|
1009
1106
|
},
|
|
1010
1107
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
1011
|
-
successfulResponseHandler: (
|
|
1108
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1012
1109
|
cohereRerankingResponseSchema
|
|
1013
1110
|
),
|
|
1014
1111
|
abortSignal,
|
|
@@ -1030,15 +1127,15 @@ var CohereRerankingModel = class {
|
|
|
1030
1127
|
};
|
|
1031
1128
|
|
|
1032
1129
|
// src/version.ts
|
|
1033
|
-
var VERSION = true ? "4.0.0-
|
|
1130
|
+
var VERSION = true ? "4.0.0-canary.34" : "0.0.0-test";
|
|
1034
1131
|
|
|
1035
1132
|
// src/cohere-provider.ts
|
|
1036
1133
|
function createCohere(options = {}) {
|
|
1037
1134
|
var _a;
|
|
1038
|
-
const baseURL = (_a =
|
|
1039
|
-
const getHeaders = () =>
|
|
1135
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.cohere.com/v2";
|
|
1136
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1040
1137
|
{
|
|
1041
|
-
Authorization: `Bearer ${
|
|
1138
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1042
1139
|
apiKey: options.apiKey,
|
|
1043
1140
|
environmentVariableName: "COHERE_API_KEY",
|
|
1044
1141
|
description: "Cohere"
|
|
@@ -1054,7 +1151,7 @@ function createCohere(options = {}) {
|
|
|
1054
1151
|
baseURL,
|
|
1055
1152
|
headers: getHeaders,
|
|
1056
1153
|
fetch: options.fetch,
|
|
1057
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1154
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId
|
|
1058
1155
|
});
|
|
1059
1156
|
};
|
|
1060
1157
|
const createEmbeddingModel = (modelId) => new CohereEmbeddingModel(modelId, {
|
|
@@ -1086,15 +1183,14 @@ function createCohere(options = {}) {
|
|
|
1086
1183
|
provider.reranking = createRerankingModel;
|
|
1087
1184
|
provider.rerankingModel = createRerankingModel;
|
|
1088
1185
|
provider.imageModel = (modelId) => {
|
|
1089
|
-
throw new
|
|
1186
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1090
1187
|
};
|
|
1091
1188
|
return provider;
|
|
1092
1189
|
}
|
|
1093
1190
|
var cohere = createCohere();
|
|
1094
|
-
|
|
1095
|
-
0 && (module.exports = {
|
|
1191
|
+
export {
|
|
1096
1192
|
VERSION,
|
|
1097
1193
|
cohere,
|
|
1098
1194
|
createCohere
|
|
1099
|
-
}
|
|
1195
|
+
};
|
|
1100
1196
|
//# sourceMappingURL=index.js.map
|