@databricks/ai-sdk-provider 0.2.2 → 0.2.3

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.cjs CHANGED
@@ -1189,6 +1189,75 @@ function convertResponsesToolChoice(toolChoice) {
1189
1189
  }
1190
1190
  }
1191
1191
 
1192
+ //#endregion
1193
+ //#region src/responses-agent-language-model/call-options-to-responses-args.ts
1194
+ /**
1195
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks Responses API body parameters.
1196
+ *
1197
+ * Inspired by the getArgs method in:
1198
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L118
1199
+ *
1200
+ * Complies with the API described in:
1201
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#responses-api-request
1202
+ */
1203
+ function callOptionsToResponsesArgs(options) {
1204
+ const warnings = [];
1205
+ const databricksOptions = options.providerOptions?.databricks;
1206
+ if (options.topK != null) warnings.push({
1207
+ type: "unsupported-setting",
1208
+ setting: "topK",
1209
+ details: "topK is not supported by the Databricks Responses API"
1210
+ });
1211
+ if (options.presencePenalty != null) warnings.push({
1212
+ type: "unsupported-setting",
1213
+ setting: "presencePenalty",
1214
+ details: "presencePenalty is not supported by the Databricks Responses API"
1215
+ });
1216
+ if (options.frequencyPenalty != null) warnings.push({
1217
+ type: "unsupported-setting",
1218
+ setting: "frequencyPenalty",
1219
+ details: "frequencyPenalty is not supported by the Databricks Responses API"
1220
+ });
1221
+ if (options.seed != null) warnings.push({
1222
+ type: "unsupported-setting",
1223
+ setting: "seed",
1224
+ details: "seed is not supported by the Databricks Responses API"
1225
+ });
1226
+ if (options.stopSequences != null && options.stopSequences.length > 0) warnings.push({
1227
+ type: "unsupported-setting",
1228
+ setting: "stopSequences",
1229
+ details: "stopSequences is not supported by the Databricks Responses API"
1230
+ });
1231
+ const args = {};
1232
+ if (options.maxOutputTokens != null) args.max_output_tokens = options.maxOutputTokens;
1233
+ if (options.temperature != null) args.temperature = options.temperature;
1234
+ if (options.topP != null) args.top_p = options.topP;
1235
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1236
+ case "text":
1237
+ args.text = { format: { type: "text" } };
1238
+ break;
1239
+ case "json":
1240
+ if (options.responseFormat.schema != null) args.text = { format: {
1241
+ type: "json_schema",
1242
+ json_schema: {
1243
+ name: options.responseFormat.name ?? "response",
1244
+ description: options.responseFormat.description,
1245
+ schema: options.responseFormat.schema,
1246
+ strict: true
1247
+ }
1248
+ } };
1249
+ else args.text = { format: { type: "json_object" } };
1250
+ break;
1251
+ }
1252
+ if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
1253
+ if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
1254
+ if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
1255
+ return {
1256
+ args,
1257
+ warnings
1258
+ };
1259
+ }
1260
+
1192
1261
  //#endregion
1193
1262
  //#region src/responses-agent-language-model/responses-agent-language-model.ts
1194
1263
  function mapResponsesFinishReason({ finishReason, hasToolCalls }) {
@@ -1213,7 +1282,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1213
1282
  }
1214
1283
  supportedUrls = {};
