UNPKG

@gluneau/n8n-nodes-venice

Version:

Venice.ai integration for n8n

222 lines 8.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VeniceEmbeddings = void 0; const n8n_workflow_1 = require("n8n-workflow"); class VeniceEmbeddings { description = { displayName: 'Venice Embeddings (Beta)', name: 'veniceEmbeddings', icon: 'file:veniceEmbeddings.svg', group: ['transform'], version: 1, description: 'Generate vector embeddings from text with Venice.ai (Beta feature, limited access)', defaults: { name: 'Venice Embeddings', }, codex: { categories: ['AI'], subcategories: { AI: ['Embeddings'], }, }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'veniceApi', required: true, }, ], subtitle: 'Venice', requestDefaults: { baseURL: 'https://api.venice.ai/api/v1', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }, properties: [ { displayName: 'BETA FEATURE - Limited Access', name: 'betaNotice', type: 'notice', default: 'The Venice Embeddings API is currently in BETA and only available to Venice beta testers. If you encounter authentication errors, you need to contact Venice to request beta access.', description: 'This feature requires special beta access permissions', }, { displayName: 'Input Type', name: 'inputType', type: 'options', options: [ { name: 'Single Text', value: 'string', description: 'Process a single text string', }, { name: 'Multiple Texts', value: 'array', description: 'Process multiple text strings as an array', }, ], default: 'string', description: 'How to process the input', }, { displayName: 'Text', name: 'input', type: 'string', typeOptions: { rows: 4, }, default: '', description: 'The text to generate embeddings for', required: true, displayOptions: { show: { inputType: ['string'], }, }, }, { displayName: 'Texts', name: 'inputs', type: 'string', typeOptions: { rows: 4, }, default: '', placeholder: '["text1", "text2", "text3"]', description: 'JSON array of texts to generate embeddings for', required: true, displayOptions: { show: { inputType: ['array'], }, }, }, { displayName: 'Model', name: 'model', type: 'options', options: [ { name: 'BGE-M3', value: 'text-embedding-bge-m3', }, ], default: 'text-embedding-bge-m3', description: 'The model to use for generating embeddings', }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add Option', default: {}, options: [ { displayName: 'Dimensions', name: 'dimensions', type: 'number', default: 1024, description: 'The number of dimensions for the output embeddings', }, { displayName: 'Encoding Format', name: 'encoding_format', type: 'options', options: [ { name: 'Float', value: 'float', description: 'Return embeddings as floating point numbers', }, { name: 'Base64', value: 'base64', description: 'Return embeddings as base64-encoded strings', }, ], default: 'float', description: 'The format to return the embeddings in', }, ], }, ], }; async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const inputType = this.getNodeParameter('inputType', i); const model = this.getNodeParameter('model', i); const options = this.getNodeParameter('options', i, {}); let input; if (inputType === 'string') { input = this.getNodeParameter('input', i); } else { const inputsJson = this.getNodeParameter('inputs', i); try { input = JSON.parse(inputsJson); if (!Array.isArray(input)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Input must be a valid JSON array of strings', { itemIndex: i, }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to parse inputs as JSON array: ${error.message}`, { itemIndex: i, }); } } const body = { model, input, }; if (options.dimensions !== undefined) body.dimensions = options.dimensions; if (options.encoding_format !== undefined) body.encoding_format = options.encoding_format; const response = await this.helpers.httpRequestWithAuthentication.call(this, 'veniceApi', { method: 'POST', url: '/embeddings', body, json: true, }); const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (error.message.includes('401') || error.message.toLowerCase().includes('unauthorized') || (error.response && error.response.status === 401)) { const betaAccessError = new n8n_workflow_1.NodeOperationError(this.getNode(), 'Venice Embeddings is a BETA feature and requires special access. Please contact Venice to request beta access for embeddings.', { itemIndex: i }); if (this.continueOnFail()) { returnData.push({ json: { error: betaAccessError.message, details: 'You need beta tester access to use embeddings.', statusCode: 401, isBetaFeature: true, }, }); continue; } throw betaAccessError; } if (this.continueOnFail()) { returnData.push({ json: { error: error.message } }); continue; } throw error; } } return [returnData]; } } exports.VeniceEmbeddings = VeniceEmbeddings; //# sourceMappingURL=VeniceEmbeddings.node.js.map