UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI's Generative AI APIs.

298 lines 13.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AskAiChatbot = void 0; const n8n_workflow_1 = require("n8n-workflow"); const auth_1 = require("../utils/auth"); const polling_1 = require("../utils/polling"); class AskAiChatbot { constructor() { this.description = { displayName: 'Wiro - Ask AI Chatbot', name: 'askAiChatbot', icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' }, group: ['transform'], version: 1, description: "Sends a prompt to Wiro AI's chatbot and returns the assistant's response", defaults: { name: 'Wiro - Ask AI Chatbot', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'wiroApi', required: true, }, ], properties: [ { displayName: 'Selected Model', name: 'selectedModel', type: 'options', default: '757', required: true, description: 'Select a LLM - Chat Model', options: [ { name: 'Qwen/Qwen2.5-14B-Instruct', value: '757' }, { name: 'Qwen/Qwen2.5-32B-Instruct', value: '756' }, { name: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-32B', value: '743' }, { name: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-14B', value: '742' }, { name: 'deepseek-ai/DeepSeek-R1-Distill-Llama-8B', value: '741' }, { name: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B', value: '740' }, { name: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B', value: '739' }, { name: 'utter-project/EuroLLM-9B-Instruct', value: '735' }, { name: 'utter-project/EuroLLM-1.7B-Instruct', value: '734' }, { name: 'm42-health/Llama3-Med42-8B', value: '730' }, { name: 'meta-llama/Llama-3.2-3B-Instruct', value: '728' }, { name: 'meta-llama/CodeLlama-34b-Instruct-hf', value: '726' }, { name: 'meta-llama/CodeLlama-7b-Instruct-hf', value: '725' }, { name: 'internlm/internlm3-8b-instruct', value: '720' }, { name: 'CohereForAI/aya-expanse-8b', value: '719' }, { name: 'mistralai/Mistral-Nemo-Instruct-2407', value: '717' }, { name: 'HuggingFaceTB/SmolLM2-1.7B-Instruct', value: '716' }, { name: 'mistralai/Mathstral-7B-v0.1', value: '714' }, { name: 'deepseek-ai/deepseek-math-7b-instruct', value: '713' }, { name: 'microsoft/Phi-3.5-mini-instruct', value: '712' }, { name: 'Qwen/Qwen2.5-3B-Instruct', value: '711' }, { name: 'Qwen/Qwen2.5-0.5B-Instruct', value: '710' }, { name: 'Qwen/Qwen2.5-1.5B-Instruct', value: '709' }, { name: 'Qwen/Qwen2-7B-Instruct', value: '692' }, { name: 'Qwen/Qwen2.5-Math-7B-Instruct', value: '691' }, { name: 'Qwen/Qwen2.5-Math-1.5B-Instruct', value: '690' }, { name: 'Qwen/Qwen2.5-Coder-7B-Instruct', value: '689' }, { name: 'Qwen/Qwen1.5-0.5B-Chat', value: '688' }, { name: 'microsoft/phi-4', value: '686' }, { name: 'Qwen/Qwen2.5-Coder-32B-Instruct', value: '685' }, { name: 'google/gemma-2-2b-it', value: '684' }, { name: 'google/gemma-2-9b-it', value: '683' }, { name: 'meta-llama/Meta-Llama-3-8B-Instruct', value: '682' }, { name: 'mistralai/Mistral-7B-Instruct-v0.3', value: '681' }, { name: 'meta-llama/Llama-3.1-8B-Instruct', value: '680' }, { name: 'Qwen/Qwen2.5-7B-Instruct', value: '679' }, { name: 'wiro/wiroai-turkish-llm-8b', value: '676' }, { name: 'wiro/wiroai-turkish-llm-9b', value: '675' }, { name: 'meta-llama/Llama-2-7b-chat-hf', value: '617' }, ], }, { displayName: 'Prompt', name: 'prompt', type: 'string', default: 'What are some interesting historical events that took place near the Tower of London, and how could they inspire a fictional story?', required: true, description: 'Prompt to send to the chat model', }, { displayName: 'System Prompt', name: 'system_prompt', type: 'string', default: "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.", required: true, description: 'System prompt to guide model behavior', }, { displayName: 'User ID', name: 'user_id', type: 'string', default: '', description: 'Unique identifier to track user history', }, { displayName: 'Session ID', name: 'session_id', type: 'string', default: '', description: 'ID for the current session to maintain history', }, { displayName: 'Temperature', name: 'temperature', type: 'string', default: '0.7', required: true, description: 'Adjusts randomness of outputs', }, { displayName: 'Top P', name: 'top_p', type: 'string', default: '0.95', required: true, description: 'Samples from top p tokens', }, { displayName: 'Top K', name: 'top_k', type: 'string', default: '0', required: true, description: 'Samples from top k tokens', }, { displayName: 'Repetition Penalty', name: 'repetition_penalty', type: 'string', default: '1.0', required: true, description: 'Discourages repeating earlier tokens', }, { displayName: 'Length Penalty', name: 'length_penalty', type: 'string', default: '1', required: true, description: 'Controls output length', }, { displayName: 'Max Tokens', name: 'max_tokens', type: 'string', default: '0', required: true, description: 'Maximum tokens to generate', }, { displayName: 'Min Tokens', name: 'min_tokens', type: 'string', default: '0', required: true, description: 'Minimum tokens to generate', }, { displayName: 'Max New Tokens', name: 'max_new_tokens', type: 'string', default: '0', required: true, description: 'Maximum new tokens to generate', }, { displayName: 'Min New Tokens', name: 'min_new_tokens', type: 'string', default: '-1', required: true, description: 'Minimum new tokens to generate', }, { displayName: 'Stop Sequences', name: 'stop_sequences', type: 'string', default: '', description: 'Semicolon-separated stop sequences', }, { displayName: 'Seed', name: 'seed', type: 'string', default: '12345', required: true, description: 'Random seed for reproducibility', }, { displayName: 'Quantization', name: 'quantization', type: 'string', default: '--quantization', description: 'Whether to use quantized weights', }, { displayName: 'Do Sample', name: 'do_sample', type: 'string', default: '--do_sample', description: 'Whether to enable sampling', }, ], }; } async execute() { const returnData = []; const credentials = await this.getCredentials('wiroApi'); const apiKey = credentials.apiKey; const apiSecret = credentials.apiSecret; const headers = (0, auth_1.generateWiroAuthHeaders)(apiKey, apiSecret); const selectedModel = this.getNodeParameter('selectedModel', 0); const prompt = this.getNodeParameter('prompt', 0); const system_prompt = this.getNodeParameter('system_prompt', 0); const user_id = this.getNodeParameter('user_id', 0, ''); const session_id = this.getNodeParameter('session_id', 0, ''); const temperature = this.getNodeParameter('temperature', 0); const top_p = this.getNodeParameter('top_p', 0); const top_k = this.getNodeParameter('top_k', 0); const repetition_penalty = this.getNodeParameter('repetition_penalty', 0); const length_penalty = this.getNodeParameter('length_penalty', 0); const max_tokens = this.getNodeParameter('max_tokens', 0); const min_tokens = this.getNodeParameter('min_tokens', 0); const max_new_tokens = this.getNodeParameter('max_new_tokens', 0); const min_new_tokens = this.getNodeParameter('min_new_tokens', 0); const stop_sequences = this.getNodeParameter('stop_sequences', 0, ''); const seed = this.getNodeParameter('seed', 0); const quantization = this.getNodeParameter('quantization', 0, ''); const do_sample = this.getNodeParameter('do_sample', 0, ''); const body = { selectedModel, prompt, system_prompt, user_id, session_id, temperature, top_p, top_k, repetition_penalty, length_penalty, max_tokens, min_tokens, max_new_tokens, min_new_tokens, stop_sequences, seed, quantization, do_sample, }; const response = await this.helpers.request({ method: 'POST', url: 'https://api.wiro.ai/v1/Run/wiro/chat', headers: { ...headers, 'Content-Type': 'application/json', }, body, json: true, }); if (!(response === null || response === void 0 ? void 0 : response.taskid) || !(response === null || response === void 0 ? void 0 : response.socketaccesstoken)) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Wiro API did not return a valid task ID or socket access token ' + JSON.stringify(response), }); } const taskid = response.taskid; const socketaccesstoken = response.socketaccesstoken; const result = await polling_1.pollTaskUntilComplete.call(this, socketaccesstoken, headers); const responseJSON = { taskid: taskid, message: '', status: '', }; switch (result) { case '-1': case '-2': case '-3': case '-4': responseJSON.status = 'failed'; break; default: responseJSON.status = 'completed'; responseJSON.message = result !== null && result !== void 0 ? result : ''; } returnData.push({ json: responseJSON, }); return [returnData]; } } exports.AskAiChatbot = AskAiChatbot; //# sourceMappingURL=AskAiChatbot.node.js.map