@ai-sdk/openai-compatible 2.0.0-beta.57 → 2.0.0-beta.58
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 +9 -0
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.58
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cbf52cd: feat: expose raw finish reason
|
|
8
|
+
- Updated dependencies [cbf52cd]
|
|
9
|
+
- @ai-sdk/provider@3.0.0-beta.30
|
|
10
|
+
- @ai-sdk/provider-utils@4.0.0-beta.57
|
|
11
|
+
|
|
3
12
|
## 2.0.0-beta.57
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -242,7 +242,7 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
|
242
242
|
case "tool_calls":
|
|
243
243
|
return "tool-calls";
|
|
244
244
|
default:
|
|
245
|
-
return "
|
|
245
|
+
return "other";
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -434,7 +434,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
434
434
|
};
|
|
435
435
|
}
|
|
436
436
|
async doGenerate(options) {
|
|
437
|
-
var _a, _b, _c, _d, _e;
|
|
437
|
+
var _a, _b, _c, _d, _e, _f;
|
|
438
438
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
439
439
|
const body = JSON.stringify(args);
|
|
440
440
|
const {
|
|
@@ -493,7 +493,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
493
493
|
}
|
|
494
494
|
return {
|
|
495
495
|
content,
|
|
496
|
-
finishReason:
|
|
496
|
+
finishReason: {
|
|
497
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
498
|
+
raw: (_f = choice.finish_reason) != null ? _f : void 0
|
|
499
|
+
},
|
|
497
500
|
usage: convertOpenAICompatibleChatUsage(responseBody.usage),
|
|
498
501
|
providerMetadata,
|
|
499
502
|
request: { body },
|
|
@@ -530,7 +533,10 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
530
533
|
fetch: this.config.fetch
|
|
531
534
|
});
|
|
532
535
|
const toolCalls = [];
|
|
533
|
-
let finishReason =
|
|
536
|
+
let finishReason = {
|
|
537
|
+
unified: "other",
|
|
538
|
+
raw: void 0
|
|
539
|
+
};
|
|
534
540
|
let usage = void 0;
|
|
535
541
|
let isFirstChunk = true;
|
|
536
542
|
const providerOptionsName = this.providerOptionsName;
|
|
@@ -543,18 +549,18 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
543
549
|
controller.enqueue({ type: "stream-start", warnings });
|
|
544
550
|
},
|
|
545
551
|
transform(chunk, controller) {
|
|
546
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
552
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
547
553
|
if (options.includeRawChunks) {
|
|
548
554
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
549
555
|
}
|
|
550
556
|
if (!chunk.success) {
|
|
551
|
-
finishReason = "error";
|
|
557
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
552
558
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
553
559
|
return;
|
|
554
560
|
}
|
|
555
561
|
metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
|
|
556
562
|
if ("error" in chunk.value) {
|
|
557
|
-
finishReason = "error";
|
|
563
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
558
564
|
controller.enqueue({
|
|
559
565
|
type: "error",
|
|
560
566
|
error: chunk.value.error.message
|
|
@@ -574,15 +580,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
574
580
|
}
|
|
575
581
|
const choice = value.choices[0];
|
|
576
582
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
577
|
-
finishReason =
|
|
578
|
-
choice.finish_reason
|
|
579
|
-
|
|
583
|
+
finishReason = {
|
|
584
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
585
|
+
raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
|
|
586
|
+
};
|
|
580
587
|
}
|
|
581
588
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
582
589
|
return;
|
|
583
590
|
}
|
|
584
591
|
const delta = choice.delta;
|
|
585
|
-
const reasoningContent = (
|
|
592
|
+
const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
|
|
586
593
|
if (reasoningContent) {
|
|
587
594
|
if (!isActiveReasoning) {
|
|
588
595
|
controller.enqueue({
|
|
@@ -618,7 +625,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
618
625
|
message: `Expected 'id' to be a string.`
|
|
619
626
|
});
|
|
620
627
|
}
|
|
621
|
-
if (((
|
|
628
|
+
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
|
|
622
629
|
throw new import_provider3.InvalidResponseDataError({
|
|
623
630
|
data: toolCallDelta,
|
|
624
631
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -634,12 +641,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
634
641
|
type: "function",
|
|
635
642
|
function: {
|
|
636
643
|
name: toolCallDelta.function.name,
|
|
637
|
-
arguments: (
|
|
644
|
+
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
|
|
638
645
|
},
|
|
639
646
|
hasFinished: false
|
|
640
647
|
};
|
|
641
648
|
const toolCall2 = toolCalls[index];
|
|
642
|
-
if (((
|
|
649
|
+
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
|
|
643
650
|
if (toolCall2.function.arguments.length > 0) {
|
|
644
651
|
controller.enqueue({
|
|
645
652
|
type: "tool-input-delta",
|
|
@@ -654,7 +661,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
654
661
|
});
|
|
655
662
|
controller.enqueue({
|
|
656
663
|
type: "tool-call",
|
|
657
|
-
toolCallId: (
|
|
664
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils2.generateId)(),
|
|
658
665
|
toolName: toolCall2.function.name,
|
|
659
666
|
input: toolCall2.function.arguments
|
|
660
667
|
});
|
|
@@ -667,22 +674,22 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
667
674
|
if (toolCall.hasFinished) {
|
|
668
675
|
continue;
|
|
669
676
|
}
|
|
670
|
-
if (((
|
|
671
|
-
toolCall.function.arguments += (
|
|
677
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
678
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
672
679
|
}
|
|
673
680
|
controller.enqueue({
|
|
674
681
|
type: "tool-input-delta",
|
|
675
682
|
id: toolCall.id,
|
|
676
|
-
delta: (
|
|
683
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
677
684
|
});
|
|
678
|
-
if (((
|
|
685
|
+
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)) {
|
|
679
686
|
controller.enqueue({
|
|
680
687
|
type: "tool-input-end",
|
|
681
688
|
id: toolCall.id
|
|
682
689
|
});
|
|
683
690
|
controller.enqueue({
|
|
684
691
|
type: "tool-call",
|
|
685
|
-
toolCallId: (
|
|
692
|
+
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils2.generateId)(),
|
|
686
693
|
toolName: toolCall.function.name,
|
|
687
694
|
input: toolCall.function.arguments
|
|
688
695
|
});
|
|
@@ -949,7 +956,7 @@ function mapOpenAICompatibleFinishReason2(finishReason) {
|
|
|
949
956
|
case "tool_calls":
|
|
950
957
|
return "tool-calls";
|
|
951
958
|
default:
|
|
952
|
-
return "
|
|
959
|
+
return "other";
|
|
953
960
|
}
|
|
954
961
|
}
|
|
955
962
|
|
|
@@ -1095,7 +1102,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1095
1102
|
return {
|
|
1096
1103
|
content,
|
|
1097
1104
|
usage: convertOpenAICompatibleCompletionUsage(response.usage),
|
|
1098
|
-
finishReason:
|
|
1105
|
+
finishReason: {
|
|
1106
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
1107
|
+
raw: choice.finish_reason
|
|
1108
|
+
},
|
|
1099
1109
|
request: { body: args },
|
|
1100
1110
|
response: {
|
|
1101
1111
|
...getResponseMetadata2(response),
|
|
@@ -1127,7 +1137,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1127
1137
|
abortSignal: options.abortSignal,
|
|
1128
1138
|
fetch: this.config.fetch
|
|
1129
1139
|
});
|
|
1130
|
-
let finishReason =
|
|
1140
|
+
let finishReason = {
|
|
1141
|
+
unified: "other",
|
|
1142
|
+
raw: void 0
|
|
1143
|
+
};
|
|
1131
1144
|
let usage = void 0;
|
|
1132
1145
|
let isFirstChunk = true;
|
|
1133
1146
|
return {
|
|
@@ -1137,17 +1150,18 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1137
1150
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1138
1151
|
},
|
|
1139
1152
|
transform(chunk, controller) {
|
|
1153
|
+
var _a;
|
|
1140
1154
|
if (options.includeRawChunks) {
|
|
1141
1155
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1142
1156
|
}
|
|
1143
1157
|
if (!chunk.success) {
|
|
1144
|
-
finishReason = "error";
|
|
1158
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1145
1159
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1146
1160
|
return;
|
|
1147
1161
|
}
|
|
1148
1162
|
const value = chunk.value;
|
|
1149
1163
|
if ("error" in value) {
|
|
1150
|
-
finishReason = "error";
|
|
1164
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
1151
1165
|
controller.enqueue({ type: "error", error: value.error });
|
|
1152
1166
|
return;
|
|
1153
1167
|
}
|
|
@@ -1167,9 +1181,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1167
1181
|
}
|
|
1168
1182
|
const choice = value.choices[0];
|
|
1169
1183
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1170
|
-
finishReason =
|
|
1171
|
-
choice.finish_reason
|
|
1172
|
-
|
|
1184
|
+
finishReason = {
|
|
1185
|
+
unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
|
|
1186
|
+
raw: (_a = choice.finish_reason) != null ? _a : void 0
|
|
1187
|
+
};
|
|
1173
1188
|
}
|
|
1174
1189
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1175
1190
|
controller.enqueue({
|
|
@@ -1461,7 +1476,7 @@ async function fileToBlob(file) {
|
|
|
1461
1476
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1462
1477
|
|
|
1463
1478
|
// src/version.ts
|
|
1464
|
-
var VERSION = true ? "2.0.0-beta.
|
|
1479
|
+
var VERSION = true ? "2.0.0-beta.58" : "0.0.0-test";
|
|
1465
1480
|
|
|
1466
1481
|
// src/openai-compatible-provider.ts
|
|
1467
1482
|
function createOpenAICompatible(options) {
|