n8n-nodes-straico-chat
Version:
Adds a Straico Chat Model to use with n8n AI Agents and Chains.
178 lines • 7.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LmChatStraico = void 0;
const StraicoChatModel_1 = require("./StraicoChatModel");
class LmChatStraico {
constructor() {
this.description = {
displayName: 'Straico Chat Model',
name: 'lmChatStraico',
icon: { light: 'file:straico.svg', dark: 'file:straico.svg' },
group: ['transform'],
version: [1],
description: 'Expose Straico chat-completion models for AI chains and the AI-Agent',
defaults: { name: 'Straico Chat Model' },
codex: {
categories: ['AI'],
subcategories: {
AI: ['Language Models', 'Root Nodes'],
'Language Models': ['Chat Models (Recommended)'],
},
resources: {
primaryDocumentation: [
{
url: 'https://github.com/nlp-deutschland-de/n8n-docs/blob/main/docs/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmChatStraico.md',
},
],
},
},
inputs: ['main'],
outputs: ['ai_languageModel'],
outputNames: ['Model'],
credentials: [
{
name: 'straicoApi',
required: true,
},
],
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: '={{ $credentials?.url }}',
},
properties: [
{
displayName: 'Model',
name: 'model',
type: 'options',
required: true,
default: '',
description: 'Choose the Straico model to generate the completion. <a href="https://documenter.getpostman.com/view/5900072/2s9YyzddrR">Learn more</a>.',
typeOptions: {
loadOptions: {
routing: {
request: {
method: 'GET',
url: '/models',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'data',
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.model}}',
value: '={{$responseItem.model}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
},
routing: {
send: { type: 'body', property: 'model' },
},
},
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
options: [
{
displayName: 'Frequency Penalty',
name: 'frequency_penalty',
type: 'number',
default: 0,
typeOptions: { minValue: -2, maxValue: 2 },
description: 'Penalizes tokens based on their frequency in the text',
},
{
displayName: 'Max Retries',
name: 'maxRetries',
type: 'number',
default: 2,
description: 'Maximum number of retries to attempt',
},
{
displayName: 'Max Tokens',
name: 'max_tokens',
type: 'number',
default: 1024,
description: 'Maximum number of tokens to generate',
},
{
displayName: 'Presence Penalty',
name: 'presence_penalty',
type: 'number',
default: 0,
typeOptions: { minValue: -2, maxValue: 2 },
description: 'Penalizes tokens based on their presence in the text',
},
{
displayName: 'Temperature',
name: 'temperature',
type: 'number',
default: 1,
typeOptions: { minValue: 0, maxValue: 2 },
description: 'Controls randomness of the model output',
},
{
displayName: 'Timeout (Ms)',
name: 'timeout',
type: 'number',
default: 60000,
description: 'Maximum amount of time a request is allowed to take in milliseconds',
},
{
displayName: 'Top P',
name: 'top_p',
type: 'number',
default: 1,
typeOptions: { minValue: 0, maxValue: 1 },
description: 'Controls diversity via nucleus sampling',
},
],
},
],
};
}
async supplyData(itemIndex) {
var _a, _b, _c;
const credentials = await this.getCredentials('straicoApi');
const modelName = this.getNodeParameter('model', itemIndex);
console.log('Selected Model Name:', modelName);
const rawOptions = this.getNodeParameter('options', itemIndex, {});
const options = {
temperature: rawOptions.temperature,
topP: rawOptions.top_p,
maxTokens: (_a = rawOptions.max_tokens) !== null && _a !== void 0 ? _a : 1024,
presencePenalty: rawOptions.presence_penalty,
frequencyPenalty: rawOptions.frequency_penalty,
timeout: (_b = rawOptions.timeout) !== null && _b !== void 0 ? _b : 60000,
maxRetries: (_c = rawOptions.maxRetries) !== null && _c !== void 0 ? _c : 2,
};
console.log('Options:', options);
const model = new StraicoChatModel_1.StraicoChatModel({
apiKey: credentials.apiKey,
baseURL: credentials.url || 'https://api.straico.com/v0',
modelName,
...options,
});
return { response: model };
}
}
exports.LmChatStraico = LmChatStraico;
//# sourceMappingURL=LmChatStraico.node.js.map