UNPKG

n8n-nodes-wxai

Version:

A user-friendly WXAI node for n8n, designed to enhance your workflow with Gemini 2.0 Flash model. Supports chat completions with configurable parameters.

248 lines (247 loc) 7.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.chatFields = exports.chatOperations = void 0; const GenericFunctions_1 = require("./GenericFunctions"); exports.chatOperations = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['chat'], }, }, options: [ { name: 'Complete', value: 'complete', action: 'Create chat completion', description: 'Creates a model response for the given chat conversation', routing: { request: { method: 'POST', url: '/chat/completions', body: { stream: false, }, }, output: { postReceive: [GenericFunctions_1.sendErrorPostReceive], }, }, }, ], default: 'complete', }, ]; const completeOperations = [ { displayName: 'Model', name: 'model', type: 'string', description: 'The model which will generate the completion', displayOptions: { show: { resource: ['chat'], }, }, default: 'gemini-2.0-flash', routing: { send: { type: 'body', property: 'model', }, }, }, // Prompt { displayName: 'Prompt', name: 'prompt', type: 'fixedCollection', typeOptions: { sortable: true, multipleValues: true, }, displayOptions: { show: { resource: ['chat'], }, }, placeholder: 'Add Message', default: {}, options: [ { displayName: 'Messages', name: 'messages', values: [ { displayName: 'Role', name: 'role', type: 'options', options: [ { name: 'Assistant', value: 'assistant', }, { name: 'System', value: 'system', }, { name: 'User', value: 'user', }, ], default: 'user', }, { displayName: 'Content', name: 'content', type: 'string', default: '', }, ], }, ], routing: { send: { type: 'body', property: 'messages', value: '={{ $value.messages }}', }, }, }, ]; const sharedOperations = [ // Simplify { displayName: 'Simplify', name: 'simplifyOutput', type: 'boolean', default: true, displayOptions: { show: { resource: ['chat'], }, }, routing: { output: { postReceive: [ { type: 'set', enabled: '={{$value}}', properties: { value: '={{ { "data": $response.body.choices } }}', }, }, { type: 'rootProperty', enabled: '={{$value}}', properties: { property: 'data', }, }, async function (items) { if (this.getNode().parameters.simplifyOutput === false) { return items; } return items.map((item) => { return { json: { ...item.json, message: item.json.message, }, }; }); }, ], }, }, description: 'Whether to return a simplified version of the response instead of the raw data', }, // Options { displayName: 'Options', name: 'options', placeholder: 'Add Option', description: 'Additional options to add', type: 'collection', default: {}, displayOptions: { show: { resource: ['chat'], }, }, options: [ { displayName: 'Maximum Number of Tokens', name: 'maxTokens', default: 1024, description: 'The maximum number of tokens to generate in the completion', type: 'number', displayOptions: { show: { '/operation': ['complete'], }, }, typeOptions: { maxValue: 8192, }, routing: { send: { type: 'body', property: 'max_tokens', }, }, }, { displayName: 'Sampling Temperature', name: 'temperature', default: 1, typeOptions: { maxValue: 2, minValue: 0, numberPrecision: 1, }, description: 'Controls randomness: Lowering results in less random completions', type: 'number', routing: { send: { type: 'body', property: 'temperature', }, }, }, { displayName: 'Top P', name: 'topP', default: 1, typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1, }, description: 'Controls diversity via nucleus sampling', type: 'number', routing: { send: { type: 'body', property: 'top_p', }, }, }, ], }, ]; exports.chatFields = [ /* -------------------------------------------------------------------------- */ /* chat:complete */ /* -------------------------------------------------------------------------- */ ...completeOperations, /* -------------------------------------------------------------------------- */ /* chat:ALL */ /* -------------------------------------------------------------------------- */ ...sharedOperations, ];