@n8n/n8n-nodes-langchain
Version:

86 lines • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LmChatLemonade = void 0;
const openai_1 = require("@langchain/openai");
const ai_utilities_1 = require("@n8n/ai-utilities");
const n8n_workflow_1 = require("n8n-workflow");
const description_1 = require("../LMLemonade/description");
class LmChatLemonade {
constructor() {
this.description = {
displayName: 'Lemonade Chat Model',
name: 'lmChatLemonade',
icon: 'file:lemonade.svg',
group: ['transform'],
version: 1,
description: 'Language Model Lemonade Chat',
defaults: {
name: 'Lemonade Chat Model',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Language Models', 'Root Nodes'],
'Language Models': ['Chat Models (Recommended)'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatlemonade/',
},
],
},
},
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, {});
const processedOptions = {
...options,
maxTokens: options.maxTokens && options.maxTokens > 0 ? options.maxTokens : undefined,
stop: undefined,
};
if (options.stop) {
const stopSequences = options.stop
.split(',')
.map((s) => s.trim())
.filter((s) => s.length > 0);
processedOptions.stop = stopSequences.length > 0 ? stopSequences : undefined;
}
const configuration = {
baseURL: credentials.baseUrl,
};
if (credentials.apiKey) {
configuration.defaultHeaders = {
Authorization: `Bearer ${credentials.apiKey}`,
};
}
configuration.fetchOptions = {
dispatcher: (0, ai_utilities_1.getProxyAgent)(configuration.baseURL ?? '', {}),
};
const model = new openai_1.ChatOpenAI({
apiKey: credentials.apiKey || 'lemonade-placeholder-key',
model: modelName,
...processedOptions,
configuration,
callbacks: [new ai_utilities_1.N8nLlmTracing(this)],
onFailedAttempt: (0, ai_utilities_1.makeN8nLlmFailedAttemptHandler)(this),
});
return {
response: model,
};
}
}
exports.LmChatLemonade = LmChatLemonade;
//# sourceMappingURL=LmChatLemonade.node.js.map