UNPKG

@n8n/n8n-nodes-langchain

Version:

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

121 lines 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = void 0; exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const transport_1 = require("../../../transport"); const descriptions_1 = require("../descriptions"); const properties = [ { displayName: 'Model', name: 'model', type: 'options', default: 'dall-e-3', description: 'The model to use for image generation', options: [ { name: 'DALL·E 2', value: 'dall-e-2', }, { name: 'DALL·E 3', value: 'dall-e-3', }, { name: 'GPT Image 1', value: 'gpt-image-1', }, ], displayOptions: { show: { '@version': [{ _cnd: { lt: 2.2 } }], }, }, }, { ...(0, descriptions_1.modelRLC)('imageGenerateModelSearch'), default: { mode: 'list', value: 'gpt-image-1-mini' }, displayOptions: { show: { '@version': [{ _cnd: { gte: 2.2 } }], }, }, }, { displayName: 'Prompt', name: 'prompt', type: 'string', placeholder: 'e.g. A cute cat eating a dinosaur', description: 'A text description of the desired image(s). The maximum length is 1000 characters for dall-e-2 and 4000 characters for dall-e-3.', default: '', typeOptions: { rows: 2, }, }, descriptions_1.imageGenerateOptions, descriptions_1.imageGenerateOptionsRLC, ]; const displayOptions = { show: { operation: ['generate'], resource: ['image'], }, }; exports.description = (0, n8n_workflow_1.updateDisplayOptions)(displayOptions, properties); async function execute(i) { const nodeVersion = this.getNode().typeVersion; let model = ''; if (nodeVersion >= 2.2) { model = this.getNodeParameter('modelId', i, '', { extractValue: true }); } else { model = this.getNodeParameter('model', i); } const prompt = this.getNodeParameter('prompt', i); const options = this.getNodeParameter('options', i, {}); const supportsResponseFormat = !model.startsWith('gpt-image'); let response_format = 'b64_json'; let binaryPropertyOutput = 'data'; if (options.returnImageUrls && supportsResponseFormat) { response_format = 'url'; } if (options.binaryPropertyOutput) { binaryPropertyOutput = options.binaryPropertyOutput; delete options.binaryPropertyOutput; } if (options.dalleQuality) { options.quality = options.dalleQuality; delete options.dalleQuality; } delete options.returnImageUrls; const body = { prompt, model, response_format: supportsResponseFormat ? response_format : undefined, ...options, }; const { data } = await transport_1.apiRequest.call(this, 'POST', '/images/generations', { body }); if (response_format === 'url') { return (data || []).map((entry) => ({ json: entry, pairedItem: { item: i }, })); } else { const returnData = []; for (const entry of data) { const binaryData = await this.helpers.prepareBinaryData(Buffer.from(entry.b64_json, 'base64'), 'data'); returnData.push({ json: Object.assign({}, binaryData, { data: undefined, }), binary: { [binaryPropertyOutput]: binaryData, }, pairedItem: { item: i }, }); } return returnData; } } //# sourceMappingURL=generate.operation.js.map