@n8n/n8n-nodes-langchain
Version:

38 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiRequest = apiRequest;
async function apiRequest(method, endpoint, parameters) {
const { body, qs, option } = parameters ?? {};
const credentials = await this.getCredentials('openAiApi');
let uri = `https://api.openai.com/v1${endpoint}`;
let headers = parameters?.headers ?? {};
if (credentials.url) {
uri = `${credentials?.url}${endpoint}`;
}
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,
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