Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/bilgenurcakir_focusflow.json
T

1 line
4.2 KiB
JSON

{"repo": "bilgenurcakir/focusflow", "files": {"utils/geminiAPI.js": {"a48b0d238b9b03588514441ed6ba98e6d1ac225a": {"t": 1785674560.395648, "n": 3976, "h": "136c14e4792531e4", "c": "// Gemini API service for getting AI feedback on statistics\n\nconst GEMINI_API_KEY = 'AIzaSyBFdGrQWMvCyzN_ZzHy4HXOC2SR1TtQpVQ'; // Replace with your API key\nconst GEMINI_API_URL = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent';\n\nexport const geminiAPI = {\n /**\n * Send statistics to Gemini and get feedback\n * @param {Object} statistics - Statistics object containing various metrics\n * @returns {Promise<string>} - AI feedback text\n */\n async getStatisticsFeedback(statistics) {\n try {\n if (!GEMINI_API_KEY || GEMINI_API_KEY === 'YOUR_GEMINI_API_KEY') {\n return '🎯 Great job on your focus sessions! You\\'re building solid habits. Keep pushing to increase your daily focus time and maintain consistency throughout the week. Try setting specific daily targets and celebrating small wins!';\n }\n\n const prompt = this.buildPrompt(statistics);\n \n // Add API key as query parameter\n const apiUrl = `${GEMINI_API_URL}?key=${GEMINI_API_KEY}`;\n\n const response = await fetch(apiUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n contents: [\n {\n parts: [\n {\n text: prompt,\n },\n ],\n },\n ],\n generationConfig: {\n temperature: 0.7,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: 500,\n },\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json();\n console.error('Gemini API error:', errorData);\n return 'Failed to get feedback from Gemini. Please try again later.';\n }\n\n const data = await response.json();\n\n if (data.candidates && data.candidates[0]?.content?.parts[0]?.text) {\n return data.candidates[0].content.parts[0].text;\n } else {\n return 'No feedback received. Please try again.';\n }\n } catch (error) {\n console.error('Error calling Gemini API:', error);\n return 'Error connecting to Gemini API. Please check your internet connection.';\n }\n },\n\n /**\n * Build a prompt for Gemini based on statistics\n * @param {Object} statistics - Statistics object\n * @returns {string} - Formatted prompt\n */\n buildPrompt(statistics) {\n const prompt = `\nYou are a productivity and focus coach. Analyze the following Pomodoro/Focus session statistics and provide constructive, encouraging feedback and actionable suggestions for improvement.\n\n**User Statistics:**\n- Total Pomodoros: ${statistics.totalPomodoros}\n- Total Focus Time: ${Math.floor(statistics.totalFocusMinutes / 60)} hours ${statistics.totalFocusMinutes % 60} minutes\n- Focus Percentage: ${Math.round(statistics.focusPercentage)}%\n- Longest Streak: ${statistics.longestStreak} days\n- Total Break Time: ${Math.floor(statistics.totalBreakMinutes / 60)} hours ${statistics.totalBreakMinutes % 60} minutes\n- Weekly Focus Time: ${Object.values(statistics.weeklyBreakdown).reduce((a, b) => a + b, 0)} minutes\n\n**Your Task:**\n1. Provide 2-3 sentences of positive feedback about their focus habits\n2. Identify 1-2 areas for improvement based on their statistics\n3. Give 2-3 specific, actionable tips to help them improve their productivity\n4. Keep your response concise and motivating (under 300 words)\n\nFormat your response in a friendly, conversational tone that feels encouraging and not judgmental.\n `.trim();\n\n return prompt;\n },\n\n /**\n * Set the API key (call this with your actual API key)\n * @param {string} apiKey - Your Gemini API key\n */\n setApiKey(apiKey) {\n // Note: In a production app, you'd want to store this securely\n // For now, we'll update it in the module\n if (apiKey && apiKey.length > 0) {\n // Store API key securely using AsyncStorage in production\n console.log('API Key configured');\n }\n },\n};\n"}}}}