UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

114 lines 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = void 0; exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const utils_1 = require("../../helpers/utils"); const transport_1 = require("../../transport"); const descriptions_1 = require("../descriptions"); const properties = [ descriptions_1.modelRLC, { displayName: 'Text Input', name: 'text', type: 'string', placeholder: "e.g. What's in this image?", default: "What's in this image?", typeOptions: { rows: 2, }, }, { displayName: 'Input Data Field Name(s)', name: 'binaryPropertyName', type: 'string', default: 'data', placeholder: 'e.g. data', hint: 'The name of the input field containing the binary file data to be processed', description: 'Name of the binary field(s) which contains the image(s), separate multiple field names with commas', typeOptions: { binaryDataProperty: true, }, }, { displayName: 'Simplify Output', name: 'simplify', type: 'boolean', default: true, description: 'Whether to return a simplified version of the response instead of the raw data', }, { displayName: 'Options', name: 'options', placeholder: 'Add Option', type: 'collection', default: {}, options: [ { displayName: 'Maximum Number of Tokens', description: 'Fewer tokens will result in shorter, less detailed image description', name: 'maxTokens', type: 'number', default: 1024, typeOptions: { minValue: 1, }, }, ], }, ]; const displayOptions = { show: { operation: ['analyze'], resource: ['image'], }, }; exports.description = (0, n8n_workflow_1.updateDisplayOptions)(displayOptions, properties); async function execute(i) { const model = this.getNodeParameter('modelId', i, '', { extractValue: true }); const text = this.getNodeParameter('text', i, ''); const simplify = this.getNodeParameter('simplify', i, true); const options = this.getNodeParameter('options', i, {}); const content = []; const binaryPropertyNames = this.getNodeParameter('binaryPropertyName', i, 'data'); for (const binaryPropertyName of (0, utils_1.prepareBinaryPropertyList)(binaryPropertyNames)) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName); const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const base64 = buffer.toString('base64'); const dataUrl = `data:${binaryData.mimeType};base64,${base64}`; content.push({ type: 'image_url', image_url: { url: dataUrl } }); } content.push({ type: 'text', text }); const body = { model, max_tokens: options.maxTokens ?? 1024, thinking: { type: 'disabled' }, messages: [ { role: 'user', content, }, ], }; const response = (await transport_1.apiRequest.call(this, 'POST', '/chat/completions', { body, })); if (simplify) { const message = response.choices?.[0]?.message; return [ { json: { content: message?.content ?? '', }, pairedItem: { item: i }, }, ]; } return [ { json: { ...response }, pairedItem: { item: i }, }, ]; } //# sourceMappingURL=analyze.operation.js.map