@ai-sdk/openai-compatible 3.0.0-beta.16 → 3.0.0-beta.17
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 +6 -0
- package/dist/index.js +53 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/openai-compatible-chat-language-model.ts +25 -10
- package/src/completion/openai-compatible-completion-language-model.ts +11 -3
- package/src/image/openai-compatible-image-model.ts +1 -4
- package/src/utils/to-camel-case.ts +19 -0
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,18 @@ import {
|
|
|
15
15
|
} from "@ai-sdk/provider-utils";
|
|
16
16
|
import { z as z3 } from "zod/v4";
|
|
17
17
|
|
|
18
|
+
// src/utils/to-camel-case.ts
|
|
19
|
+
function toCamelCase(str) {
|
|
20
|
+
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
function resolveProviderOptionsKey(rawName, providerOptions) {
|
|
23
|
+
const camelName = toCamelCase(rawName);
|
|
24
|
+
if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[camelName]) != null) {
|
|
25
|
+
return camelName;
|
|
26
|
+
}
|
|
27
|
+
return rawName;
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
// src/openai-compatible-error.ts
|
|
19
31
|
import { z } from "zod/v4";
|
|
20
32
|
var openaiCompatibleErrorDataSchema = z.object({
|
|
@@ -467,9 +479,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
467
479
|
provider: this.providerOptionsName,
|
|
468
480
|
providerOptions,
|
|
469
481
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
470
|
-
})) != null ? _b : {}
|
|
482
|
+
})) != null ? _b : {},
|
|
483
|
+
(_c = await parseProviderOptions({
|
|
484
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
485
|
+
providerOptions,
|
|
486
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
487
|
+
})) != null ? _c : {}
|
|
471
488
|
);
|
|
472
|
-
const strictJsonSchema = (
|
|
489
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
473
490
|
if (topK != null) {
|
|
474
491
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
475
492
|
}
|
|
@@ -488,7 +505,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
488
505
|
tools,
|
|
489
506
|
toolChoice
|
|
490
507
|
});
|
|
508
|
+
const metadataKey = resolveProviderOptionsKey(
|
|
509
|
+
this.providerOptionsName,
|
|
510
|
+
providerOptions
|
|
511
|
+
);
|
|
491
512
|
return {
|
|
513
|
+
metadataKey,
|
|
492
514
|
args: {
|
|
493
515
|
// model id:
|
|
494
516
|
model: this.modelId,
|
|
@@ -505,16 +527,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
505
527
|
json_schema: {
|
|
506
528
|
schema: responseFormat.schema,
|
|
507
529
|
strict: strictJsonSchema,
|
|
508
|
-
name: (
|
|
530
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
509
531
|
description: responseFormat.description
|
|
510
532
|
}
|
|
511
533
|
} : { type: "json_object" } : void 0,
|
|
512
534
|
stop: stopSequences,
|
|
513
535
|
seed,
|
|
514
536
|
...Object.fromEntries(
|
|
515
|
-
Object.entries(
|
|
516
|
-
|
|
517
|
-
|
|
537
|
+
Object.entries({
|
|
538
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
539
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
540
|
+
}).filter(
|
|
518
541
|
([key]) => !Object.keys(
|
|
519
542
|
openaiCompatibleLanguageModelChatOptions.shape
|
|
520
543
|
).includes(key)
|
|
@@ -533,7 +556,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
533
556
|
}
|
|
534
557
|
async doGenerate(options) {
|
|
535
558
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
536
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
559
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
537
560
|
const transformedBody = this.transformRequestBody(args);
|
|
538
561
|
const body = JSON.stringify(transformedBody);
|
|
539
562
|
const {
|
|
@@ -577,24 +600,24 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
577
600
|
input: toolCall.function.arguments,
|
|
578
601
|
...thoughtSignature ? {
|
|
579
602
|
providerMetadata: {
|
|
580
|
-
[
|
|
603
|
+
[metadataKey]: { thoughtSignature }
|
|
581
604
|
}
|
|
582
605
|
} : {}
|
|
583
606
|
});
|
|
584
607
|
}
|
|
585
608
|
}
|
|
586
609
|
const providerMetadata = {
|
|
587
|
-
[
|
|
610
|
+
[metadataKey]: {},
|
|
588
611
|
...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
|
|
589
612
|
parsedBody: rawResponse
|
|
590
613
|
}))
|
|
591
614
|
};
|
|
592
615
|
const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
|
|
593
616
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
594
|
-
providerMetadata[
|
|
617
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
595
618
|
}
|
|
596
619
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
597
|
-
providerMetadata[
|
|
620
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
598
621
|
}
|
|
599
622
|
return {
|
|
600
623
|
content,
|
|
@@ -615,7 +638,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
615
638
|
}
|
|
616
639
|
async doStream(options) {
|
|
617
640
|
var _a;
|
|
618
|
-
const { args, warnings } = await this.getArgs({
|
|
641
|
+
const { args, warnings, metadataKey } = await this.getArgs({
|
|
642
|
+
...options
|
|
643
|
+
});
|
|
619
644
|
const body = this.transformRequestBody({
|
|
620
645
|
...args,
|
|
621
646
|
stream: true,
|
|
@@ -644,7 +669,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
644
669
|
};
|
|
645
670
|
let usage = void 0;
|
|
646
671
|
let isFirstChunk = true;
|
|
647
|
-
const providerOptionsName =
|
|
672
|
+
const providerOptionsName = metadataKey;
|
|
648
673
|
let isActiveReasoning = false;
|
|
649
674
|
let isActiveText = false;
|
|
650
675
|
return {
|
|
@@ -1188,13 +1213,20 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1188
1213
|
tools,
|
|
1189
1214
|
toolChoice
|
|
1190
1215
|
}) {
|
|
1191
|
-
var _a;
|
|
1216
|
+
var _a, _b;
|
|
1192
1217
|
const warnings = [];
|
|
1193
|
-
const completionOptions = (
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1218
|
+
const completionOptions = Object.assign(
|
|
1219
|
+
(_a = await parseProviderOptions2({
|
|
1220
|
+
provider: this.providerOptionsName,
|
|
1221
|
+
providerOptions,
|
|
1222
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1223
|
+
})) != null ? _a : {},
|
|
1224
|
+
(_b = await parseProviderOptions2({
|
|
1225
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
1226
|
+
providerOptions,
|
|
1227
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1228
|
+
})) != null ? _b : {}
|
|
1229
|
+
);
|
|
1198
1230
|
if (topK != null) {
|
|
1199
1231
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1200
1232
|
}
|
|
@@ -1230,6 +1262,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1230
1262
|
presence_penalty: presencePenalty,
|
|
1231
1263
|
seed,
|
|
1232
1264
|
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
1265
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
1233
1266
|
// prompt:
|
|
1234
1267
|
prompt: completionPrompt,
|
|
1235
1268
|
// stop sequences:
|
|
@@ -1679,9 +1712,6 @@ async function fileToBlob(file) {
|
|
|
1679
1712
|
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array2(file.data);
|
|
1680
1713
|
return new Blob([data], { type: file.mediaType });
|
|
1681
1714
|
}
|
|
1682
|
-
function toCamelCase(str) {
|
|
1683
|
-
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
1684
|
-
}
|
|
1685
1715
|
|
|
1686
1716
|
// src/openai-compatible-provider.ts
|
|
1687
1717
|
import {
|
|
@@ -1690,7 +1720,7 @@ import {
|
|
|
1690
1720
|
} from "@ai-sdk/provider-utils";
|
|
1691
1721
|
|
|
1692
1722
|
// src/version.ts
|
|
1693
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1723
|
+
var VERSION = true ? "3.0.0-beta.17" : "0.0.0-test";
|
|
1694
1724
|
|
|
1695
1725
|
// src/openai-compatible-provider.ts
|
|
1696
1726
|
function createOpenAICompatible(options) {
|