@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.js CHANGED
@@ -1165,6 +1165,75 @@ function convertResponsesToolChoice(toolChoice) {
1165
1165
  }
1166
1166
  }
1167
1167
 
1168
+ //#endregion
1169
+ //#region src/responses-agent-language-model/call-options-to-responses-args.ts
1170
+ /**
1171
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks Responses API body parameters.
1172
+ *
1173
+ * Inspired by the getArgs method in:
1174
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/responses/openai-responses-language-model.ts#L118
1175
+ *
1176
+ * Complies with the API described in:
1177
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#responses-api-request
1178
+ */
1179
+ function callOptionsToResponsesArgs(options) {
1180
+ const warnings = [];
1181
+ const databricksOptions = options.providerOptions?.databricks;
1182
+ if (options.topK != null) warnings.push({
1183
+ type: "unsupported-setting",
1184
+ setting: "topK",
1185
+ details: "topK is not supported by the Databricks Responses API"
1186
+ });
1187
+ if (options.presencePenalty != null) warnings.push({
1188
+ type: "unsupported-setting",
1189
+ setting: "presencePenalty",
1190
+ details: "presencePenalty is not supported by the Databricks Responses API"
1191
+ });
1192
+ if (options.frequencyPenalty != null) warnings.push({
1193
+ type: "unsupported-setting",
1194
+ setting: "frequencyPenalty",
1195
+ details: "frequencyPenalty is not supported by the Databricks Responses API"
1196
+ });
1197
+ if (options.seed != null) warnings.push({
1198
+ type: "unsupported-setting",
1199
+ setting: "seed",
1200
+ details: "seed is not supported by the Databricks Responses API"
1201
+ });
1202
+ if (options.stopSequences != null && options.stopSequences.length > 0) warnings.push({
1203
+ type: "unsupported-setting",
1204
+ setting: "stopSequences",
1205
+ details: "stopSequences is not supported by the Databricks Responses API"
1206
+ });
1207
+ const args = {};
1208
+ if (options.maxOutputTokens != null) args.max_output_tokens = options.maxOutputTokens;
1209
+ if (options.temperature != null) args.temperature = options.temperature;
1210
+ if (options.topP != null) args.top_p = options.topP;
1211
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1212
+ case "text":
1213
+ args.text = { format: { type: "text" } };
1214
+ break;
1215
+ case "json":
1216
+ if (options.responseFormat.schema != null) args.text = { format: {
1217
+ type: "json_schema",
1218
+ json_schema: {
1219
+ name: options.responseFormat.name ?? "response",
1220
+ description: options.responseFormat.description,
1221
+ schema: options.responseFormat.schema,
1222
+ strict: true
1223
+ }
1224
+ } };
1225
+ else args.text = { format: { type: "json_object" } };
1226
+ break;
1227
+ }
1228
+ if (databricksOptions?.parallelToolCalls != null) args.parallel_tool_calls = databricksOptions.parallelToolCalls;
1229
+ if (databricksOptions?.metadata != null) args.metadata = databricksOptions.metadata;
1230
+ if (databricksOptions?.reasoning != null) args.reasoning = databricksOptions.reasoning;
1231
+ return {
1232
+ args,
1233
+ warnings
1234
+ };
1235
+ }
1236
+
1168
1237
  //#endregion
1169
1238
  //#region src/responses-agent-language-model/responses-agent-language-model.ts
1170
1239
  function mapResponsesFinishReason({ finishReason, hasToolCalls }) {
@@ -1189,7 +1258,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1189
1258
  }
1190
1259
  supportedUrls = {};
