@ai-sdk/openai-compatible 2.0.11 → 2.0.13
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 +14 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -0
- package/dist/internal/index.d.ts +6 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 2.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5c090e7]
|
|
8
|
+
- @ai-sdk/provider@3.0.4
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.8
|
|
10
|
+
|
|
11
|
+
## 2.0.12
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 78a133a: feat(openai-compatible): add transformRequestBody function for openai-compatible
|
|
16
|
+
|
|
3
17
|
## 2.0.11
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,12 @@ type OpenAICompatibleChatConfig = {
|
|
|
88
88
|
* The supported URLs for the model.
|
|
89
89
|
*/
|
|
90
90
|
supportedUrls?: () => LanguageModelV3['supportedUrls'];
|
|
91
|
+
/**
|
|
92
|
+
* Optional function to transform the request body before sending it to the API.
|
|
93
|
+
* This is useful for proxy providers that may require a different request format
|
|
94
|
+
* than the official OpenAI API.
|
|
95
|
+
*/
|
|
96
|
+
transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
|
|
91
97
|
};
|
|
92
98
|
declare class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
|
|
93
99
|
readonly specificationVersion = "v3";
|
|
@@ -100,6 +106,7 @@ declare class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
|
|
|
100
106
|
get provider(): string;
|
|
101
107
|
private get providerOptionsName();
|
|
102
108
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
109
|
+
private transformRequestBody;
|
|
103
110
|
private getArgs;
|
|
104
111
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
105
112
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
@@ -255,6 +262,12 @@ interface OpenAICompatibleProviderSettings {
|
|
|
255
262
|
* Whether the provider supports structured outputs in chat models.
|
|
256
263
|
*/
|
|
257
264
|
supportsStructuredOutputs?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Optional function to transform the request body before sending it to the API.
|
|
267
|
+
* This is useful for proxy providers that may require a different request format
|
|
268
|
+
* than the official OpenAI API.
|
|
269
|
+
*/
|
|
270
|
+
transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
|
|
258
271
|
}
|
|
259
272
|
/**
|
|
260
273
|
Create an OpenAICompatible provider instance.
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,12 @@ type OpenAICompatibleChatConfig = {
|
|
|
88
88
|
* The supported URLs for the model.
|
|
89
89
|
*/
|
|
90
90
|
supportedUrls?: () => LanguageModelV3['supportedUrls'];
|
|
91
|
+
/**
|
|
92
|
+
* Optional function to transform the request body before sending it to the API.
|
|
93
|
+
* This is useful for proxy providers that may require a different request format
|
|
94
|
+
* than the official OpenAI API.
|
|
95
|
+
*/
|
|
96
|
+
transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
|
|
91
97
|
};
|
|
92
98
|
declare class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
|
|
93
99
|
readonly specificationVersion = "v3";
|
|
@@ -100,6 +106,7 @@ declare class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
|
|
|
100
106
|
get provider(): string;
|
|
101
107
|
private get providerOptionsName();
|
|
102
108
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
109
|
+
private transformRequestBody;
|
|
103
110
|
private getArgs;
|
|
104
111
|
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
105
112
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
@@ -255,6 +262,12 @@ interface OpenAICompatibleProviderSettings {
|
|
|
255
262
|
* Whether the provider supports structured outputs in chat models.
|
|
256
263
|
*/
|
|
257
264
|
supportsStructuredOutputs?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Optional function to transform the request body before sending it to the API.
|
|
267
|
+
* This is useful for proxy providers that may require a different request format
|
|
268
|
+
* than the official OpenAI API.
|
|
269
|
+
*/
|
|
270
|
+
transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
|
|
258
271
|
}
|
|
259
272
|
/**
|
|
260
273
|
Create an OpenAICompatible provider instance.
|
package/dist/index.js
CHANGED
|
@@ -366,6 +366,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
366
366
|
var _a, _b, _c;
|
|
367
367
|
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
368
368
|
}
|
|
369
|
+
transformRequestBody(args) {
|
|
370
|
+
var _a, _b, _c;
|
|
371
|
+
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
372
|
+
}
|
|
369
373
|
async getArgs({
|
|
370
374
|
prompt,
|
|
371
375
|
maxOutputTokens,
|
|
@@ -458,7 +462,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
458
462
|
async doGenerate(options) {
|
|
459
463
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
460
464
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
461
|
-
const
|
|
465
|
+
const transformedBody = this.transformRequestBody(args);
|
|
466
|
+
const body = JSON.stringify(transformedBody);
|
|
462
467
|
const {
|
|
463
468
|
responseHeaders,
|
|
464
469
|
value: responseBody,
|
|
@@ -469,7 +474,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
469
474
|
modelId: this.modelId
|
|
470
475
|
}),
|
|
471
476
|
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
|
472
|
-
body:
|
|
477
|
+
body: transformedBody,
|
|
473
478
|
failedResponseHandler: this.failedResponseHandler,
|
|
474
479
|
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
|
475
480
|
OpenAICompatibleChatResponseSchema
|
|
@@ -539,12 +544,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
539
544
|
async doStream(options) {
|
|
540
545
|
var _a;
|
|
541
546
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
542
|
-
const body = {
|
|
547
|
+
const body = this.transformRequestBody({
|
|
543
548
|
...args,
|
|
544
549
|
stream: true,
|
|
545
550
|
// only include stream_options when in strict compatibility mode:
|
|
546
551
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
547
|
-
};
|
|
552
|
+
});
|
|
548
553
|
const metadataExtractor = (_a = this.config.metadataExtractor) == null ? void 0 : _a.createStreamExtractor();
|
|
549
554
|
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
|
550
555
|
url: this.config.url({
|
|
@@ -1553,7 +1558,7 @@ async function fileToBlob(file) {
|
|
|
1553
1558
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1554
1559
|
|
|
1555
1560
|
// src/version.ts
|
|
1556
|
-
var VERSION = true ? "2.0.
|
|
1561
|
+
var VERSION = true ? "2.0.13" : "0.0.0-test";
|
|
1557
1562
|
|
|
1558
1563
|
// src/openai-compatible-provider.ts
|
|
1559
1564
|
function createOpenAICompatible(options) {
|
|
@@ -1580,7 +1585,8 @@ function createOpenAICompatible(options) {
|
|
|
1580
1585
|
const createChatModel = (modelId) => new OpenAICompatibleChatLanguageModel(modelId, {
|
|
1581
1586
|
...getCommonModelConfig("chat"),
|
|
1582
1587
|
includeUsage: options.includeUsage,
|
|
1583
|
-
supportsStructuredOutputs: options.supportsStructuredOutputs
|
|
1588
|
+
supportsStructuredOutputs: options.supportsStructuredOutputs,
|
|
1589
|
+
transformRequestBody: options.transformRequestBody
|
|
1584
1590
|
});
|
|
1585
1591
|
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(modelId, {
|
|
1586
1592
|
...getCommonModelConfig("completion"),
|