@n8n/n8n-nodes-langchain
Version:
36 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resourcePath = resourcePath;
exports.modelPath = modelPath;
exports.fileSearchStorePath = fileSearchStorePath;
exports.apiRequest = apiRequest;
const n8n_workflow_1 = require("n8n-workflow");
function resourcePath(name) {
return name.split('/').reduce((path, segment) => (0, n8n_workflow_1.requestPath) `${path}/${segment}`, (0, n8n_workflow_1.requestPath) ``);
}
function namedResourcePath(name, collections) {
const [collection, id, ...rest] = name.split('/');
if (!collections.includes(collection) || !id || rest.length > 0) {
const formats = collections.map((c) => `"${c}/<ID>"`).join(' or ');
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid resource name "${name}"`, {
description: `Use the format ${formats}`,
});
}
return (0, n8n_workflow_1.requestPath) `/${collection}/${id}`;
}
function modelPath(model) {
return namedResourcePath.call(this, model, ['models', 'tunedModels']);
}
function fileSearchStorePath(name) {
return namedResourcePath.call(this, name, ['fileSearchStores']);
}
async function apiRequest(method, endpoint, parameters) {
const { body, qs, headers, returnFullResponse, allowedDomains } = parameters ?? {};
const credentials = await this.getCredentials('googlePalmApi');
const host = credentials.host || 'https://generativelanguage.googleapis.com';
const options = { headers, method, body, qs, json: true, returnFullResponse, allowedDomains };
return await this.helpers.httpRequestWithAuthentication.call(this, 'googlePalmApi', 'url' in endpoint
? { ...options, url: endpoint.url }
: { ...options, url: (0, n8n_workflow_1.requestUrl) `${host}${endpoint}` });
}
//# sourceMappingURL=index.js.map