@ai-sdk/openai-compatible 1.0.0-canary.1 → 1.0.0-canary.2
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 +88 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -160
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +1 -1
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +1 -1
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# @ai-sdk/openai-compatible
|
2
2
|
|
3
|
+
## 1.0.0-canary.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [c57e248]
|
8
|
+
- Updated dependencies [33f4a6a]
|
9
|
+
- @ai-sdk/provider@2.0.0-canary.1
|
10
|
+
- @ai-sdk/provider-utils@3.0.0-canary.2
|
11
|
+
|
3
12
|
## 1.0.0-canary.1
|
4
13
|
|
5
14
|
### Patch Changes
|
package/dist/index.js
CHANGED
@@ -38,7 +38,7 @@ var import_provider = require("@ai-sdk/provider");
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
39
39
|
function getOpenAIMetadata(message) {
|
40
40
|
var _a, _b;
|
41
|
-
return (_b = (_a = message == null ? void 0 : message.
|
41
|
+
return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
|
42
42
|
}
|
43
43
|
function convertToOpenAICompatibleChatMessages(prompt) {
|
44
44
|
const messages = [];
|
@@ -191,16 +191,14 @@ var defaultOpenAICompatibleErrorStructure = {
|
|
191
191
|
// src/openai-compatible-prepare-tools.ts
|
192
192
|
var import_provider2 = require("@ai-sdk/provider");
|
193
193
|
function prepareTools({
|
194
|
-
|
195
|
-
|
194
|
+
tools,
|
195
|
+
toolChoice
|
196
196
|
}) {
|
197
|
-
|
198
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
197
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
199
198
|
const toolWarnings = [];
|
200
199
|
if (tools == null) {
|
201
|
-
return { tools: void 0,
|
200
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
202
201
|
}
|
203
|
-
const toolChoice = mode.toolChoice;
|
204
202
|
const openaiCompatTools = [];
|
205
203
|
for (const tool of tools) {
|
206
204
|
if (tool.type === "provider-defined") {
|
@@ -217,22 +215,20 @@ function prepareTools({
|
|
217
215
|
}
|
218
216
|
}
|
219
217
|
if (toolChoice == null) {
|
220
|
-
return { tools: openaiCompatTools,
|
218
|
+
return { tools: openaiCompatTools, toolChoice: void 0, toolWarnings };
|
221
219
|
}
|
222
220
|
const type = toolChoice.type;
|
223
221
|
switch (type) {
|
224
222
|
case "auto":
|
225
223
|
case "none":
|
226
224
|
case "required":
|
227
|
-
return { tools: openaiCompatTools,
|
225
|
+
return { tools: openaiCompatTools, toolChoice: type, toolWarnings };
|
228
226
|
case "tool":
|
229
227
|
return {
|
230
228
|
tools: openaiCompatTools,
|
231
|
-
|
229
|
+
toolChoice: {
|
232
230
|
type: "function",
|
233
|
-
function: {
|
234
|
-
name: toolChoice.toolName
|
235
|
-
}
|
231
|
+
function: { name: toolChoice.toolName }
|
236
232
|
},
|
237
233
|
toolWarnings
|
238
234
|
};
|
@@ -271,7 +267,6 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
271
267
|
return this.config.provider.split(".")[0].trim();
|
272
268
|
}
|
273
269
|
getArgs({
|
274
|
-
mode,
|
275
270
|
prompt,
|
276
271
|
maxTokens,
|
277
272
|
temperature,
|
@@ -279,19 +274,17 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
279
274
|
topK,
|
280
275
|
frequencyPenalty,
|
281
276
|
presencePenalty,
|
282
|
-
|
277
|
+
providerOptions,
|
283
278
|
stopSequences,
|
284
279
|
responseFormat,
|
285
|
-
seed
|
280
|
+
seed,
|
281
|
+
toolChoice,
|
282
|
+
tools
|
286
283
|
}) {
|
287
|
-
var _a
|
288
|
-
const type = mode.type;
|
284
|
+
var _a;
|
289
285
|
const warnings = [];
|
290
286
|
if (topK != null) {
|
291
|
-
warnings.push({
|
292
|
-
type: "unsupported-setting",
|
293
|
-
setting: "topK"
|
294
|
-
});
|
287
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
295
288
|
}
|
296
289
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
|
297
290
|
warnings.push({
|
@@ -300,85 +293,45 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
300
293
|
details: "JSON response format schema is only supported with structuredOutputs"
|
301
294
|
});
|
302
295
|
}
|
303
|
-
const
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
296
|
+
const {
|
297
|
+
tools: openaiTools,
|
298
|
+
toolChoice: openaiToolChoice,
|
299
|
+
toolWarnings
|
300
|
+
} = prepareTools({
|
301
|
+
tools,
|
302
|
+
toolChoice
|
303
|
+
});
|
304
|
+
return {
|
305
|
+
args: {
|
306
|
+
// model id:
|
307
|
+
model: this.modelId,
|
308
|
+
// model specific settings:
|
309
|
+
user: this.settings.user,
|
310
|
+
// standardized settings:
|
311
|
+
max_tokens: maxTokens,
|
312
|
+
temperature,
|
313
|
+
top_p: topP,
|
314
|
+
frequency_penalty: frequencyPenalty,
|
315
|
+
presence_penalty: presencePenalty,
|
316
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && responseFormat.schema != null ? {
|
317
|
+
type: "json_schema",
|
318
|
+
json_schema: {
|
319
|
+
schema: responseFormat.schema,
|
320
|
+
name: (_a = responseFormat.name) != null ? _a : "response",
|
321
|
+
description: responseFormat.description
|
322
|
+
}
|
323
|
+
} : { type: "json_object" } : void 0,
|
324
|
+
stop: stopSequences,
|
325
|
+
seed,
|
326
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
327
|
+
// messages:
|
328
|
+
messages: convertToOpenAICompatibleChatMessages(prompt),
|
329
|
+
// tools:
|
330
|
+
tools: openaiTools,
|
331
|
+
tool_choice: openaiToolChoice
|
332
|
+
},
|
333
|
+
warnings: [...warnings, ...toolWarnings]
|
327
334
|
};
|
328
|
-
switch (type) {
|
329
|
-
case "regular": {
|
330
|
-
const { tools, tool_choice, toolWarnings } = prepareTools({
|
331
|
-
mode,
|
332
|
-
structuredOutputs: this.supportsStructuredOutputs
|
333
|
-
});
|
334
|
-
return {
|
335
|
-
args: { ...baseArgs, tools, tool_choice },
|
336
|
-
warnings: [...warnings, ...toolWarnings]
|
337
|
-
};
|
338
|
-
}
|
339
|
-
case "object-json": {
|
340
|
-
return {
|
341
|
-
args: {
|
342
|
-
...baseArgs,
|
343
|
-
response_format: this.supportsStructuredOutputs === true && mode.schema != null ? {
|
344
|
-
type: "json_schema",
|
345
|
-
json_schema: {
|
346
|
-
schema: mode.schema,
|
347
|
-
name: (_b = mode.name) != null ? _b : "response",
|
348
|
-
description: mode.description
|
349
|
-
}
|
350
|
-
} : { type: "json_object" }
|
351
|
-
},
|
352
|
-
warnings
|
353
|
-
};
|
354
|
-
}
|
355
|
-
case "object-tool": {
|
356
|
-
return {
|
357
|
-
args: {
|
358
|
-
...baseArgs,
|
359
|
-
tool_choice: {
|
360
|
-
type: "function",
|
361
|
-
function: { name: mode.tool.name }
|
362
|
-
},
|
363
|
-
tools: [
|
364
|
-
{
|
365
|
-
type: "function",
|
366
|
-
function: {
|
367
|
-
name: mode.tool.name,
|
368
|
-
description: mode.tool.description,
|
369
|
-
parameters: mode.tool.parameters
|
370
|
-
}
|
371
|
-
}
|
372
|
-
]
|
373
|
-
},
|
374
|
-
warnings
|
375
|
-
};
|
376
|
-
}
|
377
|
-
default: {
|
378
|
-
const _exhaustiveCheck = type;
|
379
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
380
|
-
}
|
381
|
-
}
|
382
335
|
}
|
383
336
|
async doGenerate(options) {
|
384
337
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
@@ -799,7 +752,6 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod2.z.union
|
|
799
752
|
]);
|
800
753
|
|
801
754
|
// src/openai-compatible-completion-language-model.ts
|
802
|
-
var import_provider5 = require("@ai-sdk/provider");
|
803
755
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
804
756
|
var import_zod3 = require("zod");
|
805
757
|
|
@@ -910,7 +862,6 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
910
862
|
return this.config.provider.split(".")[0].trim();
|
911
863
|
}
|
912
864
|
getArgs({
|
913
|
-
mode,
|
914
865
|
inputFormat,
|
915
866
|
prompt,
|
916
867
|
maxTokens,
|
@@ -922,16 +873,19 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
922
873
|
stopSequences: userStopSequences,
|
923
874
|
responseFormat,
|
924
875
|
seed,
|
925
|
-
|
876
|
+
providerOptions,
|
877
|
+
tools,
|
878
|
+
toolChoice
|
926
879
|
}) {
|
927
|
-
var _a;
|
928
|
-
const type = mode.type;
|
929
880
|
const warnings = [];
|
930
881
|
if (topK != null) {
|
931
|
-
warnings.push({
|
932
|
-
|
933
|
-
|
934
|
-
});
|
882
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
883
|
+
}
|
884
|
+
if (tools == null ? void 0 : tools.length) {
|
885
|
+
warnings.push({ type: "unsupported-setting", setting: "tools" });
|
886
|
+
}
|
887
|
+
if (toolChoice != null) {
|
888
|
+
warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
|
935
889
|
}
|
936
890
|
if (responseFormat != null && responseFormat.type !== "text") {
|
937
891
|
warnings.push({
|
@@ -942,56 +896,30 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
942
896
|
}
|
943
897
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompatibleCompletionPrompt({ prompt, inputFormat });
|
944
898
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
899
|
+
return {
|
900
|
+
args: {
|
901
|
+
// model id:
|
902
|
+
model: this.modelId,
|
903
|
+
// model specific settings:
|
904
|
+
echo: this.settings.echo,
|
905
|
+
logit_bias: this.settings.logitBias,
|
906
|
+
suffix: this.settings.suffix,
|
907
|
+
user: this.settings.user,
|
908
|
+
// standardized settings:
|
909
|
+
max_tokens: maxTokens,
|
910
|
+
temperature,
|
911
|
+
top_p: topP,
|
912
|
+
frequency_penalty: frequencyPenalty,
|
913
|
+
presence_penalty: presencePenalty,
|
914
|
+
seed,
|
915
|
+
...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
|
916
|
+
// prompt:
|
917
|
+
prompt: completionPrompt,
|
918
|
+
// stop sequences:
|
919
|
+
stop: stop.length > 0 ? stop : void 0
|
920
|
+
},
|
921
|
+
warnings
|
965
922
|
};
|
966
|
-
switch (type) {
|
967
|
-
case "regular": {
|
968
|
-
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
969
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
970
|
-
functionality: "tools"
|
971
|
-
});
|
972
|
-
}
|
973
|
-
if (mode.toolChoice) {
|
974
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
975
|
-
functionality: "toolChoice"
|
976
|
-
});
|
977
|
-
}
|
978
|
-
return { args: baseArgs, warnings };
|
979
|
-
}
|
980
|
-
case "object-json": {
|
981
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
982
|
-
functionality: "object-json mode"
|
983
|
-
});
|
984
|
-
}
|
985
|
-
case "object-tool": {
|
986
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
987
|
-
functionality: "object-tool mode"
|
988
|
-
});
|
989
|
-
}
|
990
|
-
default: {
|
991
|
-
const _exhaustiveCheck = type;
|
992
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
993
|
-
}
|
994
|
-
}
|
995
923
|
}
|
996
924
|
async doGenerate(options) {
|
997
925
|
var _a, _b, _c, _d;
|
@@ -1150,7 +1078,7 @@ var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod3.z
|
|
1150
1078
|
]);
|
1151
1079
|
|
1152
1080
|
// src/openai-compatible-embedding-model.ts
|
1153
|
-
var
|
1081
|
+
var import_provider5 = require("@ai-sdk/provider");
|
1154
1082
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1155
1083
|
var import_zod4 = require("zod");
|
1156
1084
|
var OpenAICompatibleEmbeddingModel = class {
|
@@ -1178,7 +1106,7 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
1178
1106
|
}) {
|
1179
1107
|
var _a;
|
1180
1108
|
if (values.length > this.maxEmbeddingsPerCall) {
|
1181
|
-
throw new
|
1109
|
+
throw new import_provider5.TooManyEmbeddingValuesForCallError({
|
1182
1110
|
provider: this.provider,
|
1183
1111
|
modelId: this.modelId,
|
1184
1112
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|