@n8n/n8n-nodes-langchain
Version:

87 lines • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.baseAnalyze = baseAnalyze;
const utils_1 = require("./utils");
const transport_1 = require("../transport");
async function baseAnalyze(i, urlsPropertyName, type) {
const model = this.getNodeParameter('modelId', i, '', { extractValue: true });
const inputType = this.getNodeParameter('inputType', i, 'url');
const text = this.getNodeParameter('text', i, '');
const simplify = this.getNodeParameter('simplify', i, true);
const options = this.getNodeParameter('options', i, {});
const baseUrl = await utils_1.getBaseUrl.call(this);
const fileUrlPrefix = `${baseUrl}/v1/files/`;
let content;
if (inputType === 'url') {
const urls = this.getNodeParameter(urlsPropertyName, i, '');
content = (0, utils_1.splitByComma)(urls).map((url) => {
if (url.startsWith(fileUrlPrefix)) {
return {
type,
source: {
type: 'file',
file_id: url.replace(fileUrlPrefix, ''),
},
};
}
else {
return {
type,
source: {
type: 'url',
url,
},
};
}
});
}
else {
const binaryPropertyNames = this.getNodeParameter('binaryPropertyName', i, 'data');
const promises = (0, utils_1.splitByComma)(binaryPropertyNames).map(async (binaryPropertyName) => {
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const fileBase64 = buffer.toString('base64');
return {
type,
source: {
type: 'base64',
media_type: binaryData.mimeType,
data: fileBase64,
},
};
});
content = await Promise.all(promises);
}
content.push({
type: 'text',
text,
});
const body = {
model,
max_tokens: options.maxTokens ?? 1024,
messages: [
{
role: 'user',
content,
},
],
};
const response = (await transport_1.apiRequest.call(this, 'POST', '/v1/messages', {
body,
}));
if (simplify) {
return [
{
json: { content: response.content },
pairedItem: { item: i },
},
];
}
return [
{
json: { ...response },
pairedItem: { item: i },
},
];
}
//# sourceMappingURL=baseAnalyze.js.map