UNPKG

@jpaulo789b/gemini-review-code-br

Version:
133 lines 5.56 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gemini = void 0; const axios_1 = __importDefault(require("axios")); const utils_1 = require("./utils"); const SAFETY_SETTINGS = [ { category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', threshold: 'BLOCK_NONE', }, { category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_NONE', }, { category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_NONE', }, { category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_NONE', }, ]; class Gemini { constructor(apiUrl, accessToken, customModel) { this.apiUrl = apiUrl; this.accessToken = accessToken; this.customModel = customModel; this.apiClient = axios_1.default.create({ baseURL: apiUrl, }); } reviewCodeChange(change) { return __awaiter(this, void 0, void 0, function* () { const apiKey = this.accessToken; const geminiAPIURL = this.apiUrl; const model = this.customModel || utils_1.geminiCompletionsConfig.model; const url = `${geminiAPIURL}/v1beta/models/${model}:generateContent?key=${apiKey}`; // change to generateContent const headers = { 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41', }; const body = { contents: [ { role: 'user', parts: [ { text: change } ] } ], systemInstruction: { parts: [ { text: utils_1.geminiSystemContent }, { text: utils_1.geminiSuggestContent } ] }, safetySettings: SAFETY_SETTINGS, }; const response = yield this.apiClient.post(url, body, { headers: headers, }); if (response.status < 200 || response.status >= 300) { throw new Error('Request failed'); } const data = response.data; return data.candidates[0].content.parts[0].text; }); } reviewPlatformChange(change) { return __awaiter(this, void 0, void 0, function* () { const apiKey = this.accessToken; const geminiAPIURL = this.apiUrl; const model = this.customModel || utils_1.geminiCompletionsConfig.model; const url = `${geminiAPIURL}/v1beta/models/${model}:generateContent?key=${apiKey}`; const headers = { 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41', }; const body = { contents: [ { role: 'user', parts: [ { text: change } ] } ], systemInstruction: { parts: [ { text: "Você é um revisor técnico sênior especializado em configurações de plataforma móvel (Android/iOS/Flutter). Analise arquivos de configuração identificando APENAS problemas que podem quebrar o build ou causar falhas críticas em produção. Seja extremamente seletivo e foque apenas em problemas que realmente impedem a compilação ou causam crashes." }, { text: (0, utils_1.getPlatformPrompt)() } ] }, safetySettings: SAFETY_SETTINGS, }; const response = yield this.apiClient.post(url, body, { headers: headers, }); if (response.status < 200 || response.status >= 300) { throw new Error('Request failed'); } const data = response.data; return data.candidates[0].content.parts[0].text; }); } } exports.Gemini = Gemini; //# sourceMappingURL=gemini.js.map