1215
1284
  async doGenerate(options) {
1216
- const networkArgs = await this.getArgs({
1285
+ const { warnings,...networkArgs } = await this.getArgs({
1217
1286
  config: this.config,
1218
1287
  options,
1219
1288
  stream: false,
@@ -1241,11 +1310,11 @@ var DatabricksResponsesAgentLanguageModel = class {
1241
1310
  outputTokens: response.usage?.output_tokens ?? 0,
1242
1311
  totalTokens: response.usage?.total_tokens ?? 0
1243
1312
  },
1244
- warnings: []
1313
+ warnings
1245
1314
  };
1246
1315
  }
1247
1316
  async doStream(options) {
1248
- const networkArgs = await this.getArgs({
1317
+ const { warnings,...networkArgs } = await this.getArgs({
1249
1318
  config: this.config,
1250
1319
  options,
1251
1320
  stream: true,
@@ -1273,7 +1342,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1273
1342
  start(controller) {
1274
1343
  controller.enqueue({
1275
1344
  type: "stream-start",
1276
- warnings: []
1345
+ warnings
1277
1346
  });
1278
1347
  },
1279
1348
  transform(chunk, controller) {
@@ -1348,6 +1417,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1348
1417
  tools: options.tools,
1349
1418
  toolChoice: options.toolChoice
1350
1419
  });
1420
+ const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
1351
1421
  return {
1352
1422
  url: config.url({ path: "/responses" }),
1353
1423
  headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
@@ -1356,8 +1426,10 @@ var DatabricksResponsesAgentLanguageModel = class {
1356
1426
  input,
1357
1427
  stream,
1358
1428
  ...tools ? { tools } : {},
1359
- ...toolChoice && tools ? { tool_choice: toolChoice } : {}
1429
+ ...toolChoice && tools ? { tool_choice: toolChoice } : {},
1430
+ ...callArgs
1360
1431
  },
1432
+ warnings,
1361
1433
  fetch: config.fetch
1362
1434
  };
1363
1435
  }
@@ -1766,6 +1838,69 @@ function mapFmapiFinishReason(finishReason) {
1766
1838
  }
1767
1839
  }
1768
1840
 
1841
+ //#endregion
1842
+ //#region src/fmapi-language-model/call-options-to-fmapi-args.ts
1843
+ /**
1844
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks FMAPI body parameters.
1845
+ *
1846
+ * Inspired by the getArgs method in:
1847
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/chat/openai-chat-language-model.ts#L71
1848
+ *
1849
+ * Complies with the API described in:
1850
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#chat-request
1851
+ */
1852
+ function callOptionsToFmapiArgs(options) {
1853
+ const warnings = [];
1854
+ const databricksOptions = options.providerOptions?.databricks;
1855
+ if (options.presencePenalty != null) warnings.push({
1856
+ type: "unsupported-setting",
1857
+ setting: "presencePenalty",
1858
+ details: "presencePenalty is not supported by the Databricks FMAPI"
1859
+ });
1860
+ if (options.frequencyPenalty != null) warnings.push({
1861
+ type: "unsupported-setting",
1862
+ setting: "frequencyPenalty",
1863
+ details: "frequencyPenalty is not supported by the Databricks FMAPI"
1864
+ });
1865
+ if (options.seed != null) warnings.push({
1866
+ type: "unsupported-setting",
1867
+ setting: "seed",
1868
+ details: "seed is not supported by the Databricks FMAPI"
1869
+ });
1870
+ const args = {};
1871
+ if (options.maxOutputTokens != null) args.max_tokens = options.maxOutputTokens;
1872
+ if (options.temperature != null) args.temperature = options.temperature;
1873
+ if (options.topP != null) args.top_p = options.topP;
1874
+ if (options.topK != null) args.top_k = options.topK;
1875
+ if (options.stopSequences != null && options.stopSequences.length > 0) args.stop = options.stopSequences;
1876
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1877
+ case "text":
1878
+ args.response_format = { type: "text" };
1879
+ break;
1880
+ case "json":
1881
+ if (options.responseFormat.schema != null) args.response_format = {
1882
+ type: "json_schema",
1883
+ json_schema: {
1884
+ name: options.responseFormat.name ?? "response",
1885
+ description: options.responseFormat.description,
1886
+ schema: options.responseFormat.schema,
1887
+ strict: true
1888
+ }
1889
+ };
1890
+ else args.response_format = { type: "json_object" };
1891
+ break;
1892
+ }
1893
+ if (databricksOptions?.topK != null) args.top_k = databricksOptions.topK;
1894
+ if (databricksOptions?.n != null) args.n = databricksOptions.n;
1895
+ if (databricksOptions?.logprobs != null) args.logprobs = databricksOptions.logprobs;
1896
+ if (databricksOptions?.topLogprobs != null) args.top_logprobs = databricksOptions.topLogprobs;
1897
+ if (databricksOptions?.reasoningEffort != null) args.reasoning_effort = databricksOptions.reasoningEffort;
1898
+ return {
1899
+ args,
1900
+ warnings
1901
+ };
1902
+ }
1903
+
1769
1904
  //#endregion
1770
1905
  //#region src/fmapi-language-model/fmapi-language-model.ts
1771
1906
  var DatabricksFmapiLanguageModel = class {
@@ -1781,7 +1916,7 @@ var DatabricksFmapiLanguageModel = class {
1781
1916
  }
1782
1917
  supportedUrls = {};
1783
1918
  async doGenerate(options) {
1784
- const networkArgs = await this.getArgs({
1919
+ const { warnings,...networkArgs } = await this.getArgs({
1785
1920
  config: this.config,
1786
1921
  options,
1787
1922
  stream: false,
@@ -1806,11 +1941,11 @@ var DatabricksFmapiLanguageModel = class {
1806
1941
  outputTokens: response.usage?.completion_tokens ?? 0,
1807
1942
  totalTokens: response.usage?.total_tokens ?? 0
1808
1943
  },
1809
- warnings: []
1944
+ warnings
1810
1945
  };
1811
1946
  }
1812
1947
  async doStream(options) {
1813
- const networkArgs = await this.getArgs({
1948
+ const { warnings,...networkArgs } = await this.getArgs({
1814
1949
  config: this.config,
1815
1950
  options,
1816
1951
  stream: true,
@@ -1840,7 +1975,7 @@ var DatabricksFmapiLanguageModel = class {
1840
1975
  start(controller) {
1841
1976
  controller.enqueue({
1842
1977
  type: "stream-start",
1843
- warnings: []
1978
+ warnings
1844
1979
  });
1845
1980
  },
1846
1981
  transform(chunk, controller) {
@@ -1907,6 +2042,7 @@ var DatabricksFmapiLanguageModel = class {
1907
2042
  const tools = options.tools?.map((tool) => convertToolToOpenAIFormat(tool)).filter((tool) => tool !== void 0);
1908
2043
  const toolChoice = options.toolChoice ? convertToolChoiceToOpenAIFormat(options.toolChoice) : void 0;
1909
2044
  const { messages } = await convertPromptToFmapiMessages(options.prompt);
2045
+ const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
1910
2046
  return {
1911
2047
  url: config.url({ path: "/chat/completions" }),
1912
2048
  headers: (0, __ai_sdk_provider_utils.combineHeaders)(config.headers(), options.headers),
@@ -1916,10 +2052,9 @@ var DatabricksFmapiLanguageModel = class {
1916
2052
  model: modelId,
1917
2053
  ...tools && tools.length > 0 ? { tools } : {},
1918
2054
  ...toolChoice && tools && tools.length > 0 ? { tool_choice: toolChoice } : {},
1919
- ...options.temperature !== void 0 ? { temperature: options.temperature } : {},
1920
- ...options.maxOutputTokens !== void 0 ? { max_tokens: options.maxOutputTokens } : {},
1921
- ...options.stopSequences && options.stopSequences.length > 0 ? { stop: options.stopSequences } : {}
2055
+ ...callArgs
1922
2056
  },
2057
+ warnings,
1923
2058
  fetch: config.fetch
1924
2059
  };
1925
2060
  }