@ai-sdk/openai-compatible 1.0.0-canary.8 → 1.0.0
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 +528 -0
- package/README.md +1 -1
- package/dist/index.d.mts +35 -110
- package/dist/index.d.ts +35 -110
- package/dist/index.js +265 -209
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +183 -127
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +9 -10
- package/dist/internal/index.d.ts +9 -10
- package/dist/internal/index.js +15 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +15 -2
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/package.json +11 -9
package/dist/index.js
CHANGED
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(src_exports);
|
|
31
31
|
// src/openai-compatible-chat-language-model.ts
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
33
33
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
34
|
-
var
|
34
|
+
var import_v43 = require("zod/v4");
|
35
35
|
|
36
36
|
// src/convert-to-openai-compatible-chat-messages.ts
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
@@ -103,7 +103,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
103
103
|
type: "function",
|
104
104
|
function: {
|
105
105
|
name: part.toolName,
|
106
|
-
arguments: JSON.stringify(part.
|
106
|
+
arguments: JSON.stringify(part.input)
|
107
107
|
},
|
108
108
|
...partMetadata
|
109
109
|
});
|
@@ -121,11 +121,24 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
121
121
|
}
|
122
122
|
case "tool": {
|
123
123
|
for (const toolResponse of content) {
|
124
|
+
const output = toolResponse.output;
|
125
|
+
let contentValue;
|
126
|
+
switch (output.type) {
|
127
|
+
case "text":
|
128
|
+
case "error-text":
|
129
|
+
contentValue = output.value;
|
130
|
+
break;
|
131
|
+
case "content":
|
132
|
+
case "json":
|
133
|
+
case "error-json":
|
134
|
+
contentValue = JSON.stringify(output.value);
|
135
|
+
break;
|
136
|
+
}
|
124
137
|
const toolResponseMetadata = getOpenAIMetadata(toolResponse);
|
125
138
|
messages.push({
|
126
139
|
role: "tool",
|
127
140
|
tool_call_id: toolResponse.toolCallId,
|
128
|
-
content:
|
141
|
+
content: contentValue,
|
129
142
|
...toolResponseMetadata
|
130
143
|
});
|
131
144
|
}
|
@@ -171,26 +184,30 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
171
184
|
}
|
172
185
|
|
173
186
|
// src/openai-compatible-chat-options.ts
|
174
|
-
var
|
175
|
-
var openaiCompatibleProviderOptions =
|
187
|
+
var import_v4 = require("zod/v4");
|
188
|
+
var openaiCompatibleProviderOptions = import_v4.z.object({
|
176
189
|
/**
|
177
190
|
* A unique identifier representing your end-user, which can help the provider to
|
178
191
|
* monitor and detect abuse.
|
179
192
|
*/
|
180
|
-
user:
|
193
|
+
user: import_v4.z.string().optional(),
|
194
|
+
/**
|
195
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
196
|
+
*/
|
197
|
+
reasoningEffort: import_v4.z.string().optional()
|
181
198
|
});
|
182
199
|
|
183
200
|
// src/openai-compatible-error.ts
|
184
|
-
var
|
185
|
-
var openaiCompatibleErrorDataSchema =
|
186
|
-
error:
|
187
|
-
message:
|
201
|
+
var import_v42 = require("zod/v4");
|
202
|
+
var openaiCompatibleErrorDataSchema = import_v42.z.object({
|
203
|
+
error: import_v42.z.object({
|
204
|
+
message: import_v42.z.string(),
|
188
205
|
// The additional information below is handled loosely to support
|
189
206
|
// OpenAI-compatible providers that have slightly different error
|
190
207
|
// responses:
|
191
|
-
type:
|
192
|
-
param:
|
193
|
-
code:
|
208
|
+
type: import_v42.z.string().nullish(),
|
209
|
+
param: import_v42.z.any().nullish(),
|
210
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
|
194
211
|
})
|
195
212
|
});
|
196
213
|
var defaultOpenAICompatibleErrorStructure = {
|
@@ -219,7 +236,7 @@ function prepareTools({
|
|
219
236
|
function: {
|
220
237
|
name: tool.name,
|
221
238
|
description: tool.description,
|
222
|
-
parameters: tool.
|
239
|
+
parameters: tool.inputSchema
|
223
240
|
}
|
224
241
|
});
|
225
242
|
}
|
@@ -266,16 +283,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
266
283
|
this.failedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)(errorStructure);
|
267
284
|
this.supportsStructuredOutputs = (_b = config.supportsStructuredOutputs) != null ? _b : false;
|
268
285
|
}
|
269
|
-
get defaultObjectGenerationMode() {
|
270
|
-
return this.config.defaultObjectGenerationMode;
|
271
|
-
}
|
272
286
|
get provider() {
|
273
287
|
return this.config.provider;
|
274
288
|
}
|
275
289
|
get providerOptionsName() {
|
276
290
|
return this.config.provider.split(".")[0].trim();
|
277
291
|
}
|
278
|
-
|
292
|
+
get supportedUrls() {
|
293
|
+
var _a, _b, _c;
|
294
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
295
|
+
}
|
296
|
+
async getArgs({
|
279
297
|
prompt,
|
280
298
|
maxOutputTokens,
|
281
299
|
temperature,
|
@@ -293,12 +311,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
293
311
|
var _a, _b, _c;
|
294
312
|
const warnings = [];
|
295
313
|
const compatibleOptions = Object.assign(
|
296
|
-
(_a = (0, import_provider_utils.parseProviderOptions)({
|
314
|
+
(_a = await (0, import_provider_utils.parseProviderOptions)({
|
297
315
|
provider: "openai-compatible",
|
298
316
|
providerOptions,
|
299
317
|
schema: openaiCompatibleProviderOptions
|
300
318
|
})) != null ? _a : {},
|
301
|
-
(_b = (0, import_provider_utils.parseProviderOptions)({
|
319
|
+
(_b = await (0, import_provider_utils.parseProviderOptions)({
|
302
320
|
provider: this.providerOptionsName,
|
303
321
|
providerOptions,
|
304
322
|
schema: openaiCompatibleProviderOptions
|
@@ -345,6 +363,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
345
363
|
stop: stopSequences,
|
346
364
|
seed,
|
347
365
|
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
366
|
+
reasoning_effort: compatibleOptions.reasoningEffort,
|
348
367
|
// messages:
|
349
368
|
messages: convertToOpenAICompatibleChatMessages(prompt),
|
350
369
|
// tools:
|
@@ -355,8 +374,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
355
374
|
};
|
356
375
|
}
|
357
376
|
async doGenerate(options) {
|
358
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
359
|
-
const { args, warnings } = this.getArgs({ ...options });
|
377
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
378
|
+
const { args, warnings } = await this.getArgs({ ...options });
|
360
379
|
const body = JSON.stringify(args);
|
361
380
|
const {
|
362
381
|
responseHeaders,
|
@@ -386,7 +405,6 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
386
405
|
if (reasoning != null && reasoning.length > 0) {
|
387
406
|
content.push({
|
388
407
|
type: "reasoning",
|
389
|
-
reasoningType: "text",
|
390
408
|
text: reasoning
|
391
409
|
});
|
392
410
|
}
|
@@ -394,39 +412,34 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
394
412
|
for (const toolCall of choice.message.tool_calls) {
|
395
413
|
content.push({
|
396
414
|
type: "tool-call",
|
397
|
-
toolCallType: "function",
|
398
415
|
toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils.generateId)(),
|
399
416
|
toolName: toolCall.function.name,
|
400
|
-
|
417
|
+
input: toolCall.function.arguments
|
401
418
|
});
|
402
419
|
}
|
403
420
|
}
|
404
421
|
const providerMetadata = {
|
405
422
|
[this.providerOptionsName]: {},
|
406
|
-
...(_c = (_b = this.config.metadataExtractor) == null ? void 0 : _b.extractMetadata) == null ? void 0 : _c.call(_b, {
|
423
|
+
...await ((_c = (_b = this.config.metadataExtractor) == null ? void 0 : _b.extractMetadata) == null ? void 0 : _c.call(_b, {
|
407
424
|
parsedBody: rawResponse
|
408
|
-
})
|
425
|
+
}))
|
409
426
|
};
|
410
427
|
const completionTokenDetails = (_d = responseBody.usage) == null ? void 0 : _d.completion_tokens_details;
|
411
|
-
const promptTokenDetails = (_e = responseBody.usage) == null ? void 0 : _e.prompt_tokens_details;
|
412
|
-
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
|
413
|
-
providerMetadata[this.providerOptionsName].reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
|
414
|
-
}
|
415
428
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
416
429
|
providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
417
430
|
}
|
418
431
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
419
432
|
providerMetadata[this.providerOptionsName].rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
420
433
|
}
|
421
|
-
if ((promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null) {
|
422
|
-
providerMetadata[this.providerOptionsName].cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
423
|
-
}
|
424
434
|
return {
|
425
435
|
content,
|
426
436
|
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
427
437
|
usage: {
|
428
|
-
inputTokens: (
|
429
|
-
outputTokens: (
|
438
|
+
inputTokens: (_f = (_e = responseBody.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : void 0,
|
439
|
+
outputTokens: (_h = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
440
|
+
totalTokens: (_j = (_i = responseBody.usage) == null ? void 0 : _i.total_tokens) != null ? _j : void 0,
|
441
|
+
reasoningTokens: (_m = (_l = (_k = responseBody.usage) == null ? void 0 : _k.completion_tokens_details) == null ? void 0 : _l.reasoning_tokens) != null ? _m : void 0,
|
442
|
+
cachedInputTokens: (_p = (_o = (_n = responseBody.usage) == null ? void 0 : _n.prompt_tokens_details) == null ? void 0 : _o.cached_tokens) != null ? _p : void 0
|
430
443
|
},
|
431
444
|
providerMetadata,
|
432
445
|
request: { body },
|
@@ -440,8 +453,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
440
453
|
}
|
441
454
|
async doStream(options) {
|
442
455
|
var _a;
|
443
|
-
const { args, warnings } = this.getArgs({ ...options });
|
444
|
-
const body =
|
456
|
+
const { args, warnings } = await this.getArgs({ ...options });
|
457
|
+
const body = {
|
458
|
+
...args,
|
459
|
+
stream: true,
|
460
|
+
// only include stream_options when in strict compatibility mode:
|
461
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
462
|
+
};
|
445
463
|
const metadataExtractor = (_a = this.config.metadataExtractor) == null ? void 0 : _a.createStreamExtractor();
|
446
464
|
const { responseHeaders, value: response } = await (0, import_provider_utils.postJsonToApi)({
|
447
465
|
url: this.config.url({
|
@@ -449,10 +467,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
449
467
|
modelId: this.modelId
|
450
468
|
}),
|
451
469
|
headers: (0, import_provider_utils.combineHeaders)(this.config.headers(), options.headers),
|
452
|
-
body
|
453
|
-
...args,
|
454
|
-
stream: true
|
455
|
-
},
|
470
|
+
body,
|
456
471
|
failedResponseHandler: this.failedResponseHandler,
|
457
472
|
successfulResponseHandler: (0, import_provider_utils.createEventSourceResponseHandler)(
|
458
473
|
this.chunkSchema
|
@@ -462,7 +477,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
462
477
|
});
|
463
478
|
const toolCalls = [];
|
464
479
|
let finishReason = "unknown";
|
465
|
-
|
480
|
+
const usage = {
|
466
481
|
completionTokens: void 0,
|
467
482
|
completionTokensDetails: {
|
468
483
|
reasoningTokens: void 0,
|
@@ -472,10 +487,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
472
487
|
promptTokens: void 0,
|
473
488
|
promptTokensDetails: {
|
474
489
|
cachedTokens: void 0
|
475
|
-
}
|
490
|
+
},
|
491
|
+
totalTokens: void 0
|
476
492
|
};
|
477
493
|
let isFirstChunk = true;
|
478
|
-
|
494
|
+
const providerOptionsName = this.providerOptionsName;
|
495
|
+
let isActiveReasoning = false;
|
496
|
+
let isActiveText = false;
|
479
497
|
return {
|
480
498
|
stream: response.pipeThrough(
|
481
499
|
new TransformStream({
|
@@ -485,6 +503,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
485
503
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
486
504
|
transform(chunk, controller) {
|
487
505
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
506
|
+
if (options.includeRawChunks) {
|
507
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
508
|
+
}
|
488
509
|
if (!chunk.success) {
|
489
510
|
finishReason = "error";
|
490
511
|
controller.enqueue({ type: "error", error: chunk.error });
|
@@ -508,11 +529,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
508
529
|
const {
|
509
530
|
prompt_tokens,
|
510
531
|
completion_tokens,
|
532
|
+
total_tokens,
|
511
533
|
prompt_tokens_details,
|
512
534
|
completion_tokens_details
|
513
535
|
} = value.usage;
|
514
536
|
usage.promptTokens = prompt_tokens != null ? prompt_tokens : void 0;
|
515
537
|
usage.completionTokens = completion_tokens != null ? completion_tokens : void 0;
|
538
|
+
usage.totalTokens = total_tokens != null ? total_tokens : void 0;
|
516
539
|
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
|
517
540
|
usage.completionTokensDetails.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
|
518
541
|
}
|
@@ -537,28 +560,34 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
537
560
|
}
|
538
561
|
const delta = choice.delta;
|
539
562
|
if (delta.reasoning_content != null) {
|
563
|
+
if (!isActiveReasoning) {
|
564
|
+
controller.enqueue({
|
565
|
+
type: "reasoning-start",
|
566
|
+
id: "reasoning-0"
|
567
|
+
});
|
568
|
+
isActiveReasoning = true;
|
569
|
+
}
|
540
570
|
controller.enqueue({
|
541
|
-
type: "reasoning",
|
542
|
-
|
543
|
-
|
571
|
+
type: "reasoning-delta",
|
572
|
+
id: "reasoning-0",
|
573
|
+
delta: delta.reasoning_content
|
544
574
|
});
|
545
575
|
}
|
546
576
|
if (delta.content != null) {
|
577
|
+
if (!isActiveText) {
|
578
|
+
controller.enqueue({ type: "text-start", id: "txt-0" });
|
579
|
+
isActiveText = true;
|
580
|
+
}
|
547
581
|
controller.enqueue({
|
548
|
-
type: "text",
|
549
|
-
|
582
|
+
type: "text-delta",
|
583
|
+
id: "txt-0",
|
584
|
+
delta: delta.content
|
550
585
|
});
|
551
586
|
}
|
552
587
|
if (delta.tool_calls != null) {
|
553
588
|
for (const toolCallDelta of delta.tool_calls) {
|
554
589
|
const index = toolCallDelta.index;
|
555
590
|
if (toolCalls[index] == null) {
|
556
|
-
if (toolCallDelta.type !== "function") {
|
557
|
-
throw new import_provider3.InvalidResponseDataError({
|
558
|
-
data: toolCallDelta,
|
559
|
-
message: `Expected 'function' type.`
|
560
|
-
});
|
561
|
-
}
|
562
591
|
if (toolCallDelta.id == null) {
|
563
592
|
throw new import_provider3.InvalidResponseDataError({
|
564
593
|
data: toolCallDelta,
|
@@ -571,6 +600,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
571
600
|
message: `Expected 'function.name' to be a string.`
|
572
601
|
});
|
573
602
|
}
|
603
|
+
controller.enqueue({
|
604
|
+
type: "tool-input-start",
|
605
|
+
id: toolCallDelta.id,
|
606
|
+
toolName: toolCallDelta.function.name
|
607
|
+
});
|
574
608
|
toolCalls[index] = {
|
575
609
|
id: toolCallDelta.id,
|
576
610
|
type: "function",
|
@@ -584,20 +618,21 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
584
618
|
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
|
585
619
|
if (toolCall2.function.arguments.length > 0) {
|
586
620
|
controller.enqueue({
|
587
|
-
type: "tool-
|
588
|
-
|
589
|
-
|
590
|
-
toolName: toolCall2.function.name,
|
591
|
-
argsTextDelta: toolCall2.function.arguments
|
621
|
+
type: "tool-input-start",
|
622
|
+
id: toolCall2.id,
|
623
|
+
toolName: toolCall2.function.name
|
592
624
|
});
|
593
625
|
}
|
594
626
|
if ((0, import_provider_utils.isParsableJson)(toolCall2.function.arguments)) {
|
627
|
+
controller.enqueue({
|
628
|
+
type: "tool-input-end",
|
629
|
+
id: toolCall2.id
|
630
|
+
});
|
595
631
|
controller.enqueue({
|
596
632
|
type: "tool-call",
|
597
|
-
toolCallType: "function",
|
598
633
|
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils.generateId)(),
|
599
634
|
toolName: toolCall2.function.name,
|
600
|
-
|
635
|
+
input: toolCall2.function.arguments
|
601
636
|
});
|
602
637
|
toolCall2.hasFinished = true;
|
603
638
|
}
|
@@ -612,19 +647,20 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
612
647
|
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
|
613
648
|
}
|
614
649
|
controller.enqueue({
|
615
|
-
type: "tool-
|
616
|
-
|
617
|
-
|
618
|
-
toolName: toolCall.function.name,
|
619
|
-
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
650
|
+
type: "tool-input-delta",
|
651
|
+
id: toolCall.id,
|
652
|
+
delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
620
653
|
});
|
621
654
|
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils.isParsableJson)(toolCall.function.arguments)) {
|
655
|
+
controller.enqueue({
|
656
|
+
type: "tool-input-end",
|
657
|
+
id: toolCall.id
|
658
|
+
});
|
622
659
|
controller.enqueue({
|
623
660
|
type: "tool-call",
|
624
|
-
toolCallType: "function",
|
625
661
|
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils.generateId)(),
|
626
662
|
toolName: toolCall.function.name,
|
627
|
-
|
663
|
+
input: toolCall.function.arguments
|
628
664
|
});
|
629
665
|
toolCall.hasFinished = true;
|
630
666
|
}
|
@@ -632,29 +668,46 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
632
668
|
}
|
633
669
|
},
|
634
670
|
flush(controller) {
|
635
|
-
var _a2, _b;
|
671
|
+
var _a2, _b, _c, _d, _e, _f;
|
672
|
+
if (isActiveReasoning) {
|
673
|
+
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
674
|
+
}
|
675
|
+
if (isActiveText) {
|
676
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
677
|
+
}
|
678
|
+
for (const toolCall of toolCalls.filter(
|
679
|
+
(toolCall2) => !toolCall2.hasFinished
|
680
|
+
)) {
|
681
|
+
controller.enqueue({
|
682
|
+
type: "tool-input-end",
|
683
|
+
id: toolCall.id
|
684
|
+
});
|
685
|
+
controller.enqueue({
|
686
|
+
type: "tool-call",
|
687
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils.generateId)(),
|
688
|
+
toolName: toolCall.function.name,
|
689
|
+
input: toolCall.function.arguments
|
690
|
+
});
|
691
|
+
}
|
636
692
|
const providerMetadata = {
|
637
693
|
[providerOptionsName]: {},
|
638
694
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
639
695
|
};
|
640
|
-
if (usage.completionTokensDetails.reasoningTokens != null) {
|
641
|
-
providerMetadata[providerOptionsName].reasoningTokens = usage.completionTokensDetails.reasoningTokens;
|
642
|
-
}
|
643
696
|
if (usage.completionTokensDetails.acceptedPredictionTokens != null) {
|
644
697
|
providerMetadata[providerOptionsName].acceptedPredictionTokens = usage.completionTokensDetails.acceptedPredictionTokens;
|
645
698
|
}
|
646
699
|
if (usage.completionTokensDetails.rejectedPredictionTokens != null) {
|
647
700
|
providerMetadata[providerOptionsName].rejectedPredictionTokens = usage.completionTokensDetails.rejectedPredictionTokens;
|
648
701
|
}
|
649
|
-
if (usage.promptTokensDetails.cachedTokens != null) {
|
650
|
-
providerMetadata[providerOptionsName].cachedPromptTokens = usage.promptTokensDetails.cachedTokens;
|
651
|
-
}
|
652
702
|
controller.enqueue({
|
653
703
|
type: "finish",
|
654
704
|
finishReason,
|
655
705
|
usage: {
|
656
|
-
inputTokens: (
|
657
|
-
outputTokens: (
|
706
|
+
inputTokens: (_b = usage.promptTokens) != null ? _b : void 0,
|
707
|
+
outputTokens: (_c = usage.completionTokens) != null ? _c : void 0,
|
708
|
+
totalTokens: (_d = usage.totalTokens) != null ? _d : void 0,
|
709
|
+
reasoningTokens: (_e = usage.completionTokensDetails.reasoningTokens) != null ? _e : void 0,
|
710
|
+
cachedInputTokens: (_f = usage.promptTokensDetails.cachedTokens) != null ? _f : void 0
|
658
711
|
},
|
659
712
|
providerMetadata
|
660
713
|
});
|
@@ -666,68 +719,67 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
666
719
|
};
|
667
720
|
}
|
668
721
|
};
|
669
|
-
var openaiCompatibleTokenUsageSchema =
|
670
|
-
prompt_tokens:
|
671
|
-
completion_tokens:
|
672
|
-
|
673
|
-
|
722
|
+
var openaiCompatibleTokenUsageSchema = import_v43.z.object({
|
723
|
+
prompt_tokens: import_v43.z.number().nullish(),
|
724
|
+
completion_tokens: import_v43.z.number().nullish(),
|
725
|
+
total_tokens: import_v43.z.number().nullish(),
|
726
|
+
prompt_tokens_details: import_v43.z.object({
|
727
|
+
cached_tokens: import_v43.z.number().nullish()
|
674
728
|
}).nullish(),
|
675
|
-
completion_tokens_details:
|
676
|
-
reasoning_tokens:
|
677
|
-
accepted_prediction_tokens:
|
678
|
-
rejected_prediction_tokens:
|
729
|
+
completion_tokens_details: import_v43.z.object({
|
730
|
+
reasoning_tokens: import_v43.z.number().nullish(),
|
731
|
+
accepted_prediction_tokens: import_v43.z.number().nullish(),
|
732
|
+
rejected_prediction_tokens: import_v43.z.number().nullish()
|
679
733
|
}).nullish()
|
680
734
|
}).nullish();
|
681
|
-
var OpenAICompatibleChatResponseSchema =
|
682
|
-
id:
|
683
|
-
created:
|
684
|
-
model:
|
685
|
-
choices:
|
686
|
-
|
687
|
-
message:
|
688
|
-
role:
|
689
|
-
content:
|
690
|
-
reasoning_content:
|
691
|
-
tool_calls:
|
692
|
-
|
693
|
-
id:
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
arguments: import_zod3.z.string()
|
735
|
+
var OpenAICompatibleChatResponseSchema = import_v43.z.object({
|
736
|
+
id: import_v43.z.string().nullish(),
|
737
|
+
created: import_v43.z.number().nullish(),
|
738
|
+
model: import_v43.z.string().nullish(),
|
739
|
+
choices: import_v43.z.array(
|
740
|
+
import_v43.z.object({
|
741
|
+
message: import_v43.z.object({
|
742
|
+
role: import_v43.z.literal("assistant").nullish(),
|
743
|
+
content: import_v43.z.string().nullish(),
|
744
|
+
reasoning_content: import_v43.z.string().nullish(),
|
745
|
+
tool_calls: import_v43.z.array(
|
746
|
+
import_v43.z.object({
|
747
|
+
id: import_v43.z.string().nullish(),
|
748
|
+
function: import_v43.z.object({
|
749
|
+
name: import_v43.z.string(),
|
750
|
+
arguments: import_v43.z.string()
|
698
751
|
})
|
699
752
|
})
|
700
753
|
).nullish()
|
701
754
|
}),
|
702
|
-
finish_reason:
|
755
|
+
finish_reason: import_v43.z.string().nullish()
|
703
756
|
})
|
704
757
|
),
|
705
758
|
usage: openaiCompatibleTokenUsageSchema
|
706
759
|
});
|
707
|
-
var createOpenAICompatibleChatChunkSchema = (errorSchema) =>
|
708
|
-
|
709
|
-
id:
|
710
|
-
created:
|
711
|
-
model:
|
712
|
-
choices:
|
713
|
-
|
714
|
-
delta:
|
715
|
-
role:
|
716
|
-
content:
|
717
|
-
reasoning_content:
|
718
|
-
tool_calls:
|
719
|
-
|
720
|
-
index:
|
721
|
-
id:
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
arguments: import_zod3.z.string().nullish()
|
760
|
+
var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_v43.z.union([
|
761
|
+
import_v43.z.object({
|
762
|
+
id: import_v43.z.string().nullish(),
|
763
|
+
created: import_v43.z.number().nullish(),
|
764
|
+
model: import_v43.z.string().nullish(),
|
765
|
+
choices: import_v43.z.array(
|
766
|
+
import_v43.z.object({
|
767
|
+
delta: import_v43.z.object({
|
768
|
+
role: import_v43.z.enum(["assistant"]).nullish(),
|
769
|
+
content: import_v43.z.string().nullish(),
|
770
|
+
reasoning_content: import_v43.z.string().nullish(),
|
771
|
+
tool_calls: import_v43.z.array(
|
772
|
+
import_v43.z.object({
|
773
|
+
index: import_v43.z.number(),
|
774
|
+
id: import_v43.z.string().nullish(),
|
775
|
+
function: import_v43.z.object({
|
776
|
+
name: import_v43.z.string().nullish(),
|
777
|
+
arguments: import_v43.z.string().nullish()
|
726
778
|
})
|
727
779
|
})
|
728
780
|
).nullish()
|
729
781
|
}).nullish(),
|
730
|
-
finish_reason:
|
782
|
+
finish_reason: import_v43.z.string().nullish()
|
731
783
|
})
|
732
784
|
),
|
733
785
|
usage: openaiCompatibleTokenUsageSchema
|
@@ -737,19 +789,15 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod3.z.union
|
|
737
789
|
|
738
790
|
// src/openai-compatible-completion-language-model.ts
|
739
791
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
740
|
-
var
|
792
|
+
var import_v45 = require("zod/v4");
|
741
793
|
|
742
794
|
// src/convert-to-openai-compatible-completion-prompt.ts
|
743
795
|
var import_provider4 = require("@ai-sdk/provider");
|
744
796
|
function convertToOpenAICompatibleCompletionPrompt({
|
745
797
|
prompt,
|
746
|
-
inputFormat,
|
747
798
|
user = "user",
|
748
799
|
assistant = "assistant"
|
749
800
|
}) {
|
750
|
-
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
751
|
-
return { prompt: prompt[0].content[0].text };
|
752
|
-
}
|
753
801
|
let text = "";
|
754
802
|
if (prompt[0].role === "system") {
|
755
803
|
text += `${prompt[0].content}
|
@@ -819,28 +867,28 @@ ${user}:`]
|
|
819
867
|
}
|
820
868
|
|
821
869
|
// src/openai-compatible-completion-options.ts
|
822
|
-
var
|
823
|
-
var openaiCompatibleCompletionProviderOptions =
|
870
|
+
var import_v44 = require("zod/v4");
|
871
|
+
var openaiCompatibleCompletionProviderOptions = import_v44.z.object({
|
824
872
|
/**
|
825
873
|
* Echo back the prompt in addition to the completion.
|
826
874
|
*/
|
827
|
-
echo:
|
875
|
+
echo: import_v44.z.boolean().optional(),
|
828
876
|
/**
|
829
877
|
* Modify the likelihood of specified tokens appearing in the completion.
|
830
878
|
*
|
831
879
|
* Accepts a JSON object that maps tokens (specified by their token ID in
|
832
880
|
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
833
881
|
*/
|
834
|
-
logitBias:
|
882
|
+
logitBias: import_v44.z.record(import_v44.z.string(), import_v44.z.number()).optional(),
|
835
883
|
/**
|
836
884
|
* The suffix that comes after a completion of inserted text.
|
837
885
|
*/
|
838
|
-
suffix:
|
886
|
+
suffix: import_v44.z.string().optional(),
|
839
887
|
/**
|
840
888
|
* A unique identifier representing your end-user, which can help providers to
|
841
889
|
* monitor and detect abuse.
|
842
890
|
*/
|
843
|
-
user:
|
891
|
+
user: import_v44.z.string().optional()
|
844
892
|
});
|
845
893
|
|
846
894
|
// src/openai-compatible-completion-language-model.ts
|
@@ -848,7 +896,6 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
848
896
|
// type inferred via constructor
|
849
897
|
constructor(modelId, config) {
|
850
898
|
this.specificationVersion = "v2";
|
851
|
-
this.defaultObjectGenerationMode = void 0;
|
852
899
|
var _a;
|
853
900
|
this.modelId = modelId;
|
854
901
|
this.config = config;
|
@@ -864,8 +911,11 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
864
911
|
get providerOptionsName() {
|
865
912
|
return this.config.provider.split(".")[0].trim();
|
866
913
|
}
|
867
|
-
|
868
|
-
|
914
|
+
get supportedUrls() {
|
915
|
+
var _a, _b, _c;
|
916
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
917
|
+
}
|
918
|
+
async getArgs({
|
869
919
|
prompt,
|
870
920
|
maxOutputTokens,
|
871
921
|
temperature,
|
@@ -882,7 +932,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
882
932
|
}) {
|
883
933
|
var _a;
|
884
934
|
const warnings = [];
|
885
|
-
const completionOptions = (_a = (0, import_provider_utils2.parseProviderOptions)({
|
935
|
+
const completionOptions = (_a = await (0, import_provider_utils2.parseProviderOptions)({
|
886
936
|
provider: this.providerOptionsName,
|
887
937
|
providerOptions,
|
888
938
|
schema: openaiCompatibleCompletionProviderOptions
|
@@ -903,7 +953,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
903
953
|
details: "JSON response format is not supported."
|
904
954
|
});
|
905
955
|
}
|
906
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompatibleCompletionPrompt({ prompt
|
956
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompatibleCompletionPrompt({ prompt });
|
907
957
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
908
958
|
return {
|
909
959
|
args: {
|
@@ -931,8 +981,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
931
981
|
};
|
932
982
|
}
|
933
983
|
async doGenerate(options) {
|
934
|
-
var _a, _b, _c, _d;
|
935
|
-
const { args, warnings } = this.getArgs(options);
|
984
|
+
var _a, _b, _c, _d, _e, _f;
|
985
|
+
const { args, warnings } = await this.getArgs(options);
|
936
986
|
const {
|
937
987
|
responseHeaders,
|
938
988
|
value: response,
|
@@ -960,7 +1010,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
960
1010
|
content,
|
961
1011
|
usage: {
|
962
1012
|
inputTokens: (_b = (_a = response.usage) == null ? void 0 : _a.prompt_tokens) != null ? _b : void 0,
|
963
|
-
outputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : void 0
|
1013
|
+
outputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : void 0,
|
1014
|
+
totalTokens: (_f = (_e = response.usage) == null ? void 0 : _e.total_tokens) != null ? _f : void 0
|
964
1015
|
},
|
965
1016
|
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
966
1017
|
request: { body: args },
|
@@ -973,10 +1024,12 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
973
1024
|
};
|
974
1025
|
}
|
975
1026
|
async doStream(options) {
|
976
|
-
const { args, warnings } = this.getArgs(options);
|
1027
|
+
const { args, warnings } = await this.getArgs(options);
|
977
1028
|
const body = {
|
978
1029
|
...args,
|
979
|
-
stream: true
|
1030
|
+
stream: true,
|
1031
|
+
// only include stream_options when in strict compatibility mode:
|
1032
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
980
1033
|
};
|
981
1034
|
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
982
1035
|
url: this.config.url({
|
@@ -995,7 +1048,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
995
1048
|
let finishReason = "unknown";
|
996
1049
|
const usage = {
|
997
1050
|
inputTokens: void 0,
|
998
|
-
outputTokens: void 0
|
1051
|
+
outputTokens: void 0,
|
1052
|
+
totalTokens: void 0
|
999
1053
|
};
|
1000
1054
|
let isFirstChunk = true;
|
1001
1055
|
return {
|
@@ -1005,7 +1059,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1005
1059
|
controller.enqueue({ type: "stream-start", warnings });
|
1006
1060
|
},
|
1007
1061
|
transform(chunk, controller) {
|
1008
|
-
var _a, _b;
|
1062
|
+
var _a, _b, _c;
|
1063
|
+
if (options.includeRawChunks) {
|
1064
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
1065
|
+
}
|
1009
1066
|
if (!chunk.success) {
|
1010
1067
|
finishReason = "error";
|
1011
1068
|
controller.enqueue({ type: "error", error: chunk.error });
|
@@ -1023,10 +1080,15 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1023
1080
|
type: "response-metadata",
|
1024
1081
|
...getResponseMetadata(value)
|
1025
1082
|
});
|
1083
|
+
controller.enqueue({
|
1084
|
+
type: "text-start",
|
1085
|
+
id: "0"
|
1086
|
+
});
|
1026
1087
|
}
|
1027
1088
|
if (value.usage != null) {
|
1028
1089
|
usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
|
1029
1090
|
usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
|
1091
|
+
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
1030
1092
|
}
|
1031
1093
|
const choice = value.choices[0];
|
1032
1094
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
@@ -1036,12 +1098,16 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1036
1098
|
}
|
1037
1099
|
if ((choice == null ? void 0 : choice.text) != null) {
|
1038
1100
|
controller.enqueue({
|
1039
|
-
type: "text",
|
1040
|
-
|
1101
|
+
type: "text-delta",
|
1102
|
+
id: "0",
|
1103
|
+
delta: choice.text
|
1041
1104
|
});
|
1042
1105
|
}
|
1043
1106
|
},
|
1044
1107
|
flush(controller) {
|
1108
|
+
if (!isFirstChunk) {
|
1109
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
1110
|
+
}
|
1045
1111
|
controller.enqueue({
|
1046
1112
|
type: "finish",
|
1047
1113
|
finishReason,
|
@@ -1055,37 +1121,36 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
1055
1121
|
};
|
1056
1122
|
}
|
1057
1123
|
};
|
1058
|
-
var
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1124
|
+
var usageSchema = import_v45.z.object({
|
1125
|
+
prompt_tokens: import_v45.z.number(),
|
1126
|
+
completion_tokens: import_v45.z.number(),
|
1127
|
+
total_tokens: import_v45.z.number()
|
1128
|
+
});
|
1129
|
+
var openaiCompatibleCompletionResponseSchema = import_v45.z.object({
|
1130
|
+
id: import_v45.z.string().nullish(),
|
1131
|
+
created: import_v45.z.number().nullish(),
|
1132
|
+
model: import_v45.z.string().nullish(),
|
1133
|
+
choices: import_v45.z.array(
|
1134
|
+
import_v45.z.object({
|
1135
|
+
text: import_v45.z.string(),
|
1136
|
+
finish_reason: import_v45.z.string()
|
1066
1137
|
})
|
1067
1138
|
),
|
1068
|
-
usage:
|
1069
|
-
prompt_tokens: import_zod5.z.number(),
|
1070
|
-
completion_tokens: import_zod5.z.number()
|
1071
|
-
}).nullish()
|
1139
|
+
usage: usageSchema.nullish()
|
1072
1140
|
});
|
1073
|
-
var createOpenAICompatibleCompletionChunkSchema = (errorSchema) =>
|
1074
|
-
|
1075
|
-
id:
|
1076
|
-
created:
|
1077
|
-
model:
|
1078
|
-
choices:
|
1079
|
-
|
1080
|
-
text:
|
1081
|
-
finish_reason:
|
1082
|
-
index:
|
1141
|
+
var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_v45.z.union([
|
1142
|
+
import_v45.z.object({
|
1143
|
+
id: import_v45.z.string().nullish(),
|
1144
|
+
created: import_v45.z.number().nullish(),
|
1145
|
+
model: import_v45.z.string().nullish(),
|
1146
|
+
choices: import_v45.z.array(
|
1147
|
+
import_v45.z.object({
|
1148
|
+
text: import_v45.z.string(),
|
1149
|
+
finish_reason: import_v45.z.string().nullish(),
|
1150
|
+
index: import_v45.z.number()
|
1083
1151
|
})
|
1084
1152
|
),
|
1085
|
-
usage:
|
1086
|
-
prompt_tokens: import_zod5.z.number(),
|
1087
|
-
completion_tokens: import_zod5.z.number()
|
1088
|
-
}).nullish()
|
1153
|
+
usage: usageSchema.nullish()
|
1089
1154
|
}),
|
1090
1155
|
errorSchema
|
1091
1156
|
]);
|
@@ -1093,21 +1158,21 @@ var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod5.z
|
|
1093
1158
|
// src/openai-compatible-embedding-model.ts
|
1094
1159
|
var import_provider5 = require("@ai-sdk/provider");
|
1095
1160
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
1096
|
-
var
|
1161
|
+
var import_v47 = require("zod/v4");
|
1097
1162
|
|
1098
1163
|
// src/openai-compatible-embedding-options.ts
|
1099
|
-
var
|
1100
|
-
var openaiCompatibleEmbeddingProviderOptions =
|
1164
|
+
var import_v46 = require("zod/v4");
|
1165
|
+
var openaiCompatibleEmbeddingProviderOptions = import_v46.z.object({
|
1101
1166
|
/**
|
1102
1167
|
* The number of dimensions the resulting output embeddings should have.
|
1103
1168
|
* Only supported in text-embedding-3 and later models.
|
1104
1169
|
*/
|
1105
|
-
dimensions:
|
1170
|
+
dimensions: import_v46.z.number().optional(),
|
1106
1171
|
/**
|
1107
1172
|
* A unique identifier representing your end-user, which can help providers to
|
1108
1173
|
* monitor and detect abuse.
|
1109
1174
|
*/
|
1110
|
-
user:
|
1175
|
+
user: import_v46.z.string().optional()
|
1111
1176
|
});
|
1112
1177
|
|
1113
1178
|
// src/openai-compatible-embedding-model.ts
|
@@ -1139,12 +1204,12 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1139
1204
|
}) {
|
1140
1205
|
var _a, _b, _c;
|
1141
1206
|
const compatibleOptions = Object.assign(
|
1142
|
-
(_a = (0, import_provider_utils3.parseProviderOptions)({
|
1207
|
+
(_a = await (0, import_provider_utils3.parseProviderOptions)({
|
1143
1208
|
provider: "openai-compatible",
|
1144
1209
|
providerOptions,
|
1145
1210
|
schema: openaiCompatibleEmbeddingProviderOptions
|
1146
1211
|
})) != null ? _a : {},
|
1147
|
-
(_b = (0, import_provider_utils3.parseProviderOptions)({
|
1212
|
+
(_b = await (0, import_provider_utils3.parseProviderOptions)({
|
1148
1213
|
provider: this.providerOptionsName,
|
1149
1214
|
providerOptions,
|
1150
1215
|
schema: openaiCompatibleEmbeddingProviderOptions
|
@@ -1191,24 +1256,20 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1191
1256
|
};
|
1192
1257
|
}
|
1193
1258
|
};
|
1194
|
-
var openaiTextEmbeddingResponseSchema =
|
1195
|
-
data:
|
1196
|
-
usage:
|
1259
|
+
var openaiTextEmbeddingResponseSchema = import_v47.z.object({
|
1260
|
+
data: import_v47.z.array(import_v47.z.object({ embedding: import_v47.z.array(import_v47.z.number()) })),
|
1261
|
+
usage: import_v47.z.object({ prompt_tokens: import_v47.z.number() }).nullish()
|
1197
1262
|
});
|
1198
1263
|
|
1199
1264
|
// src/openai-compatible-image-model.ts
|
1200
1265
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1201
|
-
var
|
1266
|
+
var import_v48 = require("zod/v4");
|
1202
1267
|
var OpenAICompatibleImageModel = class {
|
1203
|
-
constructor(modelId,
|
1268
|
+
constructor(modelId, config) {
|
1204
1269
|
this.modelId = modelId;
|
1205
|
-
this.settings = settings;
|
1206
1270
|
this.config = config;
|
1207
|
-
this.specificationVersion = "
|
1208
|
-
|
1209
|
-
get maxImagesPerCall() {
|
1210
|
-
var _a;
|
1211
|
-
return (_a = this.settings.maxImagesPerCall) != null ? _a : 10;
|
1271
|
+
this.specificationVersion = "v2";
|
1272
|
+
this.maxImagesPerCall = 10;
|
1212
1273
|
}
|
1213
1274
|
get provider() {
|
1214
1275
|
return this.config.provider;
|
@@ -1248,8 +1309,7 @@ var OpenAICompatibleImageModel = class {
|
|
1248
1309
|
n,
|
1249
1310
|
size,
|
1250
1311
|
...(_d = providerOptions.openai) != null ? _d : {},
|
1251
|
-
response_format: "b64_json"
|
1252
|
-
...this.settings.user ? { user: this.settings.user } : {}
|
1312
|
+
response_format: "b64_json"
|
1253
1313
|
},
|
1254
1314
|
failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)(
|
1255
1315
|
(_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
|
@@ -1271,8 +1331,8 @@ var OpenAICompatibleImageModel = class {
|
|
1271
1331
|
};
|
1272
1332
|
}
|
1273
1333
|
};
|
1274
|
-
var openaiCompatibleImageResponseSchema =
|
1275
|
-
data:
|
1334
|
+
var openaiCompatibleImageResponseSchema = import_v48.z.object({
|
1335
|
+
data: import_v48.z.array(import_v48.z.object({ b64_json: import_v48.z.string() }))
|
1276
1336
|
});
|
1277
1337
|
|
1278
1338
|
// src/openai-compatible-provider.ts
|
@@ -1299,20 +1359,16 @@ function createOpenAICompatible(options) {
|
|
1299
1359
|
const createLanguageModel = (modelId) => createChatModel(modelId);
|
1300
1360
|
const createChatModel = (modelId) => new OpenAICompatibleChatLanguageModel(modelId, {
|
1301
1361
|
...getCommonModelConfig("chat"),
|
1302
|
-
|
1362
|
+
includeUsage: options.includeUsage
|
1363
|
+
});
|
1364
|
+
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(modelId, {
|
1365
|
+
...getCommonModelConfig("completion"),
|
1366
|
+
includeUsage: options.includeUsage
|
1303
1367
|
});
|
1304
|
-
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
|
1305
|
-
modelId,
|
1306
|
-
getCommonModelConfig("completion")
|
1307
|
-
);
|
1308
1368
|
const createEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(modelId, {
|
1309
1369
|
...getCommonModelConfig("embedding")
|
1310
1370
|
});
|
1311
|
-
const createImageModel = (modelId
|
1312
|
-
modelId,
|
1313
|
-
settings,
|
1314
|
-
getCommonModelConfig("image")
|
1315
|
-
);
|
1371
|
+
const createImageModel = (modelId) => new OpenAICompatibleImageModel(modelId, getCommonModelConfig("image"));
|
1316
1372
|
const provider = (modelId) => createLanguageModel(modelId);
|
1317
1373
|
provider.languageModel = createLanguageModel;
|
1318
1374
|
provider.chatModel = createChatModel;
|