@n8n/n8n-nodes-langchain
Version:

85 lines • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LmLemonade = void 0;
const openai_1 = require("@langchain/openai");
const n8n_workflow_1 = require("n8n-workflow");
const description_1 = require("./description");
const ai_utilities_1 = require("@n8n/ai-utilities");
class LmLemonade {
constructor() {
this.description = {
displayName: 'Lemonade Model',
name: 'lmLemonade',
icon: 'file:lemonade.svg',
group: ['transform'],
version: 1,
description: 'Language Model Lemonade',
defaults: {
name: 'Lemonade Model',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Language Models', 'Root Nodes'],
'Language Models': ['Text Completion Models'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmlemonade/',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiLanguageModel],
outputNames: ['Model'],
...description_1.lemonadeDescription,
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiChain, n8n_workflow_1.NodeConnectionTypes.AiAgent]),
description_1.lemonadeModel,
description_1.lemonadeOptions,
],
};
}
async supplyData(itemIndex) {
const credentials = (await this.getCredentials('lemonadeApi'));
const modelName = this.getNodeParameter('model', itemIndex);
const options = this.getNodeParameter('options', itemIndex, {});
let stop;
if (options.stop) {
const stopSequences = options.stop
.split(',')
.map((s) => s.trim())
.filter((s) => s.length > 0);
stop = stopSequences.length > 0 ? stopSequences : undefined;
}
const apiKey = credentials.apiKey || 'lemonade-placeholder-key';
const configuration = {
baseURL: credentials.baseUrl,
};
if (credentials.apiKey) {
configuration.defaultHeaders = {
Authorization: `Bearer ${credentials.apiKey}`,
};
}
const model = new openai_1.OpenAI({
apiKey,
model: modelName,
temperature: options.temperature,
topP: options.topP,
frequencyPenalty: options.frequencyPenalty,
presencePenalty: options.presencePenalty,
maxTokens: options.maxTokens && options.maxTokens > 0 ? options.maxTokens : undefined,
stop,
configuration,
callbacks: [new ai_utilities_1.N8nLlmTracing(this)],
onFailedAttempt: (0, ai_utilities_1.makeN8nLlmFailedAttemptHandler)(this),
});
return {
response: model,
};
}
}
exports.LmLemonade = LmLemonade;
//# sourceMappingURL=LmLemonade.node.js.map