n8n-nodes-gigachat
Version:
A user-friendly GigaChat AI (Sber) nodes for n8n
160 lines • 6.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LmGigaChat = void 0;
const GigaChatApiClient_1 = require("../../shared/GigaChatApiClient");
const GigaChatLcClient_1 = require("../../shared/GigaChatLcClient");
class LmGigaChat {
constructor() {
this.description = {
displayName: 'GigaChat',
name: 'lmGigaChat',
icon: 'file:gigachat.svg',
group: ['transform'],
version: 1,
description: 'Language Models from Sberbank of Russia',
defaults: {
name: 'GigaChat Model',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Language Models', 'Root Nodes'],
'Language Models': ['Text Completion Models'],
},
},
inputs: [],
outputs: ["ai_languageModel"],
outputNames: ['Model'],
credentials: [
{
name: 'gigaChatApi',
required: true,
},
],
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: 'https://gigachat.devices.sberbank.ru/api/v1',
skipSslCertificateValidation: true,
headers: {
Authorization: 'Bearer {{$execution.token}}',
},
},
properties: [
{
displayName: 'Model Name or ID',
name: 'model',
type: 'options',
description: 'The name of the model to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
default: '',
typeOptions: {
loadOptionsMethod: 'getGigaChatModels',
},
routing: {
send: {
type: 'body',
property: 'model',
},
},
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
description: 'Additional options for the model',
type: 'collection',
default: {},
options: [
{
displayName: 'Max Tokens',
name: 'maxTokens',
type: 'number',
default: 1000,
typeOptions: {
minValue: 1,
},
routing: {
send: {
type: 'body',
property: 'max_tokens',
},
},
},
{
displayName: 'Temperature',
name: 'temperature',
type: 'number',
default: 0.8,
typeOptions: {
minValue: 0,
maxValue: 3,
},
routing: {
send: {
type: 'body',
property: 'temperature',
},
},
},
{
displayName: 'Top P',
name: 'topP',
type: 'number',
default: 1,
typeOptions: {
minValue: 0,
maxValue: 1,
},
routing: {
send: {
type: 'body',
property: 'top_p',
},
},
},
{
displayName: 'Repetition Penalty',
name: 'repetitionPenalty',
type: 'number',
default: 1,
routing: {
send: {
type: 'body',
property: 'repetition_penalty',
},
},
},
],
},
],
};
this.methods = {
loadOptions: {
async getGigaChatModels() {
const credentials = await this.getCredentials('gigaChatApi');
await GigaChatApiClient_1.GigaChatApiClient.updateConfig({
credentials: credentials.authorizationKey,
});
const response = await GigaChatApiClient_1.GigaChatApiClient.getModels();
return response.data.map((model) => ({
name: model.id,
value: model.id,
}));
},
},
};
}
async supplyData(itemIndex) {
const credentials = await this.getCredentials('gigaChatApi');
const modelName = this.getNodeParameter('model', itemIndex);
await GigaChatLcClient_1.GigaChatLcClient.updateConfig({
credentials: credentials.authorizationKey,
model: modelName,
scope: credentials.scope,
});
return {
response: GigaChatLcClient_1.GigaChatLcClient,
};
}
}
exports.LmGigaChat = LmGigaChat;
//# sourceMappingURL=LmGigaChat.node.js.map