@ai-sdk/openai-compatible 1.0.61 → 1.0.63
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 +26 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +56 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -3
- package/dist/internal/index.d.ts +6 -3
- package/dist/internal/index.js +2 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +2 -2
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 1.0.63
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [c31e0a2]
|
|
8
|
+
- @ai-sdk/provider-utils@3.0.46
|
|
9
|
+
|
|
10
|
+
## 1.0.62
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- db18e4f: Avoid empty structured-output answers from Baseten's DeepSeek V4 Pro 0813 when reasoning is enabled. Fall back to JSON prompt instructions while keeping reasoning and SDK output validation, and report the fallback through request transformation warnings.
|
|
15
|
+
- ce27f15: fix(openai,openai-compatible): surface refusal logprobs and openai-compatible refusals
|
|
16
|
+
|
|
17
|
+
`@ai-sdk/openai`: Chat Completions responses that contain a refusal can return `logprobs.refusal` next to `logprobs.content`. The provider previously read only `logprobs.content`, so `providerMetadata.openai.logprobs` was empty or missing for refusals. Refusal logprobs are now included in emission order (content logprobs followed by refusal logprobs) in both `generateText` and `streamText`.
|
|
18
|
+
|
|
19
|
+
Streaming logprobs are now collected across all chunks in `streamText`: previously only the logprobs of the last streamed chunk were reported. This applies to content logprobs as well, so `providerMetadata.openai.logprobs` now contains the logprobs of every streamed token instead of only the last chunk's tokens. Explicitly empty logprobs (`logprobs: { content: [], refusal: null }`) are reported as an empty array, as before.
|
|
20
|
+
|
|
21
|
+
A refusal that arrives in the same streamed chunk as the `finish_reason` is now taken into account: such a response is reported with a `content-filter` finish reason instead of `stop`.
|
|
22
|
+
|
|
23
|
+
`@ai-sdk/openai-compatible`: Chat Completions responses that carry `message.refusal` (non-streaming) or `delta.refusal` (streaming) were ignored, so providers such as OpenAI served through `createOpenAICompatible` lost the refusal text and reported an empty `stop` response. Refusals are now returned as text content after any content text, and a non-empty refusal with a `stop` finish reason is reported as a `content-filter` finish reason. This also applies when the refusal and the finish reason arrive in the same streamed chunk. Non-string refusals (for example `refusal: false` from servers that use booleans) are ignored instead of failing the response.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [49c554d]
|
|
26
|
+
- Updated dependencies [b753c03]
|
|
27
|
+
- @ai-sdk/provider-utils@3.0.45
|
|
28
|
+
|
|
3
29
|
## 1.0.61
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SharedV2ProviderMetadata, LanguageModelV2, LanguageModelV2Usage, EmbeddingModelV2, ImageModelV2, ProviderV2 } from '@ai-sdk/provider';
|
|
1
|
+
import { SharedV2ProviderMetadata, LanguageModelV2, LanguageModelV2CallWarning, LanguageModelV2Usage, EmbeddingModelV2, ImageModelV2, ProviderV2 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
4
|
import { z, ZodType } from 'zod/v4';
|
|
@@ -92,8 +92,9 @@ type OpenAICompatibleChatConfig = {
|
|
|
92
92
|
* Optional function to transform the request body before sending it to the API.
|
|
93
93
|
* This is useful for proxy providers that may require a different request format
|
|
94
94
|
* than the official OpenAI API.
|
|
95
|
+
* The optional warnings array can be used to report request transformations.
|
|
95
96
|
*/
|
|
96
|
-
transformRequestBody?: (args: Record<string, any
|
|
97
|
+
transformRequestBody?: (args: Record<string, any>, warnings?: LanguageModelV2CallWarning[]) => Record<string, any>;
|
|
97
98
|
/**
|
|
98
99
|
* Optional usage converter for OpenAI-compatible providers with different
|
|
99
100
|
* token accounting semantics.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SharedV2ProviderMetadata, LanguageModelV2, LanguageModelV2Usage, EmbeddingModelV2, ImageModelV2, ProviderV2 } from '@ai-sdk/provider';
|
|
1
|
+
import { SharedV2ProviderMetadata, LanguageModelV2, LanguageModelV2CallWarning, LanguageModelV2Usage, EmbeddingModelV2, ImageModelV2, ProviderV2 } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
4
|
import { z, ZodType } from 'zod/v4';
|
|
@@ -92,8 +92,9 @@ type OpenAICompatibleChatConfig = {
|
|
|
92
92
|
* Optional function to transform the request body before sending it to the API.
|
|
93
93
|
* This is useful for proxy providers that may require a different request format
|
|
94
94
|
* than the official OpenAI API.
|
|
95
|
+
* The optional warnings array can be used to report request transformations.
|
|
95
96
|
*/
|
|
96
|
-
transformRequestBody?: (args: Record<string, any
|
|
97
|
+
transformRequestBody?: (args: Record<string, any>, warnings?: LanguageModelV2CallWarning[]) => Record<string, any>;
|
|
97
98
|
/**
|
|
98
99
|
* Optional usage converter for OpenAI-compatible providers with different
|
|
99
100
|
* token accounting semantics.
|
package/dist/index.js
CHANGED
|
@@ -186,10 +186,10 @@ function getResponseMetadata({
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// src/chat/map-openai-compatible-finish-reason.ts
|
|
189
|
-
function mapOpenAICompatibleFinishReason(finishReason) {
|
|
189
|
+
function mapOpenAICompatibleFinishReason(finishReason, { hasRefusal = false } = {}) {
|
|
190
190
|
switch (finishReason) {
|
|
191
191
|
case "stop":
|
|
192
|
-
return "stop";
|
|
192
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
193
193
|
case "length":
|
|
194
194
|
return "length";
|
|
195
195
|
case "content_filter":
|
|
@@ -316,9 +316,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
316
316
|
var _a, _b, _c;
|
|
317
317
|
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
318
318
|
}
|
|
319
|
-
transformRequestBody(args) {
|
|
319
|
+
transformRequestBody(args, warnings) {
|
|
320
320
|
var _a, _b, _c;
|
|
321
|
-
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
321
|
+
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, warnings)) != null ? _c : args;
|
|
322
322
|
}
|
|
323
323
|
convertUsage(usage) {
|
|
324
324
|
var _a, _b, _c;
|
|
@@ -414,7 +414,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
414
414
|
async doGenerate(options) {
|
|
415
415
|
var _a, _b, _c, _d, _e;
|
|
416
416
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
417
|
-
const transformedArgs = this.transformRequestBody(args);
|
|
417
|
+
const transformedArgs = this.transformRequestBody(args, warnings);
|
|
418
418
|
const body = JSON.stringify(transformedArgs);
|
|
419
419
|
const {
|
|
420
420
|
responseHeaders,
|
|
@@ -446,6 +446,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
446
446
|
if (text != null && text.length > 0) {
|
|
447
447
|
content.push({ type: "text", text });
|
|
448
448
|
}
|
|
449
|
+
const refusal = choice.message.refusal;
|
|
450
|
+
const hasRefusal = refusal != null && refusal.length > 0;
|
|
451
|
+
if (hasRefusal) {
|
|
452
|
+
content.push({ type: "text", text: refusal });
|
|
453
|
+
}
|
|
449
454
|
const reasoning = (_a = choice.message.reasoning_content) != null ? _a : choice.message.reasoning;
|
|
450
455
|
if (reasoning != null && reasoning.length > 0) {
|
|
451
456
|
content.push({
|
|
@@ -478,7 +483,9 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
478
483
|
}
|
|
479
484
|
return {
|
|
480
485
|
content,
|
|
481
|
-
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason
|
|
486
|
+
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason, {
|
|
487
|
+
hasRefusal
|
|
488
|
+
}),
|
|
482
489
|
usage: this.convertUsage(responseBody.usage),
|
|
483
490
|
providerMetadata,
|
|
484
491
|
request: { body },
|
|
@@ -493,12 +500,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
493
500
|
async doStream(options) {
|
|
494
501
|
var _a;
|
|
495
502
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
496
|
-
const body = this.transformRequestBody(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
503
|
+
const body = this.transformRequestBody(
|
|
504
|
+
{
|
|
505
|
+
...args,
|
|
506
|
+
stream: true,
|
|
507
|
+
// only include stream_options when in strict compatibility mode:
|
|
508
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
509
|
+
},
|
|
510
|
+
warnings
|
|
511
|
+
);
|
|
502
512
|
const metadataExtractor = (_a = this.config.metadataExtractor) == null ? void 0 : _a.createStreamExtractor();
|
|
503
513
|
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
|
504
514
|
url: this.config.url({
|
|
@@ -516,6 +526,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
516
526
|
});
|
|
517
527
|
let toolCallTracker;
|
|
518
528
|
let finishReason = "unknown";
|
|
529
|
+
let rawFinishReason = void 0;
|
|
530
|
+
let hasRefusal = false;
|
|
519
531
|
const usage = {
|
|
520
532
|
completionTokens: void 0,
|
|
521
533
|
completionTokensDetails: {
|
|
@@ -592,9 +604,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
592
604
|
}
|
|
593
605
|
}
|
|
594
606
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
595
|
-
|
|
596
|
-
choice.finish_reason
|
|
597
|
-
);
|
|
607
|
+
rawFinishReason = choice.finish_reason;
|
|
598
608
|
}
|
|
599
609
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
600
610
|
return;
|
|
@@ -626,6 +636,19 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
626
636
|
delta: delta.content
|
|
627
637
|
});
|
|
628
638
|
}
|
|
639
|
+
const refusal = delta.refusal;
|
|
640
|
+
if (refusal != null && refusal.length > 0) {
|
|
641
|
+
hasRefusal = true;
|
|
642
|
+
if (!isActiveText) {
|
|
643
|
+
controller.enqueue({ type: "text-start", id: "txt-0" });
|
|
644
|
+
isActiveText = true;
|
|
645
|
+
}
|
|
646
|
+
controller.enqueue({
|
|
647
|
+
type: "text-delta",
|
|
648
|
+
id: "txt-0",
|
|
649
|
+
delta: refusal
|
|
650
|
+
});
|
|
651
|
+
}
|
|
629
652
|
if (delta.tool_calls != null) {
|
|
630
653
|
for (const [
|
|
631
654
|
fallbackIndex,
|
|
@@ -646,6 +669,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
646
669
|
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
647
670
|
}
|
|
648
671
|
toolCallTracker.flush();
|
|
672
|
+
if (rawFinishReason != null) {
|
|
673
|
+
finishReason = mapOpenAICompatibleFinishReason(rawFinishReason, {
|
|
674
|
+
hasRefusal
|
|
675
|
+
});
|
|
676
|
+
}
|
|
649
677
|
const providerMetadata = {
|
|
650
678
|
[providerOptionsName]: {},
|
|
651
679
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
|
@@ -704,6 +732,12 @@ var OpenAICompatibleChatResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
704
732
|
message: import_v43.z.object({
|
|
705
733
|
role: import_v43.z.literal("assistant").nullish(),
|
|
706
734
|
content: import_v43.z.string().nullish(),
|
|
735
|
+
// set instead of `content` when the model refuses to answer. Some
|
|
736
|
+
// OpenAI-compatible servers send non-string values (e.g. `false`),
|
|
737
|
+
// which are ignored instead of failing the whole response:
|
|
738
|
+
refusal: import_v43.z.unknown().nullish().transform(
|
|
739
|
+
(value) => typeof value === "string" ? value : void 0
|
|
740
|
+
),
|
|
707
741
|
reasoning_content: import_v43.z.string().nullish(),
|
|
708
742
|
reasoning: import_v43.z.string().nullish(),
|
|
709
743
|
tool_calls: import_v43.z.array(
|
|
@@ -733,6 +767,12 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_v43.z.union(
|
|
|
733
767
|
delta: import_v43.z.object({
|
|
734
768
|
role: import_v43.z.enum(["assistant"]).nullish(),
|
|
735
769
|
content: import_v43.z.string().nullish(),
|
|
770
|
+
// set instead of `content` when the model refuses to answer. Some
|
|
771
|
+
// OpenAI-compatible servers send non-string values (e.g. `false`),
|
|
772
|
+
// which are ignored instead of failing the whole response:
|
|
773
|
+
refusal: import_v43.z.unknown().nullish().transform(
|
|
774
|
+
(value) => typeof value === "string" ? value : void 0
|
|
775
|
+
),
|
|
736
776
|
// Most openai-compatible models set `reasoning_content`, but some
|
|
737
777
|
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
738
778
|
reasoning_content: import_v43.z.string().nullish(),
|
|
@@ -1369,7 +1409,7 @@ var openaiCompatibleImageResponseSchema = (0, import_provider_utils7.lazySchema)
|
|
|
1369
1409
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1370
1410
|
|
|
1371
1411
|
// src/version.ts
|
|
1372
|
-
var VERSION = true ? "1.0.
|
|
1412
|
+
var VERSION = true ? "1.0.63" : "0.0.0-test";
|
|
1373
1413
|
|
|
1374
1414
|
// src/openai-compatible-provider.ts
|
|
1375
1415
|
function createOpenAICompatible(options) {
|