@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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,6 +34,18 @@ var import_provider3 = require("@ai-sdk/provider");
|
|
|
34
34
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
35
35
|
var import_v43 = require("zod/v4");
|
|
36
36
|
|
|
37
|
+
// src/utils/to-camel-case.ts
|
|
38
|
+
function toCamelCase(str) {
|
|
39
|
+
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
40
|
+
}
|
|
41
|
+
function resolveProviderOptionsKey(rawName, providerOptions) {
|
|
42
|
+
const camelName = toCamelCase(rawName);
|
|
43
|
+
if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[camelName]) != null) {
|
|
44
|
+
return camelName;
|
|
45
|
+
}
|
|
46
|
+
return rawName;
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
// src/openai-compatible-error.ts
|
|
38
50
|
var import_v4 = require("zod/v4");
|
|
39
51
|
var openaiCompatibleErrorDataSchema = import_v4.z.object({
|
|
@@ -478,9 +490,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
478
490
|
provider: this.providerOptionsName,
|
|
479
491
|
providerOptions,
|
|
480
492
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
481
|
-
})) != null ? _b : {}
|
|
493
|
+
})) != null ? _b : {},
|
|
494
|
+
(_c = await (0, import_provider_utils2.parseProviderOptions)({
|
|
495
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
496
|
+
providerOptions,
|
|
497
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
498
|
+
})) != null ? _c : {}
|
|
482
499
|
);
|
|
483
|
-
const strictJsonSchema = (
|
|
500
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
484
501
|
if (topK != null) {
|
|
485
502
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
486
503
|
}
|
|
@@ -499,7 +516,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
499
516
|
tools,
|
|
500
517
|
toolChoice
|
|
501
518
|
});
|
|
519
|
+
const metadataKey = resolveProviderOptionsKey(
|
|
520
|
+
this.providerOptionsName,
|
|
521
|
+
providerOptions
|
|
522
|
+
);
|
|
502
523
|
return {
|
|
524
|
+
metadataKey,
|
|
503
525
|
args: {
|
|
504
526
|
// model id:
|
|
505
527
|
model: this.modelId,
|
|
@@ -516,16 +538,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
516
538
|
json_schema: {
|
|
517
539
|
schema: responseFormat.schema,
|
|
518
540
|
strict: strictJsonSchema,
|
|
519
|
-
name: (
|
|
541
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
520
542
|
description: responseFormat.description
|
|
521
543
|
}
|
|
522
544
|
} : { type: "json_object" } : void 0,
|
|
523
545
|
stop: stopSequences,
|
|
524
546
|
seed,
|
|
525
547
|
...Object.fromEntries(
|
|
526
|
-
Object.entries(
|
|
527
|
-
|
|
528
|
-
|
|
548
|
+
Object.entries({
|
|
549
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
550
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
551
|
+
}).filter(
|
|
529
552
|
([key]) => !Object.keys(
|
|
530
553
|
openaiCompatibleLanguageModelChatOptions.shape
|
|
531
554
|
).includes(key)
|
|
@@ -544,7 +567,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
544
567
|
}
|
|
545
568
|
async doGenerate(options) {
|
|
546
569
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
547
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
570
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
548
571
|
const transformedBody = this.transformRequestBody(args);
|
|
549
572
|
const body = JSON.stringify(transformedBody);
|
|
550
573
|
const {
|
|
@@ -588,24 +611,24 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
588
611
|
input: toolCall.function.arguments,
|
|
589
612
|
...thoughtSignature ? {
|
|
590
613
|
providerMetadata: {
|
|
591
|
-
[
|
|
614
|
+
[metadataKey]: { thoughtSignature }
|
|
592
615
|
}
|
|
593
616
|
} : {}
|
|
594
617
|
});
|
|
595
618
|
}
|
|
596
619
|
}
|
|
597
620
|
const providerMetadata = {
|
|
598
|
-
[
|
|
621
|
+
[metadataKey]: {},
|
|
599
622
|
...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
|
|
600
623
|
parsedBody: rawResponse
|
|
601
624
|
}))
|
|
602
625
|
};
|
|
603
626
|
const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
|
|
604
627
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
605
|
-
providerMetadata[
|
|
628
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
606
629
|
}
|
|
607
630
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
608
|
-
providerMetadata[
|
|
631
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
609
632
|
}
|
|
610
633
|
return {
|
|
611
634
|
content,
|
|
@@ -626,7 +649,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
626
649
|
}
|
|
627
650
|
async doStream(options) {
|
|
628
651
|
var _a;
|
|
629
|
-
const { args, warnings } = await this.getArgs({
|
|
652
|
+
const { args, warnings, metadataKey } = await this.getArgs({
|
|
653
|
+
...options
|
|
654
|
+
});
|
|
630
655
|
const body = this.transformRequestBody({
|
|
631
656
|
...args,
|
|
632
657
|
stream: true,
|
|
@@ -655,7 +680,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
655
680
|
};
|
|
656
681
|
let usage = void 0;
|
|
657
682
|
let isFirstChunk = true;
|
|
658
|
-
const providerOptionsName =
|
|
683
|
+
const providerOptionsName = metadataKey;
|
|
659
684
|
let isActiveReasoning = false;
|
|
660
685
|
let isActiveText = false;
|
|
661
686
|
return {
|
|
@@ -1189,13 +1214,20 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1189
1214
|
tools,
|
|
1190
1215
|
toolChoice
|
|
1191
1216
|
}) {
|
|
1192
|
-
var _a;
|
|
1217
|
+
var _a, _b;
|
|
1193
1218
|
const warnings = [];
|
|
1194
|
-
const completionOptions =
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1219
|
+
const completionOptions = Object.assign(
|
|
1220
|
+
(_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
1221
|
+
provider: this.providerOptionsName,
|
|
1222
|
+
providerOptions,
|
|
1223
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1224
|
+
})) != null ? _a : {},
|
|
1225
|
+
(_b = await (0, import_provider_utils3.parseProviderOptions)({
|
|
1226
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
1227
|
+
providerOptions,
|
|
1228
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1229
|
+
})) != null ? _b : {}
|
|
1230
|
+
);
|
|
1199
1231
|
if (topK != null) {
|
|
1200
1232
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1201
1233
|
}
|
|
@@ -1231,6 +1263,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1231
1263
|
presence_penalty: presencePenalty,
|
|
1232
1264
|
seed,
|
|
1233
1265
|
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
1266
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
1234
1267
|
// prompt:
|
|
1235
1268
|
prompt: completionPrompt,
|
|
1236
1269
|
// stop sequences:
|
|
@@ -1663,15 +1696,12 @@ async function fileToBlob(file) {
|
|
|
1663
1696
|
const data = file.data instanceof Uint8Array ? file.data : (0, import_provider_utils5.convertBase64ToUint8Array)(file.data);
|
|
1664
1697
|
return new Blob([data], { type: file.mediaType });
|
|
1665
1698
|
}
|
|
1666
|
-
function toCamelCase(str) {
|
|
1667
|
-
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
1668
|
-
}
|
|
1669
1699
|
|
|
1670
1700
|
// src/openai-compatible-provider.ts
|
|
1671
1701
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1672
1702
|
|
|
1673
1703
|
// src/version.ts
|
|
1674
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1704
|
+
var VERSION = true ? "3.0.0-beta.17" : "0.0.0-test";
|
|
1675
1705
|
|
|
1676
1706
|
// src/openai-compatible-provider.ts
|
|
1677
1707
|
function createOpenAICompatible(options) {
|