UNPKG

n8n-nodes-gemini-search

Version:

n8n nodes to interact with Google Gemini API for search and content generation

39 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.geminiRequest = void 0; const n8n_workflow_1 = require("n8n-workflow"); async function geminiRequest(model, body) { var _a, _b; const credentials = await this.getCredentials('geminiSearchApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials provided!'); } const apiKey = credentials.apiKey; const options = { method: 'POST', uri: `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`, qs: { key: apiKey, }, headers: { 'Content-Type': 'application/json', }, body, json: true, }; try { if (!this.helpers) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Helpers are not available!'); } const response = await ((_b = (_a = this.helpers).request) === null || _b === void 0 ? void 0 : _b.call(_a, options)); if (!response) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No response from API request'); } return response; } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } exports.geminiRequest = geminiRequest; //# sourceMappingURL=GenericFunctions.js.map