UNPKG

@n8n/n8n-nodes-langchain

Version:
36 lines • 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.apiRequest = apiRequest; const n8n_workflow_1 = require("n8n-workflow"); async function apiRequest(method, endpoint, parameters) { const { body, qs, option } = parameters ?? {}; const credentials = await this.getCredentials('openAiApi'); const baseUrl = credentials.url || 'https://api.openai.com/v1'; let headers = parameters?.headers ?? {}; if (credentials.header && typeof credentials.headerName === 'string' && credentials.headerName && typeof credentials.headerValue === 'string') { headers = { ...headers, [credentials.headerName]: credentials.headerValue, }; } const options = { headers, method, body, qs, uri: (0, n8n_workflow_1.requestUrl) `${baseUrl}${endpoint}`, json: true, }; if (option && Object.keys(option).length !== 0) { Object.assign(options, option); } const response = await this.helpers.requestWithAuthentication.call(this, 'openAiApi', options); if (response && response.error === null) { response.error = undefined; } return response; } //# sourceMappingURL=index.js.map