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