n8n-nodes-databricks-api
Version:
Databricks node for n8n
184 lines • 7.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LmChatDatabricks = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const openai_1 = require("@langchain/openai");
class LmChatDatabricks {
constructor() {
this.description = {
displayName: 'Databricks Chat Model',
name: 'lmChatDatabricks',
icon: 'file:databricks.svg',
group: ['transform'],
version: 1,
description: 'Use Databricks hosted LLM models',
defaults: {
name: 'Databricks Chat Model',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Language Models', 'Root Nodes'],
'Language Models': ['Chat Models (Recommended)'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.databricks.com/machine-learning/model-serving/index.html',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiLanguageModel],
outputNames: ['Model'],
credentials: [
{
name: 'databricks',
required: true,
},
],
requestDefaults: {
baseURL: '={{$credentials.host}}',
headers: {
Authorization: '=Bearer {{$credentials.token}}',
},
},
properties: [
{
displayName: 'Model',
name: 'model',
type: 'options',
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '/api/2.0/serving-endpoints',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'endpoints',
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.name}}',
value: '={{$responseItem.name}}',
description: '={{$responseItem.config.served_models[0].name}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
},
required: true,
default: '',
description: 'The model to use',
routing: {
send: {
type: 'body',
property: 'model',
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Maximum Tokens',
name: 'max_tokens',
type: 'number',
typeOptions: {
maxValue: 32768,
},
default: 512,
routing: {
send: {
type: 'body',
property: 'max_tokens',
},
},
},
{
displayName: 'Temperature',
name: 'temperature',
type: 'number',
typeOptions: {
maxValue: 2,
minValue: 0,
numberPrecision: 1,
},
default: 0.7,
routing: {
send: {
type: 'body',
property: 'temperature',
},
},
},
{
displayName: 'Top P',
name: 'top_p',
type: 'number',
typeOptions: {
maxValue: 1,
minValue: 0,
numberPrecision: 1,
},
default: 1,
routing: {
send: {
type: 'body',
property: 'top_p',
},
},
},
],
},
],
};
}
async supplyData(itemIndex) {
var _a, _b;
const credentials = await this.getCredentials('databricks');
const modelName = this.getNodeParameter('model', itemIndex);
const options = this.getNodeParameter('options', itemIndex, {});
const configuration = {
baseURL: `${credentials.host}/serving-endpoints`,
};
const model = new openai_1.ChatOpenAI({
openAIApiKey: `${credentials.token}`,
modelName,
...options,
timeout: (_a = options.timeout) !== null && _a !== void 0 ? _a : 60000,
maxRetries: (_b = options.maxRetries) !== null && _b !== void 0 ? _b : 2,
configuration,
modelKwargs: options.responseFormat
? {
response_format: { type: options.responseFormat },
}
: undefined,
});
return {
response: model,
};
}
}
exports.LmChatDatabricks = LmChatDatabricks;
//# sourceMappingURL=LmChatDatabricks.node.js.map