@databricks/ai-sdk-provider 0.2.1 → 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 +166 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +166 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -521,7 +521,7 @@ const responsesAgentResponseSchema = z.object({
|
|
|
521
521
|
}).nullish(),
|
|
522
522
|
model: z.string().optional(),
|
|
523
523
|
output: z.array(responsesAgentOutputItem),
|
|
524
|
-
incomplete_details: z.object({ reason: z.
|
|
524
|
+
incomplete_details: z.object({ reason: z.string().nullish().optional() }).nullish(),
|
|
525
525
|
usage: z.object({
|
|
526
526
|
input_tokens: z.number(),
|
|
527
527
|
output_tokens: z.number(),
|
|
@@ -591,7 +591,7 @@ const responsesCompletedSchema = z.object({
|
|
|
591
591
|
"queued",
|
|
592
592
|
"incomplete"
|
|
593
593
|
]).optional(),
|
|
594
|
-
incomplete_details: z.object({ reason: z.
|
|
594
|
+
incomplete_details: z.object({ reason: z.string().nullish().optional() }).nullish(),
|
|
595
595
|
usage: z.object({
|
|
596
596
|
input_tokens: z.number(),
|
|
597
597
|
output_tokens: z.number(),
|
|
@@ -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
|
}
|
|
@@ -1455,11 +1527,7 @@ const fmapiChunkSchema = z.object({
|
|
|
1455
1527
|
]).optional(),
|
|
1456
1528
|
tool_calls: z.array(toolCallDeltaSchema).optional()
|
|
1457
1529
|
}),
|
|
1458
|
-
finish_reason: z.union([
|
|
1459
|
-
z.literal("stop"),
|
|
1460
|
-
z.literal("tool_calls"),
|
|
1461
|
-
z.null()
|
|
1462
|
-
]).optional()
|
|
1530
|
+
finish_reason: z.union([z.string(), z.null()]).optional()
|
|
1463
1531
|
}))
|
|
1464
1532
|
});
|
|
1465
1533
|
const fmapiResponseSchema = z.object({
|
|
@@ -1485,11 +1553,7 @@ const fmapiResponseSchema = z.object({
|
|
|
1485
1553
|
]).optional(),
|
|
1486
1554
|
tool_calls: z.array(toolCallSchema).optional()
|
|
1487
1555
|
}),
|
|
1488
|
-
finish_reason: z.union([
|
|
1489
|
-
z.literal("stop"),
|
|
1490
|
-
z.literal("tool_calls"),
|
|
1491
|
-
z.null()
|
|
1492
|
-
]).optional()
|
|
1556
|
+
finish_reason: z.union([z.string(), z.null()]).optional()
|
|
1493
1557
|
}))
|
|
1494
1558
|
});
|
|
1495
1559
|
|
|
@@ -1737,6 +1801,82 @@ const getToolNameFromPart = async (part) => {
|
|
|
1737
1801
|
return providerOptions?.toolName ?? part.toolName;
|
|
1738
1802
|
};
|
|
1739
1803
|
|
|
1804
|
+
//#endregion
|
|
1805
|
+
//#region src/fmapi-language-model/fmapi-finish-reason.ts
|
|
1806
|
+
function mapFmapiFinishReason(finishReason) {
|
|
1807
|
+
switch (finishReason) {
|
|
1808
|
+
case "stop": return "stop";
|
|
1809
|
+
case "length": return "length";
|
|
1810
|
+
case "content_filter": return "content-filter";
|
|
1811
|
+
case "function_call":
|
|
1812
|
+
case "tool_calls": return "tool-calls";
|
|
1813
|
+
default: return "other";
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
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
|
+
|
|
1740
1880
|
//#endregion
|
|
1741
1881
|
//#region src/fmapi-language-model/fmapi-language-model.ts
|
|
1742
1882
|
var DatabricksFmapiLanguageModel = class {
|
|
@@ -1752,7 +1892,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1752
1892
|
}
|
|
1753
1893
|
supportedUrls = {};
|
|
1754
1894
|
async doGenerate(options) {
|
|
1755
|
-
const networkArgs = await this.getArgs({
|
|
1895
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1756
1896
|
config: this.config,
|
|
1757
1897
|
options,
|
|
1758
1898
|
stream: false,
|
|
@@ -1768,8 +1908,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1768
1908
|
})
|
|
1769
1909
|
});
|
|
1770
1910
|
const choice = response.choices[0];
|
|
1771
|
-
|
|
1772
|
-
if (choice?.finish_reason === "tool_calls") finishReason = "tool-calls";
|
|
1911
|
+
const finishReason = mapFmapiFinishReason(choice?.finish_reason);
|
|
1773
1912
|
return {
|
|
1774
1913
|
content: convertFmapiResponseToMessagePart(response),
|
|
1775
1914
|
finishReason,
|
|
@@ -1778,11 +1917,11 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1778
1917
|
outputTokens: response.usage?.completion_tokens ?? 0,
|
|
1779
1918
|
totalTokens: response.usage?.total_tokens ?? 0
|
|
1780
1919
|
},
|
|
1781
|
-
warnings
|
|
1920
|
+
warnings
|
|
1782
1921
|
};
|
|
1783
1922
|
}
|
|
1784
1923
|
async doStream(options) {
|
|
1785
|
-
const networkArgs = await this.getArgs({
|
|
1924
|
+
const { warnings,...networkArgs } = await this.getArgs({
|
|
1786
1925
|
config: this.config,
|
|
1787
1926
|
options,
|
|
1788
1927
|
stream: true,
|
|
@@ -1812,7 +1951,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1812
1951
|
start(controller) {
|
|
1813
1952
|
controller.enqueue({
|
|
1814
1953
|
type: "stream-start",
|
|
1815
|
-
warnings
|
|
1954
|
+
warnings
|
|
1816
1955
|
});
|
|
1817
1956
|
},
|
|
1818
1957
|
transform(chunk, controller) {
|
|
@@ -1829,8 +1968,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1829
1968
|
return;
|
|
1830
1969
|
}
|
|
1831
1970
|
const choice = chunk.value.choices[0];
|
|
1832
|
-
|
|
1833
|
-
else if (choice?.finish_reason === "tool_calls") finishReason = "tool-calls";
|
|
1971
|
+
finishReason = mapFmapiFinishReason(choice?.finish_reason);
|
|
1834
1972
|
if (chunk.value.usage) usage = {
|
|
1835
1973
|
inputTokens: chunk.value.usage.prompt_tokens ?? 0,
|
|
1836
1974
|
outputTokens: chunk.value.usage.completion_tokens ?? 0,
|
|
@@ -1880,6 +2018,7 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1880
2018
|
const tools = options.tools?.map((tool) => convertToolToOpenAIFormat(tool)).filter((tool) => tool !== void 0);
|
|
1881
2019
|
const toolChoice = options.toolChoice ? convertToolChoiceToOpenAIFormat(options.toolChoice) : void 0;
|
|
1882
2020
|
const { messages } = await convertPromptToFmapiMessages(options.prompt);
|
|
2021
|
+
const { args: callArgs, warnings } = callOptionsToFmapiArgs(options);
|
|
1883
2022
|
return {
|
|
1884
2023
|
url: config.url({ path: "/chat/completions" }),
|
|
1885
2024
|
headers: combineHeaders(config.headers(), options.headers),
|
|
@@ -1889,10 +2028,9 @@ var DatabricksFmapiLanguageModel = class {
|
|
|
1889
2028
|
model: modelId,
|
|
1890
2029
|
...tools && tools.length > 0 ? { tools } : {},
|
|
1891
2030
|
...toolChoice && tools && tools.length > 0 ? { tool_choice: toolChoice } : {},
|
|
1892
|
-
...
|
|
1893
|
-
...options.maxOutputTokens !== void 0 ? { max_tokens: options.maxOutputTokens } : {},
|
|
1894
|
-
...options.stopSequences && options.stopSequences.length > 0 ? { stop: options.stopSequences } : {}
|
|
2031
|
+
...callArgs
|
|
1895
2032
|
},
|
|
2033
|
+
warnings,
|
|
1896
2034
|
fetch: config.fetch
|
|
1897
2035
|
};
|
|
1898
2036
|
}
|