@ai-sdk/openai-compatible 3.0.0-beta.16 → 3.0.0-beta.19
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 +24 -0
- package/dist/index.js +94 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/chat/openai-compatible-chat-language-model.ts +39 -12
- package/src/completion/openai-compatible-completion-language-model.ts +21 -3
- package/src/embedding/openai-compatible-embedding-model.ts +11 -2
- package/src/image/openai-compatible-image-model.ts +11 -6
- package/src/utils/to-camel-case.ts +43 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 008271d: feat(openai-compatible): emit warning when using kebab-case instead of camelCase
|
|
8
|
+
- Updated dependencies [34bd95d]
|
|
9
|
+
- Updated dependencies [008271d]
|
|
10
|
+
- @ai-sdk/provider@4.0.0-beta.8
|
|
11
|
+
- @ai-sdk/provider-utils@5.0.0-beta.14
|
|
12
|
+
|
|
13
|
+
## 3.0.0-beta.18
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [b0c2869]
|
|
18
|
+
- Updated dependencies [7e26e81]
|
|
19
|
+
- @ai-sdk/provider-utils@5.0.0-beta.13
|
|
20
|
+
|
|
21
|
+
## 3.0.0-beta.17
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 816ff67: fix(openai-compatible): honor camelCase providerOptions key in chat and completion models
|
|
26
|
+
|
|
3
27
|
## 3.0.0-beta.16
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,32 @@ 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
|
+
function warnIfDeprecatedProviderOptionsKey({
|
|
49
|
+
rawName,
|
|
50
|
+
providerOptions,
|
|
51
|
+
warnings
|
|
52
|
+
}) {
|
|
53
|
+
const camelName = toCamelCase(rawName);
|
|
54
|
+
if (camelName !== rawName && (providerOptions == null ? void 0 : providerOptions[rawName]) != null) {
|
|
55
|
+
warnings.push({
|
|
56
|
+
type: "deprecated",
|
|
57
|
+
setting: `providerOptions key '${rawName}'`,
|
|
58
|
+
message: `Use '${camelName}' instead.`
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
37
63
|
// src/openai-compatible-error.ts
|
|
38
64
|
var import_v4 = require("zod/v4");
|
|
39
65
|
var openaiCompatibleErrorDataSchema = import_v4.z.object({
|
|
@@ -463,10 +489,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
463
489
|
});
|
|
464
490
|
if (deprecatedOptions != null) {
|
|
465
491
|
warnings.push({
|
|
466
|
-
type: "
|
|
467
|
-
|
|
492
|
+
type: "deprecated",
|
|
493
|
+
setting: "providerOptions key 'openai-compatible'",
|
|
494
|
+
message: "Use 'openaiCompatible' instead."
|
|
468
495
|
});
|
|
469
496
|
}
|
|
497
|
+
warnIfDeprecatedProviderOptionsKey({
|
|
498
|
+
rawName: this.providerOptionsName,
|
|
499
|
+
providerOptions,
|
|
500
|
+
warnings
|
|
501
|
+
});
|
|
470
502
|
const compatibleOptions = Object.assign(
|
|
471
503
|
deprecatedOptions != null ? deprecatedOptions : {},
|
|
472
504
|
(_a = await (0, import_provider_utils2.parseProviderOptions)({
|
|
@@ -478,9 +510,14 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
478
510
|
provider: this.providerOptionsName,
|
|
479
511
|
providerOptions,
|
|
480
512
|
schema: openaiCompatibleLanguageModelChatOptions
|
|
481
|
-
})) != null ? _b : {}
|
|
513
|
+
})) != null ? _b : {},
|
|
514
|
+
(_c = await (0, import_provider_utils2.parseProviderOptions)({
|
|
515
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
516
|
+
providerOptions,
|
|
517
|
+
schema: openaiCompatibleLanguageModelChatOptions
|
|
518
|
+
})) != null ? _c : {}
|
|
482
519
|
);
|
|
483
|
-
const strictJsonSchema = (
|
|
520
|
+
const strictJsonSchema = (_d = compatibleOptions == null ? void 0 : compatibleOptions.strictJsonSchema) != null ? _d : true;
|
|
484
521
|
if (topK != null) {
|
|
485
522
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
486
523
|
}
|
|
@@ -499,7 +536,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
499
536
|
tools,
|
|
500
537
|
toolChoice
|
|
501
538
|
});
|
|
539
|
+
const metadataKey = resolveProviderOptionsKey(
|
|
540
|
+
this.providerOptionsName,
|
|
541
|
+
providerOptions
|
|
542
|
+
);
|
|
502
543
|
return {
|
|
544
|
+
metadataKey,
|
|
503
545
|
args: {
|
|
504
546
|
// model id:
|
|
505
547
|
model: this.modelId,
|
|
@@ -516,16 +558,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
516
558
|
json_schema: {
|
|
517
559
|
schema: responseFormat.schema,
|
|
518
560
|
strict: strictJsonSchema,
|
|
519
|
-
name: (
|
|
561
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
520
562
|
description: responseFormat.description
|
|
521
563
|
}
|
|
522
564
|
} : { type: "json_object" } : void 0,
|
|
523
565
|
stop: stopSequences,
|
|
524
566
|
seed,
|
|
525
567
|
...Object.fromEntries(
|
|
526
|
-
Object.entries(
|
|
527
|
-
|
|
528
|
-
|
|
568
|
+
Object.entries({
|
|
569
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
570
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)]
|
|
571
|
+
}).filter(
|
|
529
572
|
([key]) => !Object.keys(
|
|
530
573
|
openaiCompatibleLanguageModelChatOptions.shape
|
|
531
574
|
).includes(key)
|
|
@@ -544,7 +587,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
544
587
|
}
|
|
545
588
|
async doGenerate(options) {
|
|
546
589
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
547
|
-
const { args, warnings } = await this.getArgs({ ...options });
|
|
590
|
+
const { args, warnings, metadataKey } = await this.getArgs({ ...options });
|
|
548
591
|
const transformedBody = this.transformRequestBody(args);
|
|
549
592
|
const body = JSON.stringify(transformedBody);
|
|
550
593
|
const {
|
|
@@ -588,24 +631,24 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
588
631
|
input: toolCall.function.arguments,
|
|
589
632
|
...thoughtSignature ? {
|
|
590
633
|
providerMetadata: {
|
|
591
|
-
[
|
|
634
|
+
[metadataKey]: { thoughtSignature }
|
|
592
635
|
}
|
|
593
636
|
} : {}
|
|
594
637
|
});
|
|
595
638
|
}
|
|
596
639
|
}
|
|
597
640
|
const providerMetadata = {
|
|
598
|
-
[
|
|
641
|
+
[metadataKey]: {},
|
|
599
642
|
...await ((_f = (_e = this.config.metadataExtractor) == null ? void 0 : _e.extractMetadata) == null ? void 0 : _f.call(_e, {
|
|
600
643
|
parsedBody: rawResponse
|
|
601
644
|
}))
|
|
602
645
|
};
|
|
603
646
|
const completionTokenDetails = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens_details;
|
|
604
647
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
605
|
-
providerMetadata[
|
|
648
|
+
providerMetadata[metadataKey].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
606
649
|
}
|
|
607
650
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
608
|
-
providerMetadata[
|
|
651
|
+
providerMetadata[metadataKey].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
609
652
|
}
|
|
610
653
|
return {
|
|
611
654
|
content,
|
|
@@ -626,7 +669,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
626
669
|
}
|
|
627
670
|
async doStream(options) {
|
|
628
671
|
var _a;
|
|
629
|
-
const { args, warnings } = await this.getArgs({
|
|
672
|
+
const { args, warnings, metadataKey } = await this.getArgs({
|
|
673
|
+
...options
|
|
674
|
+
});
|
|
630
675
|
const body = this.transformRequestBody({
|
|
631
676
|
...args,
|
|
632
677
|
stream: true,
|
|
@@ -655,7 +700,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
655
700
|
};
|
|
656
701
|
let usage = void 0;
|
|
657
702
|
let isFirstChunk = true;
|
|
658
|
-
const providerOptionsName =
|
|
703
|
+
const providerOptionsName = metadataKey;
|
|
659
704
|
let isActiveReasoning = false;
|
|
660
705
|
let isActiveText = false;
|
|
661
706
|
return {
|
|
@@ -1189,13 +1234,25 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1189
1234
|
tools,
|
|
1190
1235
|
toolChoice
|
|
1191
1236
|
}) {
|
|
1192
|
-
var _a;
|
|
1237
|
+
var _a, _b;
|
|
1193
1238
|
const warnings = [];
|
|
1194
|
-
|
|
1195
|
-
|
|
1239
|
+
warnIfDeprecatedProviderOptionsKey({
|
|
1240
|
+
rawName: this.providerOptionsName,
|
|
1196
1241
|
providerOptions,
|
|
1197
|
-
|
|
1198
|
-
})
|
|
1242
|
+
warnings
|
|
1243
|
+
});
|
|
1244
|
+
const completionOptions = Object.assign(
|
|
1245
|
+
(_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
1246
|
+
provider: this.providerOptionsName,
|
|
1247
|
+
providerOptions,
|
|
1248
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1249
|
+
})) != null ? _a : {},
|
|
1250
|
+
(_b = await (0, import_provider_utils3.parseProviderOptions)({
|
|
1251
|
+
provider: toCamelCase(this.providerOptionsName),
|
|
1252
|
+
providerOptions,
|
|
1253
|
+
schema: openaiCompatibleLanguageModelCompletionOptions
|
|
1254
|
+
})) != null ? _b : {}
|
|
1255
|
+
);
|
|
1199
1256
|
if (topK != null) {
|
|
1200
1257
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1201
1258
|
}
|
|
@@ -1231,6 +1288,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1231
1288
|
presence_penalty: presencePenalty,
|
|
1232
1289
|
seed,
|
|
1233
1290
|
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
|
1291
|
+
...providerOptions == null ? void 0 : providerOptions[toCamelCase(this.providerOptionsName)],
|
|
1234
1292
|
// prompt:
|
|
1235
1293
|
prompt: completionPrompt,
|
|
1236
1294
|
// stop sequences:
|
|
@@ -1466,10 +1524,16 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1466
1524
|
});
|
|
1467
1525
|
if (deprecatedOptions != null) {
|
|
1468
1526
|
warnings.push({
|
|
1469
|
-
type: "
|
|
1470
|
-
|
|
1527
|
+
type: "deprecated",
|
|
1528
|
+
setting: "providerOptions key 'openai-compatible'",
|
|
1529
|
+
message: "Use 'openaiCompatible' instead."
|
|
1471
1530
|
});
|
|
1472
1531
|
}
|
|
1532
|
+
warnIfDeprecatedProviderOptionsKey({
|
|
1533
|
+
rawName: this.providerOptionsName,
|
|
1534
|
+
providerOptions,
|
|
1535
|
+
warnings
|
|
1536
|
+
});
|
|
1473
1537
|
const compatibleOptions = Object.assign(
|
|
1474
1538
|
deprecatedOptions != null ? deprecatedOptions : {},
|
|
1475
1539
|
(_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
@@ -1551,8 +1615,12 @@ var OpenAICompatibleImageModel = class {
|
|
|
1551
1615
|
get providerOptionsKey() {
|
|
1552
1616
|
return this.config.provider.split(".")[0].trim();
|
|
1553
1617
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1618
|
+
getArgs(providerOptions, warnings) {
|
|
1619
|
+
warnIfDeprecatedProviderOptionsKey({
|
|
1620
|
+
rawName: this.providerOptionsKey,
|
|
1621
|
+
providerOptions,
|
|
1622
|
+
warnings
|
|
1623
|
+
});
|
|
1556
1624
|
return {
|
|
1557
1625
|
...providerOptions[this.providerOptionsKey],
|
|
1558
1626
|
...providerOptions[toCamelCase(this.providerOptionsKey)]
|
|
@@ -1583,7 +1651,7 @@ var OpenAICompatibleImageModel = class {
|
|
|
1583
1651
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
1584
1652
|
}
|
|
1585
1653
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1586
|
-
const args = this.getArgs(providerOptions);
|
|
1654
|
+
const args = this.getArgs(providerOptions, warnings);
|
|
1587
1655
|
if (files != null && files.length > 0) {
|
|
1588
1656
|
const { value: response2, responseHeaders: responseHeaders2 } = await (0, import_provider_utils5.postFormDataToApi)({
|
|
1589
1657
|
url: this.config.url({
|
|
@@ -1663,15 +1731,12 @@ async function fileToBlob(file) {
|
|
|
1663
1731
|
const data = file.data instanceof Uint8Array ? file.data : (0, import_provider_utils5.convertBase64ToUint8Array)(file.data);
|
|
1664
1732
|
return new Blob([data], { type: file.mediaType });
|
|
1665
1733
|
}
|
|
1666
|
-
function toCamelCase(str) {
|
|
1667
|
-
return str.replace(/[_-]([a-z])/g, (g) => g[1].toUpperCase());
|
|
1668
|
-
}
|
|
1669
1734
|
|
|
1670
1735
|
// src/openai-compatible-provider.ts
|
|
1671
1736
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1672
1737
|
|
|
1673
1738
|
// src/version.ts
|
|
1674
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1739
|
+
var VERSION = true ? "3.0.0-beta.19" : "0.0.0-test";
|
|
1675
1740
|
|
|
1676
1741
|
// src/openai-compatible-provider.ts
|
|
1677
1742
|
function createOpenAICompatible(options) {
|