1191
1260
  async doGenerate(options) {
1192
- const networkArgs = await this.getArgs({
1261
+ const { warnings,...networkArgs } = await this.getArgs({
1193
1262
  config: this.config,
1194
1263
  options,
1195
1264
  stream: false,
@@ -1217,11 +1286,11 @@ var DatabricksResponsesAgentLanguageModel = class {
1217
1286
  outputTokens: response.usage?.output_tokens ?? 0,
1218
1287
  totalTokens: response.usage?.total_tokens ?? 0
1219
1288
  },
1220
- warnings: []
1289
+ warnings
1221
1290
  };
1222
1291
  }
1223
1292
  async doStream(options) {
1224
- const networkArgs = await this.getArgs({
1293
+ const { warnings,...networkArgs } = await this.getArgs({
1225
1294
  config: this.config,
1226
1295
  options,
1227
1296
  stream: true,
@@ -1249,7 +1318,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1249
1318
  start(controller) {
1250
1319
  controller.enqueue({
1251
1320
  type: "stream-start",
1252
- warnings: []
1321
+ warnings
1253
1322
  });
1254
1323
  },
1255
1324
  transform(chunk, controller) {
@@ -1324,6 +1393,7 @@ var DatabricksResponsesAgentLanguageModel = class {
1324
1393
  tools: options.tools,
1325
1394
  toolChoice: options.toolChoice
1326
1395
  });
1396
+ const { args: callArgs, warnings } = callOptionsToResponsesArgs(options);
1327
1397
  return {
1328
1398
  url: config.url({ path: "/responses" }),
1329
1399
  headers: combineHeaders(config.headers(), options.headers),
@@ -1332,8 +1402,10 @@ var DatabricksResponsesAgentLanguageModel = class {
1332
1402
  input,
1333
1403
  stream,
1334
1404
  ...tools ? { tools } : {},
1335
- ...toolChoice && tools ? { tool_choice: toolChoice } : {}
1405
+ ...toolChoice && tools ? { tool_choice: toolChoice } : {},
1406
+ ...callArgs
1336
1407
  },
1408
+ warnings,
1337
1409
  fetch: config.fetch
1338
1410
  };
1339
1411
  }
@@ -1742,6 +1814,69 @@ function mapFmapiFinishReason(finishReason) {
1742
1814
  }
1743
1815
  }
1744
1816
 
1817
+ //#endregion
1818
+ //#region src/fmapi-language-model/call-options-to-fmapi-args.ts
1819
+ /**
1820
+ * Converts AI SDK LanguageModelV2CallOptions to Databricks FMAPI body parameters.
1821
+ *
1822
+ * Inspired by the getArgs method in:
1823
+ * https://github.com/vercel/ai/blob/main/packages/openai/src/chat/openai-chat-language-model.ts#L71
1824
+ *
1825
+ * Complies with the API described in:
1826
+ * https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/api-reference#chat-request
1827
+ */
1828
+ function callOptionsToFmapiArgs(options) {
1829
+ const warnings = [];
1830
+ const databricksOptions = options.providerOptions?.databricks;
1831
+ if (options.presencePenalty != null) warnings.push({
1832
+ type: "unsupported-setting",
1833
+ setting: "presencePenalty",
1834
+ details: "presencePenalty is not supported by the Databricks FMAPI"
1835
+ });
1836
+ if (options.frequencyPenalty != null) warnings.push({
1837
+ type: "unsupported-setting",
1838
+ setting: "frequencyPenalty",
1839
+ details: "frequencyPenalty is not supported by the Databricks FMAPI"
1840
+ });
1841
+ if (options.seed != null) warnings.push({
1842
+ type: "unsupported-setting",
1843
+ setting: "seed",
1844
+ details: "seed is not supported by the Databricks FMAPI"
1845
+ });
1846
+ const args = {};
1847
+ if (options.maxOutputTokens != null) args.max_tokens = options.maxOutputTokens;
1848
+ if (options.temperature != null) args.temperature = options.temperature;
1849
+ if (options.topP != null) args.top_p = options.topP;
1850
+ if (options.topK != null) args.top_k = options.topK;
1851
+ if (options.stopSequences != null && options.stopSequences.length > 0) args.stop = options.stopSequences;
1852
+ if (options.responseFormat != null) switch (options.responseFormat.type) {
1853
+ case "text":
1854
+ args.response_format = { type: "text" };
1855
+ break;
1856
+ case "json":
1857
+ if (options.responseFormat.schema != null) args.response_format = {
1858
+ type: "json_schema",
1859
+ json_schema: {
1860
+ name: options.responseFormat.name ?? "response",
1861
+ description: options.responseFormat.description,
1862
+ schema: options.responseFormat.schema,
1863
+ strict: true
1864
+ }
1865
+ };
1866
+ else args.response_format = { type: "json_object" };
1867
+ break;
1868
+ }
1869
+ if (databricksOptions?.topK != null) args.top_k = databricksOptions.topK;
1870
+ if (databricksOptions?.n != null) args.n = databricksOptions.n;
1871
+ if (databricksOptions?.logprobs != null) args.logprobs = databricksOptions.logprobs;
1872
+ if (databricksOptions?.topLogprobs != null) args.top_logprobs = databricksOptions.topLogprobs;
1873
+ if (databricksOptions?.reasoningEffort != null) args.reasoning_effort = databricksOptions.reasoningEffort;
1874
+ return {
1875
+ args,
1876
+ warnings
1877
+ };
1878
+ }
1879
+
1745
1880
  //#endregion
1746
1881
  //#region src/fmapi-language-model/fmapi-language-model.ts
1747
1882
  var DatabricksFmapiLanguageModel = class {
@@ -1757,7 +1892,7 @@ var DatabricksFmapiLanguageModel = class {
1757
1892
  }
1758
1893
  supportedUrls = {};
1759
1894
  async doGenerate(options) {
1760
- const networkArgs = await this.getArgs({
1895
+ const { warnings,...networkArgs } = await this.getArgs({
1761
1896
  config: this.config,
1762
1897
  options,
1763
1898
  stream: false,
@@ -1782,11 +1917,11 @@ var DatabricksFmapiLanguageModel = class {
1782
1917
  outputTokens: response.usage?.completion_tokens ?? 0,
1783
1918
  totalTokens: response.usage?.total_tokens ?? 0
1784
1919
  },
1785
- warnings: []
1920
+ warnings
1786
1921
  };
1787
1922
  }
1788
1923
  async doStream(options) {
1789
- const networkArgs = await this.getArgs({
1924
+ const { warnings,...networkArgs } = await this.getArgs({
1790
1925
  config: this.config,
1791
1926
  options,
1792
1927
  stream: true,
@@ -1816,7 +1951,7 @@ var DatabricksFmapiLanguageModel = class {
1816
1951
  start(controller) {
1817
1952
  controller.enqueue({
1818
1953
  type: "stream-start",
1819
- warnings: []
1954
+ warnings
1820
1955
  });
1821
1956
  },
1822
1957
  transform(chunk, controller) {
@@ -1883,6 +2018,7 @@ var DatabricksFmapiLanguageModel = class {
1883
2018
  const tools = options.tools?.map((tool) => convertToolToOpenAIFormat(tool)).filter((tool) => tool !== void 0);
1884
2019
  const toolChoice = options.toolChoice ? convertToolChoiceToOpenAIFormat(options.toolChoice) : void 0;
1885
2020
  const { messages } = await convertPromptToFmapiMessages(options.prompt);
2021
+ const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
1886
2022
  return {
1887
2023
  url: config.url({ path: "/chat/completions" }),
1888
2024
  headers: combineHeaders(config.headers(), options.headers),
@@ -1892,10 +2028,9 @@ var DatabricksFmapiLanguageModel = class {
1892
2028
  model: modelId,
1893
2029
  ...tools && tools.length > 0 ? { tools } : {},
1894
2030
  ...toolChoice && tools && tools.length > 0 ? { tool_choice: toolChoice } : {},
1895
- ...options.temperature !== void 0 ? { temperature: options.temperature } : {},
1896
- ...options.maxOutputTokens !== void 0 ? { max_tokens: options.maxOutputTokens } : {},
1897
- ...options.stopSequences && options.stopSequences.length > 0 ? { stop: options.stopSequences } : {}
2031
+ ...callArgs
1898
2032
  },
2033
+ warnings,
1899
2034
  fetch: config.fetch
1900
2035
  };
1901
2036
  }