@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/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
21
21
  function getOpenAIMetadata(message) {
22
22
  var _a, _b;
23
- return (_b = (_a = message == null ? void 0 : message.providerMetadata) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
23
+ return (_b = (_a = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a.openaiCompatible) != null ? _b : {};
24
24
  }
25
25
  function convertToOpenAICompatibleChatMessages(prompt) {
26
26
  const messages = [];
@@ -175,16 +175,14 @@ import {
175
175
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
176
176
  } from "@ai-sdk/provider";
177
177
  function prepareTools({
178
- mode,
179
- structuredOutputs
178
+ tools,
179
+ toolChoice
180
180
  }) {
181
- var _a;
182
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
181
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
183
182
  const toolWarnings = [];
184
183
  if (tools == null) {
185
- return { tools: void 0, tool_choice: void 0, toolWarnings };
184
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
186
185
  }
187
- const toolChoice = mode.toolChoice;
188
186
  const openaiCompatTools = [];
189
187
  for (const tool of tools) {
190
188
  if (tool.type === "provider-defined") {
@@ -201,22 +199,20 @@ function prepareTools({
201
199
  }
202
200
  }
203
201
  if (toolChoice == null) {
204
- return { tools: openaiCompatTools, tool_choice: void 0, toolWarnings };
202
+ return { tools: openaiCompatTools, toolChoice: void 0, toolWarnings };
205
203
  }
206
204
  const type = toolChoice.type;
207
205
  switch (type) {
208
206
  case "auto":
209
207
  case "none":
210
208
  case "required":
211
- return { tools: openaiCompatTools, tool_choice: type, toolWarnings };
209
+ return { tools: openaiCompatTools, toolChoice: type, toolWarnings };
212
210
  case "tool":
213
211
  return {
214
212
  tools: openaiCompatTools,
215
- tool_choice: {
213
+ toolChoice: {
216
214
  type: "function",
217
- function: {
218
- name: toolChoice.toolName
219
- }
215
+ function: { name: toolChoice.toolName }
220
216
  },
221
217
  toolWarnings
222
218
  };
@@ -255,7 +251,6 @@ var OpenAICompatibleChatLanguageModel = class {
255
251
  return this.config.provider.split(".")[0].trim();
256
252
  }
257
253
  getArgs({
258
- mode,
259
254
  prompt,
260
255
  maxTokens,
261
256
  temperature,
@@ -263,19 +258,17 @@ var OpenAICompatibleChatLanguageModel = class {
263
258
  topK,
264
259
  frequencyPenalty,
265
260
  presencePenalty,
266
- providerMetadata,
261
+ providerOptions,
267
262
  stopSequences,
268
263
  responseFormat,
269
- seed
264
+ seed,
265
+ toolChoice,
266
+ tools
270
267
  }) {
271
- var _a, _b;
272
- const type = mode.type;
268
+ var _a;
273
269
  const warnings = [];
274
270
  if (topK != null) {
275
- warnings.push({
276
- type: "unsupported-setting",
277
- setting: "topK"
278
- });
271
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
279
272
  }
280
273
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
281
274
  warnings.push({
@@ -284,85 +277,45 @@ var OpenAICompatibleChatLanguageModel = class {
284
277
  details: "JSON response format schema is only supported with structuredOutputs"
285
278
  });
286
279
  }
287
- const baseArgs = {
288
- // model id:
289
- model: this.modelId,
290
- // model specific settings:
291
- user: this.settings.user,
292
- // standardized settings:
293
- max_tokens: maxTokens,
294
- temperature,
295
- top_p: topP,
296
- frequency_penalty: frequencyPenalty,
297
- presence_penalty: presencePenalty,
298
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && responseFormat.schema != null ? {
299
- type: "json_schema",
300
- json_schema: {
301
- schema: responseFormat.schema,
302
- name: (_a = responseFormat.name) != null ? _a : "response",
303
- description: responseFormat.description
304
- }
305
- } : { type: "json_object" } : void 0,
306
- stop: stopSequences,
307
- seed,
308
- ...providerMetadata == null ? void 0 : providerMetadata[this.providerOptionsName],
309
- // messages:
310
- messages: convertToOpenAICompatibleChatMessages(prompt)
280
+ const {
281
+ tools: openaiTools,
282
+ toolChoice: openaiToolChoice,
283
+ toolWarnings
284
+ } = prepareTools({
285
+ tools,
286
+ toolChoice
287
+ });
288
+ return {
289
+ args: {
290
+ // model id:
291
+ model: this.modelId,
292
+ // model specific settings:
293
+ user: this.settings.user,
294
+ // standardized settings:
295
+ max_tokens: maxTokens,
296
+ temperature,
297
+ top_p: topP,
298
+ frequency_penalty: frequencyPenalty,
299
+ presence_penalty: presencePenalty,
300
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && responseFormat.schema != null ? {
301
+ type: "json_schema",
302
+ json_schema: {
303
+ schema: responseFormat.schema,
304
+ name: (_a = responseFormat.name) != null ? _a : "response",
305
+ description: responseFormat.description
306
+ }
307
+ } : { type: "json_object" } : void 0,
308
+ stop: stopSequences,
309
+ seed,
310
+ ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
311
+ // messages:
312
+ messages: convertToOpenAICompatibleChatMessages(prompt),
313
+ // tools:
314
+ tools: openaiTools,
315
+ tool_choice: openaiToolChoice
316
+ },
317
+ warnings: [...warnings, ...toolWarnings]
311
318
  };
312
- switch (type) {
313
- case "regular": {
314
- const { tools, tool_choice, toolWarnings } = prepareTools({
315
- mode,
316
- structuredOutputs: this.supportsStructuredOutputs
317
- });
318
- return {
319
- args: { ...baseArgs, tools, tool_choice },
320
- warnings: [...warnings, ...toolWarnings]
321
- };
322
- }
323
- case "object-json": {
324
- return {
325
- args: {
326
- ...baseArgs,
327
- response_format: this.supportsStructuredOutputs === true && mode.schema != null ? {
328
- type: "json_schema",
329
- json_schema: {
330
- schema: mode.schema,
331
- name: (_b = mode.name) != null ? _b : "response",
332
- description: mode.description
333
- }
334
- } : { type: "json_object" }
335
- },
336
- warnings
337
- };
338
- }
339
- case "object-tool": {
340
- return {
341
- args: {
342
- ...baseArgs,
343
- tool_choice: {
344
- type: "function",
345
- function: { name: mode.tool.name }
346
- },
347
- tools: [
348
- {
349
- type: "function",
350
- function: {
351
- name: mode.tool.name,
352
- description: mode.tool.description,
353
- parameters: mode.tool.parameters
354
- }
355
- }
356
- ]
357
- },
358
- warnings
359
- };
360
- }
361
- default: {
362
- const _exhaustiveCheck = type;
363
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
364
- }
365
- }
366
319
  }
367
320
  async doGenerate(options) {
368
321
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
@@ -783,9 +736,6 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => z2.union([
783
736
  ]);
784
737
 
785
738
  // src/openai-compatible-completion-language-model.ts
786
- import {
787
- UnsupportedFunctionalityError as UnsupportedFunctionalityError4
788
- } from "@ai-sdk/provider";
789
739
  import {
790
740
  combineHeaders as combineHeaders2,
791
741
  createEventSourceResponseHandler as createEventSourceResponseHandler2,
@@ -905,7 +855,6 @@ var OpenAICompatibleCompletionLanguageModel = class {
905
855
  return this.config.provider.split(".")[0].trim();
906
856
  }
907
857
  getArgs({
908
- mode,
909
858
  inputFormat,
910
859
  prompt,
911
860
  maxTokens,
@@ -917,16 +866,19 @@ var OpenAICompatibleCompletionLanguageModel = class {
917
866
  stopSequences: userStopSequences,
918
867
  responseFormat,
919
868
  seed,
920
- providerMetadata
869
+ providerOptions,
870
+ tools,
871
+ toolChoice
921
872
  }) {
922
- var _a;
923
- const type = mode.type;
924
873
  const warnings = [];
925
874
  if (topK != null) {
926
- warnings.push({
927
- type: "unsupported-setting",
928
- setting: "topK"
929
- });
875
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
876
+ }
877
+ if (tools == null ? void 0 : tools.length) {
878
+ warnings.push({ type: "unsupported-setting", setting: "tools" });
879
+ }
880
+ if (toolChoice != null) {
881
+ warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
930
882
  }
931
883
  if (responseFormat != null && responseFormat.type !== "text") {
932
884
  warnings.push({
@@ -937,56 +889,30 @@ var OpenAICompatibleCompletionLanguageModel = class {
937
889
  }
938
890
  const { prompt: completionPrompt, stopSequences } = convertToOpenAICompatibleCompletionPrompt({ prompt, inputFormat });
939
891
  const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
940
- const baseArgs = {
941
- // model id:
942
- model: this.modelId,
943
- // model specific settings:
944
- echo: this.settings.echo,
945
- logit_bias: this.settings.logitBias,
946
- suffix: this.settings.suffix,
947
- user: this.settings.user,
948
- // standardized settings:
949
- max_tokens: maxTokens,
950
- temperature,
951
- top_p: topP,
952
- frequency_penalty: frequencyPenalty,
953
- presence_penalty: presencePenalty,
954
- seed,
955
- ...providerMetadata == null ? void 0 : providerMetadata[this.providerOptionsName],
956
- // prompt:
957
- prompt: completionPrompt,
958
- // stop sequences:
959
- stop: stop.length > 0 ? stop : void 0
892
+ return {
893
+ args: {
894
+ // model id:
895
+ model: this.modelId,
896
+ // model specific settings:
897
+ echo: this.settings.echo,
898
+ logit_bias: this.settings.logitBias,
899
+ suffix: this.settings.suffix,
900
+ user: this.settings.user,
901
+ // standardized settings:
902
+ max_tokens: maxTokens,
903
+ temperature,
904
+ top_p: topP,
905
+ frequency_penalty: frequencyPenalty,
906
+ presence_penalty: presencePenalty,
907
+ seed,
908
+ ...providerOptions == null ? void 0 : providerOptions[this.providerOptionsName],
909
+ // prompt:
910
+ prompt: completionPrompt,
911
+ // stop sequences:
912
+ stop: stop.length > 0 ? stop : void 0
913
+ },
914
+ warnings
960
915
  };
961
- switch (type) {
962
- case "regular": {
963
- if ((_a = mode.tools) == null ? void 0 : _a.length) {
964
- throw new UnsupportedFunctionalityError4({
965
- functionality: "tools"
966
- });
967
- }
968
- if (mode.toolChoice) {
969
- throw new UnsupportedFunctionalityError4({
970
- functionality: "toolChoice"
971
- });
972
- }
973
- return { args: baseArgs, warnings };
974
- }
975
- case "object-json": {
976
- throw new UnsupportedFunctionalityError4({
977
- functionality: "object-json mode"
978
- });
979
- }
980
- case "object-tool": {
981
- throw new UnsupportedFunctionalityError4({
982
- functionality: "object-tool mode"
983
- });
984
- }
985
- default: {
986
- const _exhaustiveCheck = type;
987
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
988
- }
989
- }
990
916
  }
991
917
  async doGenerate(options) {
992
918
  var _a, _b, _c, _d;