@ai-sdk/openai-compatible 0.0.6 → 0.0.7
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.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +73 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ProviderV1, LanguageModelV1, EmbeddingModelV1, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider';
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
3
|
+
import { ZodSchema } from 'zod';
|
3
4
|
|
4
5
|
type OpenAICompatibleChatModelId = string;
|
5
6
|
interface OpenAICompatibleChatSettings {
|
@@ -87,6 +88,12 @@ Create an OpenAICompatible provider instance.
|
|
87
88
|
*/
|
88
89
|
declare function createOpenAICompatible<CHAT_MODEL_IDS extends string, COMPLETION_MODEL_IDS extends string, EMBEDDING_MODEL_IDS extends string>(options: OpenAICompatibleProviderSettings): OpenAICompatibleProvider<CHAT_MODEL_IDS, COMPLETION_MODEL_IDS, EMBEDDING_MODEL_IDS>;
|
89
90
|
|
91
|
+
type ProviderErrorStructure<T> = {
|
92
|
+
errorSchema: ZodSchema<T>;
|
93
|
+
errorToMessage: (error: T) => string;
|
94
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
95
|
+
};
|
96
|
+
|
90
97
|
type OpenAICompatibleChatConfig = {
|
91
98
|
provider: string;
|
92
99
|
headers: () => Record<string, string | undefined>;
|
@@ -95,6 +102,7 @@ type OpenAICompatibleChatConfig = {
|
|
95
102
|
path: string;
|
96
103
|
}) => string;
|
97
104
|
fetch?: FetchFunction;
|
105
|
+
errorStructure?: ProviderErrorStructure<any>;
|
98
106
|
/**
|
99
107
|
Default object generation mode that should be used with this model when
|
100
108
|
no mode is specified. Should be the mode with the best results for this
|
@@ -112,6 +120,8 @@ declare class OpenAICompatibleChatLanguageModel implements LanguageModelV1 {
|
|
112
120
|
readonly modelId: OpenAICompatibleChatModelId;
|
113
121
|
readonly settings: OpenAICompatibleChatSettings;
|
114
122
|
private readonly config;
|
123
|
+
private readonly failedResponseHandler;
|
124
|
+
private readonly chunkSchema;
|
115
125
|
constructor(modelId: OpenAICompatibleChatModelId, settings: OpenAICompatibleChatSettings, config: OpenAICompatibleChatConfig);
|
116
126
|
get defaultObjectGenerationMode(): 'json' | 'tool' | undefined;
|
117
127
|
get provider(): string;
|
@@ -128,6 +138,7 @@ type OpenAICompatibleCompletionConfig = {
|
|
128
138
|
path: string;
|
129
139
|
}) => string;
|
130
140
|
fetch?: FetchFunction;
|
141
|
+
errorStructure?: ProviderErrorStructure<any>;
|
131
142
|
};
|
132
143
|
declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV1 {
|
133
144
|
readonly specificationVersion = "v1";
|
@@ -135,6 +146,8 @@ declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV1
|
|
135
146
|
readonly modelId: OpenAICompatibleCompletionModelId;
|
136
147
|
readonly settings: OpenAICompatibleCompletionSettings;
|
137
148
|
private readonly config;
|
149
|
+
private readonly failedResponseHandler;
|
150
|
+
private readonly chunkSchema;
|
138
151
|
constructor(modelId: OpenAICompatibleCompletionModelId, settings: OpenAICompatibleCompletionSettings, config: OpenAICompatibleCompletionConfig);
|
139
152
|
get provider(): string;
|
140
153
|
private getArgs;
|
@@ -158,6 +171,7 @@ type OpenAICompatibleEmbeddingConfig = {
|
|
158
171
|
}) => string;
|
159
172
|
headers: () => Record<string, string | undefined>;
|
160
173
|
fetch?: FetchFunction;
|
174
|
+
errorStructure?: ProviderErrorStructure<any>;
|
161
175
|
};
|
162
176
|
declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV1<string> {
|
163
177
|
readonly specificationVersion = "v1";
|
@@ -171,4 +185,4 @@ declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV1<string>
|
|
171
185
|
doEmbed({ values, headers, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
|
172
186
|
}
|
173
187
|
|
174
|
-
export { OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatSettings, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionSettings, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderSettings, createOpenAICompatible };
|
188
|
+
export { OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatSettings, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionSettings, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderSettings, type ProviderErrorStructure, createOpenAICompatible };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ProviderV1, LanguageModelV1, EmbeddingModelV1, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider';
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
3
|
+
import { ZodSchema } from 'zod';
|
3
4
|
|
4
5
|
type OpenAICompatibleChatModelId = string;
|
5
6
|
interface OpenAICompatibleChatSettings {
|
@@ -87,6 +88,12 @@ Create an OpenAICompatible provider instance.
|
|
87
88
|
*/
|
88
89
|
declare function createOpenAICompatible<CHAT_MODEL_IDS extends string, COMPLETION_MODEL_IDS extends string, EMBEDDING_MODEL_IDS extends string>(options: OpenAICompatibleProviderSettings): OpenAICompatibleProvider<CHAT_MODEL_IDS, COMPLETION_MODEL_IDS, EMBEDDING_MODEL_IDS>;
|
89
90
|
|
91
|
+
type ProviderErrorStructure<T> = {
|
92
|
+
errorSchema: ZodSchema<T>;
|
93
|
+
errorToMessage: (error: T) => string;
|
94
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
95
|
+
};
|
96
|
+
|
90
97
|
type OpenAICompatibleChatConfig = {
|
91
98
|
provider: string;
|
92
99
|
headers: () => Record<string, string | undefined>;
|
@@ -95,6 +102,7 @@ type OpenAICompatibleChatConfig = {
|
|
95
102
|
path: string;
|
96
103
|
}) => string;
|
97
104
|
fetch?: FetchFunction;
|
105
|
+
errorStructure?: ProviderErrorStructure<any>;
|
98
106
|
/**
|
99
107
|
Default object generation mode that should be used with this model when
|
100
108
|
no mode is specified. Should be the mode with the best results for this
|
@@ -112,6 +120,8 @@ declare class OpenAICompatibleChatLanguageModel implements LanguageModelV1 {
|
|
112
120
|
readonly modelId: OpenAICompatibleChatModelId;
|
113
121
|
readonly settings: OpenAICompatibleChatSettings;
|
114
122
|
private readonly config;
|
123
|
+
private readonly failedResponseHandler;
|
124
|
+
private readonly chunkSchema;
|
115
125
|
constructor(modelId: OpenAICompatibleChatModelId, settings: OpenAICompatibleChatSettings, config: OpenAICompatibleChatConfig);
|
116
126
|
get defaultObjectGenerationMode(): 'json' | 'tool' | undefined;
|
117
127
|
get provider(): string;
|
@@ -128,6 +138,7 @@ type OpenAICompatibleCompletionConfig = {
|
|
128
138
|
path: string;
|
129
139
|
}) => string;
|
130
140
|
fetch?: FetchFunction;
|
141
|
+
errorStructure?: ProviderErrorStructure<any>;
|
131
142
|
};
|
132
143
|
declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV1 {
|
133
144
|
readonly specificationVersion = "v1";
|
@@ -135,6 +146,8 @@ declare class OpenAICompatibleCompletionLanguageModel implements LanguageModelV1
|
|
135
146
|
readonly modelId: OpenAICompatibleCompletionModelId;
|
136
147
|
readonly settings: OpenAICompatibleCompletionSettings;
|
137
148
|
private readonly config;
|
149
|
+
private readonly failedResponseHandler;
|
150
|
+
private readonly chunkSchema;
|
138
151
|
constructor(modelId: OpenAICompatibleCompletionModelId, settings: OpenAICompatibleCompletionSettings, config: OpenAICompatibleCompletionConfig);
|
139
152
|
get provider(): string;
|
140
153
|
private getArgs;
|
@@ -158,6 +171,7 @@ type OpenAICompatibleEmbeddingConfig = {
|
|
158
171
|
}) => string;
|
159
172
|
headers: () => Record<string, string | undefined>;
|
160
173
|
fetch?: FetchFunction;
|
174
|
+
errorStructure?: ProviderErrorStructure<any>;
|
161
175
|
};
|
162
176
|
declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV1<string> {
|
163
177
|
readonly specificationVersion = "v1";
|
@@ -171,4 +185,4 @@ declare class OpenAICompatibleEmbeddingModel implements EmbeddingModelV1<string>
|
|
171
185
|
doEmbed({ values, headers, abortSignal, }: Parameters<EmbeddingModelV1<string>['doEmbed']>[0]): Promise<Awaited<ReturnType<EmbeddingModelV1<string>['doEmbed']>>>;
|
172
186
|
}
|
173
187
|
|
174
|
-
export { OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatSettings, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionSettings, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderSettings, createOpenAICompatible };
|
188
|
+
export { OpenAICompatibleChatLanguageModel, type OpenAICompatibleChatSettings, OpenAICompatibleCompletionLanguageModel, type OpenAICompatibleCompletionSettings, OpenAICompatibleEmbeddingModel, type OpenAICompatibleEmbeddingSettings, type OpenAICompatibleProvider, type OpenAICompatibleProviderSettings, type ProviderErrorStructure, createOpenAICompatible };
|
package/dist/index.js
CHANGED
@@ -28,11 +28,11 @@ __export(src_exports, {
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
29
29
|
|
30
30
|
// src/openai-compatible-provider.ts
|
31
|
-
var
|
31
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
32
32
|
|
33
33
|
// src/openai-compatible-chat-language-model.ts
|
34
34
|
var import_provider3 = require("@ai-sdk/provider");
|
35
|
-
var
|
35
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
36
36
|
var import_zod2 = require("zod");
|
37
37
|
|
38
38
|
// src/convert-to-openai-compatible-chat-messages.ts
|
@@ -142,9 +142,25 @@ function getResponseMetadata({
|
|
142
142
|
};
|
143
143
|
}
|
144
144
|
|
145
|
+
// src/map-openai-compatible-finish-reason.ts
|
146
|
+
function mapOpenAICompatibleFinishReason(finishReason) {
|
147
|
+
switch (finishReason) {
|
148
|
+
case "stop":
|
149
|
+
return "stop";
|
150
|
+
case "length":
|
151
|
+
return "length";
|
152
|
+
case "content_filter":
|
153
|
+
return "content-filter";
|
154
|
+
case "function_call":
|
155
|
+
case "tool_calls":
|
156
|
+
return "tool-calls";
|
157
|
+
default:
|
158
|
+
return "unknown";
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
145
162
|
// src/openai-compatible-error.ts
|
146
163
|
var import_zod = require("zod");
|
147
|
-
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
148
164
|
var openaiCompatibleErrorDataSchema = import_zod.z.object({
|
149
165
|
error: import_zod.z.object({
|
150
166
|
message: import_zod.z.string(),
|
@@ -156,10 +172,10 @@ var openaiCompatibleErrorDataSchema = import_zod.z.object({
|
|
156
172
|
code: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).nullish()
|
157
173
|
})
|
158
174
|
});
|
159
|
-
var
|
175
|
+
var defaultOpenAICompatibleErrorStructure = {
|
160
176
|
errorSchema: openaiCompatibleErrorDataSchema,
|
161
177
|
errorToMessage: (data) => data.error.message
|
162
|
-
}
|
178
|
+
};
|
163
179
|
|
164
180
|
// src/openai-compatible-prepare-tools.ts
|
165
181
|
var import_provider2 = require("@ai-sdk/provider");
|
@@ -219,32 +235,21 @@ function prepareTools({
|
|
219
235
|
}
|
220
236
|
}
|
221
237
|
|
222
|
-
// src/map-openai-compatible-finish-reason.ts
|
223
|
-
function mapOpenAICompatibleFinishReason(finishReason) {
|
224
|
-
switch (finishReason) {
|
225
|
-
case "stop":
|
226
|
-
return "stop";
|
227
|
-
case "length":
|
228
|
-
return "length";
|
229
|
-
case "content_filter":
|
230
|
-
return "content-filter";
|
231
|
-
case "function_call":
|
232
|
-
case "tool_calls":
|
233
|
-
return "tool-calls";
|
234
|
-
default:
|
235
|
-
return "unknown";
|
236
|
-
}
|
237
|
-
}
|
238
|
-
|
239
238
|
// src/openai-compatible-chat-language-model.ts
|
240
239
|
var OpenAICompatibleChatLanguageModel = class {
|
240
|
+
// type inferred via constructor
|
241
241
|
constructor(modelId, settings, config) {
|
242
242
|
this.specificationVersion = "v1";
|
243
|
-
var _a;
|
243
|
+
var _a, _b;
|
244
244
|
this.modelId = modelId;
|
245
245
|
this.settings = settings;
|
246
246
|
this.config = config;
|
247
|
-
|
247
|
+
const errorStructure = (_a = config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure;
|
248
|
+
this.chunkSchema = createOpenAICompatibleChatChunkSchema(
|
249
|
+
errorStructure.errorSchema
|
250
|
+
);
|
251
|
+
this.failedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)(errorStructure);
|
252
|
+
this.supportsStructuredOutputs = (_b = config.supportsStructuredOutputs) != null ? _b : false;
|
248
253
|
}
|
249
254
|
get defaultObjectGenerationMode() {
|
250
255
|
return this.config.defaultObjectGenerationMode;
|
@@ -367,15 +372,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
367
372
|
var _a, _b, _c, _d, _e, _f;
|
368
373
|
const { args, warnings } = this.getArgs({ ...options });
|
369
374
|
const body = JSON.stringify(args);
|
370
|
-
const { responseHeaders, value: response } = await (0,
|
375
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
371
376
|
url: this.config.url({
|
372
377
|
path: "/chat/completions",
|
373
378
|
modelId: this.modelId
|
374
379
|
}),
|
375
|
-
headers: (0,
|
380
|
+
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
376
381
|
body: args,
|
377
|
-
failedResponseHandler:
|
378
|
-
successfulResponseHandler: (0,
|
382
|
+
failedResponseHandler: this.failedResponseHandler,
|
383
|
+
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
379
384
|
OpenAICompatibleChatResponseSchema
|
380
385
|
),
|
381
386
|
abortSignal: options.abortSignal,
|
@@ -389,7 +394,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
389
394
|
var _a2;
|
390
395
|
return {
|
391
396
|
toolCallType: "function",
|
392
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0,
|
397
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils2.generateId)(),
|
393
398
|
toolName: toolCall.function.name,
|
394
399
|
args: toolCall.function.arguments
|
395
400
|
};
|
@@ -409,19 +414,19 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
409
414
|
async doStream(options) {
|
410
415
|
const { args, warnings } = this.getArgs({ ...options });
|
411
416
|
const body = JSON.stringify({ ...args, stream: true });
|
412
|
-
const { responseHeaders, value: response } = await (0,
|
417
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
413
418
|
url: this.config.url({
|
414
419
|
path: "/chat/completions",
|
415
420
|
modelId: this.modelId
|
416
421
|
}),
|
417
|
-
headers: (0,
|
422
|
+
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
418
423
|
body: {
|
419
424
|
...args,
|
420
425
|
stream: true
|
421
426
|
},
|
422
|
-
failedResponseHandler:
|
423
|
-
successfulResponseHandler: (0,
|
424
|
-
|
427
|
+
failedResponseHandler: this.failedResponseHandler,
|
428
|
+
successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
|
429
|
+
this.chunkSchema
|
425
430
|
),
|
426
431
|
abortSignal: options.abortSignal,
|
427
432
|
fetch: this.config.fetch
|
@@ -522,11 +527,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
522
527
|
argsTextDelta: toolCall2.function.arguments
|
523
528
|
});
|
524
529
|
}
|
525
|
-
if ((0,
|
530
|
+
if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
|
526
531
|
controller.enqueue({
|
527
532
|
type: "tool-call",
|
528
533
|
toolCallType: "function",
|
529
|
-
toolCallId: (_g = toolCall2.id) != null ? _g : (0,
|
534
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils2.generateId)(),
|
530
535
|
toolName: toolCall2.function.name,
|
531
536
|
args: toolCall2.function.arguments
|
532
537
|
});
|
@@ -549,11 +554,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
549
554
|
toolName: toolCall.function.name,
|
550
555
|
argsTextDelta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
551
556
|
});
|
552
|
-
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0,
|
557
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
553
558
|
controller.enqueue({
|
554
559
|
type: "tool-call",
|
555
560
|
toolCallType: "function",
|
556
|
-
toolCallId: (_n = toolCall.id) != null ? _n : (0,
|
561
|
+
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils2.generateId)(),
|
557
562
|
toolName: toolCall.function.name,
|
558
563
|
args: toolCall.function.arguments
|
559
564
|
});
|
@@ -611,7 +616,7 @@ var OpenAICompatibleChatResponseSchema = import_zod2.z.object({
|
|
611
616
|
completion_tokens: import_zod2.z.number().nullish()
|
612
617
|
}).nullish()
|
613
618
|
});
|
614
|
-
var
|
619
|
+
var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod2.z.union([
|
615
620
|
import_zod2.z.object({
|
616
621
|
id: import_zod2.z.string().nullish(),
|
617
622
|
created: import_zod2.z.number().nullish(),
|
@@ -641,12 +646,12 @@ var OpenAICompatibleChatChunkSchema = import_zod2.z.union([
|
|
641
646
|
completion_tokens: import_zod2.z.number().nullish()
|
642
647
|
}).nullish()
|
643
648
|
}),
|
644
|
-
|
649
|
+
errorSchema
|
645
650
|
]);
|
646
651
|
|
647
652
|
// src/openai-compatible-completion-language-model.ts
|
648
653
|
var import_provider5 = require("@ai-sdk/provider");
|
649
|
-
var
|
654
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
650
655
|
var import_zod3 = require("zod");
|
651
656
|
|
652
657
|
// src/convert-to-openai-compatible-completion-prompt.ts
|
@@ -735,12 +740,19 @@ ${user}:`]
|
|
735
740
|
|
736
741
|
// src/openai-compatible-completion-language-model.ts
|
737
742
|
var OpenAICompatibleCompletionLanguageModel = class {
|
743
|
+
// type inferred via constructor
|
738
744
|
constructor(modelId, settings, config) {
|
739
745
|
this.specificationVersion = "v1";
|
740
746
|
this.defaultObjectGenerationMode = void 0;
|
747
|
+
var _a;
|
741
748
|
this.modelId = modelId;
|
742
749
|
this.settings = settings;
|
743
750
|
this.config = config;
|
751
|
+
const errorStructure = (_a = config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure;
|
752
|
+
this.chunkSchema = createOpenAICompatibleCompletionChunkSchema(
|
753
|
+
errorStructure.errorSchema
|
754
|
+
);
|
755
|
+
this.failedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)(errorStructure);
|
744
756
|
}
|
745
757
|
get provider() {
|
746
758
|
return this.config.provider;
|
@@ -830,15 +842,15 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
830
842
|
async doGenerate(options) {
|
831
843
|
var _a, _b, _c, _d;
|
832
844
|
const { args, warnings } = this.getArgs(options);
|
833
|
-
const { responseHeaders, value: response } = await (0,
|
845
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
834
846
|
url: this.config.url({
|
835
847
|
path: "/completions",
|
836
848
|
modelId: this.modelId
|
837
849
|
}),
|
838
|
-
headers: (0,
|
850
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
839
851
|
body: args,
|
840
|
-
failedResponseHandler:
|
841
|
-
successfulResponseHandler: (0,
|
852
|
+
failedResponseHandler: this.failedResponseHandler,
|
853
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
842
854
|
openaiCompatibleCompletionResponseSchema
|
843
855
|
),
|
844
856
|
abortSignal: options.abortSignal,
|
@@ -866,16 +878,16 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
866
878
|
...args,
|
867
879
|
stream: true
|
868
880
|
};
|
869
|
-
const { responseHeaders, value: response } = await (0,
|
881
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
870
882
|
url: this.config.url({
|
871
883
|
path: "/completions",
|
872
884
|
modelId: this.modelId
|
873
885
|
}),
|
874
|
-
headers: (0,
|
886
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
875
887
|
body,
|
876
|
-
failedResponseHandler:
|
877
|
-
successfulResponseHandler: (0,
|
878
|
-
|
888
|
+
failedResponseHandler: this.failedResponseHandler,
|
889
|
+
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
890
|
+
this.chunkSchema
|
879
891
|
),
|
880
892
|
abortSignal: options.abortSignal,
|
881
893
|
fetch: this.config.fetch
|
@@ -959,7 +971,7 @@ var openaiCompatibleCompletionResponseSchema = import_zod3.z.object({
|
|
959
971
|
completion_tokens: import_zod3.z.number()
|
960
972
|
}).nullish()
|
961
973
|
});
|
962
|
-
var
|
974
|
+
var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod3.z.union([
|
963
975
|
import_zod3.z.object({
|
964
976
|
id: import_zod3.z.string().nullish(),
|
965
977
|
created: import_zod3.z.number().nullish(),
|
@@ -976,12 +988,12 @@ var openaiCompatibleCompletionChunkSchema = import_zod3.z.union([
|
|
976
988
|
completion_tokens: import_zod3.z.number()
|
977
989
|
}).nullish()
|
978
990
|
}),
|
979
|
-
|
991
|
+
errorSchema
|
980
992
|
]);
|
981
993
|
|
982
994
|
// src/openai-compatible-embedding-model.ts
|
983
995
|
var import_provider6 = require("@ai-sdk/provider");
|
984
|
-
var
|
996
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
985
997
|
var import_zod4 = require("zod");
|
986
998
|
var OpenAICompatibleEmbeddingModel = class {
|
987
999
|
constructor(modelId, settings, config) {
|
@@ -1006,6 +1018,7 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1006
1018
|
headers,
|
1007
1019
|
abortSignal
|
1008
1020
|
}) {
|
1021
|
+
var _a;
|
1009
1022
|
if (values.length > this.maxEmbeddingsPerCall) {
|
1010
1023
|
throw new import_provider6.TooManyEmbeddingValuesForCallError({
|
1011
1024
|
provider: this.provider,
|
@@ -1014,12 +1027,12 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1014
1027
|
values
|
1015
1028
|
});
|
1016
1029
|
}
|
1017
|
-
const { responseHeaders, value: response } = await (0,
|
1030
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
1018
1031
|
url: this.config.url({
|
1019
1032
|
path: "/embeddings",
|
1020
1033
|
modelId: this.modelId
|
1021
1034
|
}),
|
1022
|
-
headers: (0,
|
1035
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), headers),
|
1023
1036
|
body: {
|
1024
1037
|
model: this.modelId,
|
1025
1038
|
input: values,
|
@@ -1027,8 +1040,10 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1027
1040
|
dimensions: this.settings.dimensions,
|
1028
1041
|
user: this.settings.user
|
1029
1042
|
},
|
1030
|
-
failedResponseHandler:
|
1031
|
-
|
1043
|
+
failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)(
|
1044
|
+
(_a = this.config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure
|
1045
|
+
),
|
1046
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
1032
1047
|
openaiTextEmbeddingResponseSchema
|
1033
1048
|
),
|
1034
1049
|
abortSignal,
|
@@ -1051,7 +1066,7 @@ function createOpenAICompatible(options) {
|
|
1051
1066
|
if (!options.baseURL) {
|
1052
1067
|
throw new Error("Base URL is required");
|
1053
1068
|
}
|
1054
|
-
const baseURL = (0,
|
1069
|
+
const baseURL = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL);
|
1055
1070
|
if (!options.name) {
|
1056
1071
|
throw new Error("Provider name is required");
|
1057
1072
|
}
|