Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/aijzkhai_final-year-project---fyp3024.json

1 line
32 KiB
JSON

{"repo": "aijzkhai/final-year-project---fyp3024", "files": {"lib/services/ai_service.dart": {"6886fa915a6e2d6c0efe42d33d8aa5aa65120e84": {"t": 1785745923.612389, "n": 15925, "h": "5ffe2dea0dee1eaa", "c": "// services/ai_service.dart\nimport 'dart:convert';\nimport 'package:http/http.dart' as http;\nimport '../models/task_model.dart';\nimport '../models/timer_settings_model.dart';\nimport 'dart:math';\n\nclass AIService {\n // Singleton instance\n static final AIService _instance = AIService._internal();\n factory AIService() => _instance;\n\n // API key for DeepSeek\n static String apiKey = 'sk-01cd5245e677480fa0a1b0f47a02ab67';\n\n // Real API URL\n static const String _baseUrl = 'https://api.deepseek.ai/v1';\n\n // Store conversation history\n final List<Map<String, dynamic>> _conversationHistory = [];\n\n // FocusMate AI branding\n static const String aiName = \"FocusMate AI\";\n static const String aiDescription =\n \"\"\"I'm FocusMate AI, your personal productivity assistant. I can help you manage tasks, recommend optimal pomodoro settings, provide productivity tips, and answer any questions about using the app.\"\"\";\n\n AIService._internal() {\n // Load API key from secure storage\n _loadApiKey();\n\n // Initialize with greeting message\n addAssistantMessage(_getWelcomeMessage());\n }\n\n String _getWelcomeMessage() {\n final currentHour = DateTime.now().hour;\n String greeting;\n\n if (currentHour < 12) {\n greeting = \"Good morning\";\n } else if (currentHour < 17) {\n greeting = \"Good afternoon\";\n } else {\n greeting = \"Good evening\";\n }\n\n return \"$greeting! $aiDescription How can I assist you today?\";\n }\n\n Future<void> _loadApiKey() async {\n // Use Flutter Secure Storage for production\n // For development, you can load from .env file with flutter_dotenv\n // apiKey = await secureStorage.read(key: 'deepseek_api_key');\n }\n\n // Add this method to set the API key\n static void setApiKey(String key) {\n apiKey = key;\n }\n\n // Task categories and their recommended pomodoro settings\n final Map<String, Map<String, int>> _taskRecommendations = {\n 'coding': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 4,\n },\n 'writing': {\n 'pomodoroTime': 30,\n 'shortBreak': 5,\n 'longBreak': 20,\n 'pomodoroCount': 3,\n },\n 'reading': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 3,\n },\n 'studying': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 20,\n 'pomodoroCount': 4,\n },\n 'design': {\n 'pomodoroTime': 30,\n 'shortBreak': 10,\n 'longBreak': 20,\n 'pomodoroCount': 3,\n },\n 'meeting': {\n 'pomodoroTime': 45,\n 'shortBreak': 10,\n 'longBreak': 30,\n 'pomodoroCount': 2,\n },\n 'default': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 4,\n },\n };\n\n // Add user message to conversation history\n void addUserMessage(String message) {\n _conversationHistory.add({\n 'role': 'user',\n 'content': message,\n 'timestamp': DateTime.now().toIso8601String(),\n });\n }\n\n // Add assistant message to conversation history\n void addAssistantMessage(String message) {\n _conversationHistory.add({\n 'role': 'assistant',\n 'content': message,\n 'timestamp': DateTime.now().toIso8601String(),\n });\n }\n\n // Get conversation history\n List<Map<String, dynamic>> getConversationHistory() {\n return _conversationHistory;\n }\n\n // Process user text input and extract task data\n Future<Map<String, dynamic>> processUserInput(String input) async {\n // Add user message to conversation history\n addUserMessage(input);\n\n try {\n // Check if this is a question or conversation rather than a task creation request\n if (_isQuestion(input) || _isConversational(input)) {\n final response = await _generateChatResponse(input);\n addAssistantMessage(response);\n\n return {\n 'success': true,\n 'isChat': true,\n 'response': response,\n };\n }\n\n // Extract task title - use the first line or up to 40 chars\n String title = input.split('\\n').first;\n if (title.length > 40) {\n title = '${title.substring(0, 37)}...';\n }\n\n // Extract or create description\n String description = '';\n if (input.contains('\\n')) {\n description = input.substring(input.indexOf('\\n')).trim();\n }\n\n // Determine task category based on keywords\n String category = _determineTaskCategory(input.toLowerCase());\n\n // Get recommended settings for this task type\n final settings =\n _taskRecommendations[category] ?? _taskRecommendations['default']!;\n\n // Create reasoning based on task and category\n final reasoning = _generateReasoning(category, settings);\n\n // Add assistant response to conversation history with FocusMate AI branding\n addAssistantMessage(\n \"I've analyzed your task and created a recommendation:\\n\\n\"\n \"Task: $title\\n\\n\"\n \"$reasoning\\n\\n\"\n \"Would you like me to create this task with these settings?\");\n\n return {\n 'success': true,\n 'isChat': false,\n 'title': title,\n 'description': description,\n 'category': category,\n 'pomodoroTime': settings['pomodoroTime'],\n 'shortBreak': settings['shortBreak'],\n 'longBreak': settings['longBreak'],\n 'pomodoroCount': settings['pomodoroCount'],\n 'reasoning': reasoning,\n };\n } catch (e) {\n final errorMessage =\n \"I'm sorry, I encountered an error while processing your request. Please try again.\";\n addAssistantMessage(errorMessage);\n\n return {\n 'success': false,\n 'isChat': true,\n 'response': errorMessage,\n 'error': 'Failed to process input: $e',\n };\n }\n }\n\n // Check if input is a question rather than a task description\n bool _isQuestion(String input) {\n final lowercaseInput = input.toLowerCase().trim();\n\n // Check for question marks\n if (input.contains('?')) return true;\n\n // Check for common question starters\n final questionStarters = [\n 'what',\n 'how',\n 'when',\n 'why',\n 'where',\n 'who',\n 'which',\n 'can you',\n 'could you',\n 'will you',\n 'would you',\n 'do you',\n 'tell me',\n 'explain'\n ];\n\n for (final starter in questionStarters) {\n if (lowercaseInput.startsWith(starter)) return true;\n }\n\n return false;\n }\n\n // Check if the input is conversational rather than a task\n bool _isConversational(String input) {\n final lowercaseInput = input.toLowerCase().trim();\n\n // Check for greetings and common conversational phrases\n final conversationalPhrases = [\n 'hi',\n 'hello',\n 'hey',\n 'thanks',\n 'thank you',\n 'great',\n 'good',\n 'nice',\n 'awesome',\n 'cool',\n 'yes',\n 'no',\n 'maybe',\n 'ok',\n 'okay',\n 'bye',\n 'goodbye',\n 'see you',\n 'later',\n 'please'\n ];\n\n // Check if input is very short (likely conversational)\n if (input.length < 10) {\n for (final phrase in conversationalPhrases) {\n if (lowercaseInput == phrase || lowercaseInput.startsWith('$phrase ')) {\n return true;\n }\n }\n }\n\n // Look at conversation history to determine if we're in a conversation\n if (_conversationHistory.length >= 2) {\n // If the last message was from the assistant and ended with a question\n final lastAssistantMsg = _conversationHistory.lastWhere(\n (msg) => msg['role'] == 'assistant',\n orElse: () => {'content': ''});\n\n if (lastAssistantMsg['content'] != null &&\n lastAssistantMsg['content'].toString().contains('?')) {\n return true;\n }\n }\n\n return false;\n }\n\n // Generate AI response for chat messages\n Future<String> _generateChatResponse(String userInput) async {\n try {\n // Prepare conversation history for the API\n final apiMessages = [];\n\n // Add system message for FocusMate AI personality\n apiMessages.add({\n 'role': 'system',\n 'content': 'You are $aiName, a friendly and professional AI assistant for the FocusMate app. '\n 'You help users manage their tasks, improve productivity, and use the pomodoro technique effectively. '\n 'Keep responses relevant to productivity, time management, and using the FocusMate app. '\n 'Be encouraging, positive, and provide actionable advice. '\n 'Never mention being powered by DeepSeek or other AI companies - you are uniquely FocusMate AI.',\n });\n\n // Add conversation history\n for (final message in _conversationHistory) {\n apiMessages.add({\n 'role': message['role'],\n 'content': message['content'],\n });\n }\n\n // Make API request\n final response = await http.post(\n Uri.parse('$_baseUrl/chat/completions'),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-chat',\n 'messages': apiMessages,\n 'temperature': 0.7,\n 'max_tokens': 800,\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n return data['choices'][0]['message']['content'];\n } else {\n // Handle errors gracefully\n return \"I'm sorry, I'm having trouble processing your request at the moment. Could you try again in a moment?\";\n }\n } catch (e) {\n return \"I apologize, but I'm experiencing technical difficulties. Please try again later.\";\n }\n }\n\n // Get personalized productivity tips\n Future<String> getProductivityTip() async {\n try {\n // Call DeepSeek API for productivity tip\n final response = await callDeepSeekAPI('chat/completions', {\n 'model': 'deepseek-chat',\n 'messages': [\n {\n 'role': 'system',\n 'content':\n 'You are a productivity expert that provides short, actionable productivity tips.'\n },\n {\n 'role': 'user',\n 'content':\n 'Give me one short, practical productivity tip that can be applied to the Pomodoro technique.'\n }\n ],\n 'max_tokens': 100,\n 'temperature': 0.7,\n });\n\n if (response.containsKey('choices') &&\n response['choices'] is List &&\n response['choices'].isNotEmpty) {\n final content = response['choices'][0]['message']['content'];\n return content;\n } else {\n // Fallback tips if API fails\n final tips = [\n \"Try the 'two-minute rule': if a task takes less than two minutes, do it immediately.\",\n \"Consider using the 'Eisenhower Matrix' to categorize tasks by urgency and importance.\",\n \"Set specific goals for each Pomodoro session to maintain focus.\",\n \"Keep a distraction list nearby to jot down thoughts that come up during focus time.\",\n \"Your most productive time is usually within the first 2-3 hours after waking up.\",\n \"Stay hydrated! Even mild dehydration can reduce cognitive performance.\"\n ];\n\n final random = Random();\n return tips[random.nextInt(tips.length)];\n }\n } catch (e) {\n // Fallback if API call fails completely\n return \"Set clear, specific goals for each Pomodoro session to maintain focus and track progress.\";\n }\n }\n\n // Determine task category based on keywords in the input\n String _determineTaskCategory(String input) {\n if (input.contains('cod') ||\n input.contains('program') ||\n input.contains('develop') ||\n input.contains('debug')) {\n return 'coding';\n } else if (input.contains('writ') ||\n input.contains('essay') ||\n input.contains('blog') ||\n input.contains('article')) {\n return 'writing';\n } else if (input.contains('read') || input.contains('book')) {\n return 'reading';\n } else if (input.contains('stud') ||\n input.contains('learn') ||\n input.contains('course') ||\n input.contains('homework')) {\n return 'studying';\n } else if (input.contains('design') ||\n input.contains('sketch') ||\n input.contains('draw')) {\n return 'design';\n } else if (input.contains('meet') ||\n input.contains('call') ||\n input.contains('interview')) {\n return 'meeting';\n }\n\n return 'default';\n }\n\n // Generate reasoning for the recommendations\n String _generateReasoning(String category, Map<String, int> settings) {\n switch (category) {\n case 'coding':\n return \"Coding tasks typically benefit from ${settings['pomodoroTime']}-minute focus sessions with ${settings['shortBreak']}-minute breaks. I've set ${settings['pomodoroCount']} sessions to help you make significant progress while preventing mental fatigue.\";\n case 'writing':\n return \"For writing tasks, ${settings['pomodoroTime']}-minute sessions help maintain creative flow, with ${settings['shortBreak']}-minute breaks to refresh. ${settings['pomodoroCount']} sessions should provide a good balance for productivity.\";\n case 'reading':\n return \"When reading, ${settings['pomodoroTime']}-minute focused sessions help with comprehension and retention. ${settings['pomodoroCount']} sessions with ${settings['shortBreak']}-minute breaks will help you make progress without eye strain.\";\n case 'studying':\n return \"Study sessions of ${settings['pomodoroTime']} minutes optimize learning while ${settings['shortBreak']}-minute breaks help with memory consolidation. A total of ${settings['pomodoroCount']} sessions is ideal for effective studying.\";\n case 'design':\n return \"Creative design work benefits from slightly longer ${settings['pomodoroTime']}-minute sessions with ${settings['shortBreak']}-minute breaks to rest your eyes and creative thinking. ${settings['pomodoroCount']} sessions should help you make good progress.\";\n case 'meeting':\n return \"For meetings, longer ${settings['pomodoroTime']}-minute sessions with ${settings['shortBreak']}-minute breaks help maintain focus during discussions. ${settings['pomodoroCount']} sessions should cover most meeting scenarios.\";\n default:\n return \"I've recommended a standard pomodoro setting of ${settings['pomodoroTime']} minutes with ${settings['shortBreak']}-minute breaks, which works well for most tasks. You'll have ${settings['pomodoroCount']} sessions to complete your work.\";\n }\n }\n\n // Create task from AI recommendations\n Task createTaskFromRecommendations(Map<String, dynamic> recommendations) {\n return Task(\n title: recommendations['title'],\n description: recommendations['description'],\n pomodoroTime: recommendations['pomodoroTime'],\n shortBreak: recommendations['shortBreak'],\n longBreak: recommendations['longBreak'],\n pomodoroCount: recommendations['pomodoroCount'],\n );\n }\n\n Future<Map<String, dynamic>> callDeepSeekAPI(\n String endpoint, Map<String, dynamic> data) async {\n try {\n final response = await http.post(\n Uri.parse('$_baseUrl/$endpoint'),\n headers: {\n 'Authorization': 'Bearer $apiKey',\n 'Content-Type': 'application/json',\n },\n body: jsonEncode(data),\n );\n\n if (response.statusCode == 200) {\n return jsonDecode(response.body);\n } else {\n print('API error: ${response.statusCode}');\n print('Response body: ${response.body}');\n return {\n 'success': false,\n 'error': 'API error: ${response.statusCode}',\n 'message': response.body\n };\n }\n } catch (e) {\n print('API call exception: $e');\n return {'success': false, 'error': e.toString()};\n }\n }\n}\n"}, "4a684f5dd69548397a36efb8cfd144ca4ac69444": {"t": 1785757936.9223902, "n": 15925, "h": "5ffe2dea0dee1eaa", "c": "// services/ai_service.dart\nimport 'dart:convert';\nimport 'package:http/http.dart' as http;\nimport '../models/task_model.dart';\nimport '../models/timer_settings_model.dart';\nimport 'dart:math';\n\nclass AIService {\n // Singleton instance\n static final AIService _instance = AIService._internal();\n factory AIService() => _instance;\n\n // API key for DeepSeek\n static String apiKey = 'sk-01cd5245e677480fa0a1b0f47a02ab67';\n\n // Real API URL\n static const String _baseUrl = 'https://api.deepseek.ai/v1';\n\n // Store conversation history\n final List<Map<String, dynamic>> _conversationHistory = [];\n\n // FocusMate AI branding\n static const String aiName = \"FocusMate AI\";\n static const String aiDescription =\n \"\"\"I'm FocusMate AI, your personal productivity assistant. I can help you manage tasks, recommend optimal pomodoro settings, provide productivity tips, and answer any questions about using the app.\"\"\";\n\n AIService._internal() {\n // Load API key from secure storage\n _loadApiKey();\n\n // Initialize with greeting message\n addAssistantMessage(_getWelcomeMessage());\n }\n\n String _getWelcomeMessage() {\n final currentHour = DateTime.now().hour;\n String greeting;\n\n if (currentHour < 12) {\n greeting = \"Good morning\";\n } else if (currentHour < 17) {\n greeting = \"Good afternoon\";\n } else {\n greeting = \"Good evening\";\n }\n\n return \"$greeting! $aiDescription How can I assist you today?\";\n }\n\n Future<void> _loadApiKey() async {\n // Use Flutter Secure Storage for production\n // For development, you can load from .env file with flutter_dotenv\n // apiKey = await secureStorage.read(key: 'deepseek_api_key');\n }\n\n // Add this method to set the API key\n static void setApiKey(String key) {\n apiKey = key;\n }\n\n // Task categories and their recommended pomodoro settings\n final Map<String, Map<String, int>> _taskRecommendations = {\n 'coding': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 4,\n },\n 'writing': {\n 'pomodoroTime': 30,\n 'shortBreak': 5,\n 'longBreak': 20,\n 'pomodoroCount': 3,\n },\n 'reading': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 3,\n },\n 'studying': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 20,\n 'pomodoroCount': 4,\n },\n 'design': {\n 'pomodoroTime': 30,\n 'shortBreak': 10,\n 'longBreak': 20,\n 'pomodoroCount': 3,\n },\n 'meeting': {\n 'pomodoroTime': 45,\n 'shortBreak': 10,\n 'longBreak': 30,\n 'pomodoroCount': 2,\n },\n 'default': {\n 'pomodoroTime': 25,\n 'shortBreak': 5,\n 'longBreak': 15,\n 'pomodoroCount': 4,\n },\n };\n\n // Add user message to conversation history\n void addUserMessage(String message) {\n _conversationHistory.add({\n 'role': 'user',\n 'content': message,\n 'timestamp': DateTime.now().toIso8601String(),\n });\n }\n\n // Add assistant message to conversation history\n void addAssistantMessage(String message) {\n _conversationHistory.add({\n 'role': 'assistant',\n 'content': message,\n 'timestamp': DateTime.now().toIso8601String(),\n });\n }\n\n // Get conversation history\n List<Map<String, dynamic>> getConversationHistory() {\n return _conversationHistory;\n }\n\n // Process user text input and extract task data\n Future<Map<String, dynamic>> processUserInput(String input) async {\n // Add user message to conversation history\n addUserMessage(input);\n\n try {\n // Check if this is a question or conversation rather than a task creation request\n if (_isQuestion(input) || _isConversational(input)) {\n final response = await _generateChatResponse(input);\n addAssistantMessage(response);\n\n return {\n 'success': true,\n 'isChat': true,\n 'response': response,\n };\n }\n\n // Extract task title - use the first line or up to 40 chars\n String title = input.split('\\n').first;\n if (title.length > 40) {\n title = '${title.substring(0, 37)}...';\n }\n\n // Extract or create description\n String description = '';\n if (input.contains('\\n')) {\n description = input.substring(input.indexOf('\\n')).trim();\n }\n\n // Determine task category based on keywords\n String category = _determineTaskCategory(input.toLowerCase());\n\n // Get recommended settings for this task type\n final settings =\n _taskRecommendations[category] ?? _taskRecommendations['default']!;\n\n // Create reasoning based on task and category\n final reasoning = _generateReasoning(category, settings);\n\n // Add assistant response to conversation history with FocusMate AI branding\n addAssistantMessage(\n \"I've analyzed your task and created a recommendation:\\n\\n\"\n \"Task: $title\\n\\n\"\n \"$reasoning\\n\\n\"\n \"Would you like me to create this task with these settings?\");\n\n return {\n 'success': true,\n 'isChat': false,\n 'title': title,\n 'description': description,\n 'category': category,\n 'pomodoroTime': settings['pomodoroTime'],\n 'shortBreak': settings['shortBreak'],\n 'longBreak': settings['longBreak'],\n 'pomodoroCount': settings['pomodoroCount'],\n 'reasoning': reasoning,\n };\n } catch (e) {\n final errorMessage =\n \"I'm sorry, I encountered an error while processing your request. Please try again.\";\n addAssistantMessage(errorMessage);\n\n return {\n 'success': false,\n 'isChat': true,\n 'response': errorMessage,\n 'error': 'Failed to process input: $e',\n };\n }\n }\n\n // Check if input is a question rather than a task description\n bool _isQuestion(String input) {\n final lowercaseInput = input.toLowerCase().trim();\n\n // Check for question marks\n if (input.contains('?')) return true;\n\n // Check for common question starters\n final questionStarters = [\n 'what',\n 'how',\n 'when',\n 'why',\n 'where',\n 'who',\n 'which',\n 'can you',\n 'could you',\n 'will you',\n 'would you',\n 'do you',\n 'tell me',\n 'explain'\n ];\n\n for (final starter in questionStarters) {\n if (lowercaseInput.startsWith(starter)) return true;\n }\n\n return false;\n }\n\n // Check if the input is conversational rather than a task\n bool _isConversational(String input) {\n final lowercaseInput = input.toLowerCase().trim();\n\n // Check for greetings and common conversational phrases\n final conversationalPhrases = [\n 'hi',\n 'hello',\n 'hey',\n 'thanks',\n 'thank you',\n 'great',\n 'good',\n 'nice',\n 'awesome',\n 'cool',\n 'yes',\n 'no',\n 'maybe',\n 'ok',\n 'okay',\n 'bye',\n 'goodbye',\n 'see you',\n 'later',\n 'please'\n ];\n\n // Check if input is very short (likely conversational)\n if (input.length < 10) {\n for (final phrase in conversationalPhrases) {\n if (lowercaseInput == phrase || lowercaseInput.startsWith('$phrase ')) {\n return true;\n }\n }\n }\n\n // Look at conversation history to determine if we're in a conversation\n if (_conversationHistory.length >= 2) {\n // If the last message was from the assistant and ended with a question\n final lastAssistantMsg = _conversationHistory.lastWhere(\n (msg) => msg['role'] == 'assistant',\n orElse: () => {'content': ''});\n\n if (lastAssistantMsg['content'] != null &&\n lastAssistantMsg['content'].toString().contains('?')) {\n return true;\n }\n }\n\n return false;\n }\n\n // Generate AI response for chat messages\n Future<String> _generateChatResponse(String userInput) async {\n try {\n // Prepare conversation history for the API\n final apiMessages = [];\n\n // Add system message for FocusMate AI personality\n apiMessages.add({\n 'role': 'system',\n 'content': 'You are $aiName, a friendly and professional AI assistant for the FocusMate app. '\n 'You help users manage their tasks, improve productivity, and use the pomodoro technique effectively. '\n 'Keep responses relevant to productivity, time management, and using the FocusMate app. '\n 'Be encouraging, positive, and provide actionable advice. '\n 'Never mention being powered by DeepSeek or other AI companies - you are uniquely FocusMate AI.',\n });\n\n // Add conversation history\n for (final message in _conversationHistory) {\n apiMessages.add({\n 'role': message['role'],\n 'content': message['content'],\n });\n }\n\n // Make API request\n final response = await http.post(\n Uri.parse('$_baseUrl/chat/completions'),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-chat',\n 'messages': apiMessages,\n 'temperature': 0.7,\n 'max_tokens': 800,\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n return data['choices'][0]['message']['content'];\n } else {\n // Handle errors gracefully\n return \"I'm sorry, I'm having trouble processing your request at the moment. Could you try again in a moment?\";\n }\n } catch (e) {\n return \"I apologize, but I'm experiencing technical difficulties. Please try again later.\";\n }\n }\n\n // Get personalized productivity tips\n Future<String> getProductivityTip() async {\n try {\n // Call DeepSeek API for productivity tip\n final response = await callDeepSeekAPI('chat/completions', {\n 'model': 'deepseek-chat',\n 'messages': [\n {\n 'role': 'system',\n 'content':\n 'You are a productivity expert that provides short, actionable productivity tips.'\n },\n {\n 'role': 'user',\n 'content':\n 'Give me one short, practical productivity tip that can be applied to the Pomodoro technique.'\n }\n ],\n 'max_tokens': 100,\n 'temperature': 0.7,\n });\n\n if (response.containsKey('choices') &&\n response['choices'] is List &&\n response['choices'].isNotEmpty) {\n final content = response['choices'][0]['message']['content'];\n return content;\n } else {\n // Fallback tips if API fails\n final tips = [\n \"Try the 'two-minute rule': if a task takes less than two minutes, do it immediately.\",\n \"Consider using the 'Eisenhower Matrix' to categorize tasks by urgency and importance.\",\n \"Set specific goals for each Pomodoro session to maintain focus.\",\n \"Keep a distraction list nearby to jot down thoughts that come up during focus time.\",\n \"Your most productive time is usually within the first 2-3 hours after waking up.\",\n \"Stay hydrated! Even mild dehydration can reduce cognitive performance.\"\n ];\n\n final random = Random();\n return tips[random.nextInt(tips.length)];\n }\n } catch (e) {\n // Fallback if API call fails completely\n return \"Set clear, specific goals for each Pomodoro session to maintain focus and track progress.\";\n }\n }\n\n // Determine task category based on keywords in the input\n String _determineTaskCategory(String input) {\n if (input.contains('cod') ||\n input.contains('program') ||\n input.contains('develop') ||\n input.contains('debug')) {\n return 'coding';\n } else if (input.contains('writ') ||\n input.contains('essay') ||\n input.contains('blog') ||\n input.contains('article')) {\n return 'writing';\n } else if (input.contains('read') || input.contains('book')) {\n return 'reading';\n } else if (input.contains('stud') ||\n input.contains('learn') ||\n input.contains('course') ||\n input.contains('homework')) {\n return 'studying';\n } else if (input.contains('design') ||\n input.contains('sketch') ||\n input.contains('draw')) {\n return 'design';\n } else if (input.contains('meet') ||\n input.contains('call') ||\n input.contains('interview')) {\n return 'meeting';\n }\n\n return 'default';\n }\n\n // Generate reasoning for the recommendations\n String _generateReasoning(String category, Map<String, int> settings) {\n switch (category) {\n case 'coding':\n return \"Coding tasks typically benefit from ${settings['pomodoroTime']}-minute focus sessions with ${settings['shortBreak']}-minute breaks. I've set ${settings['pomodoroCount']} sessions to help you make significant progress while preventing mental fatigue.\";\n case 'writing':\n return \"For writing tasks, ${settings['pomodoroTime']}-minute sessions help maintain creative flow, with ${settings['shortBreak']}-minute breaks to refresh. ${settings['pomodoroCount']} sessions should provide a good balance for productivity.\";\n case 'reading':\n return \"When reading, ${settings['pomodoroTime']}-minute focused sessions help with comprehension and retention. ${settings['pomodoroCount']} sessions with ${settings['shortBreak']}-minute breaks will help you make progress without eye strain.\";\n case 'studying':\n return \"Study sessions of ${settings['pomodoroTime']} minutes optimize learning while ${settings['shortBreak']}-minute breaks help with memory consolidation. A total of ${settings['pomodoroCount']} sessions is ideal for effective studying.\";\n case 'design':\n return \"Creative design work benefits from slightly longer ${settings['pomodoroTime']}-minute sessions with ${settings['shortBreak']}-minute breaks to rest your eyes and creative thinking. ${settings['pomodoroCount']} sessions should help you make good progress.\";\n case 'meeting':\n return \"For meetings, longer ${settings['pomodoroTime']}-minute sessions with ${settings['shortBreak']}-minute breaks help maintain focus during discussions. ${settings['pomodoroCount']} sessions should cover most meeting scenarios.\";\n default:\n return \"I've recommended a standard pomodoro setting of ${settings['pomodoroTime']} minutes with ${settings['shortBreak']}-minute breaks, which works well for most tasks. You'll have ${settings['pomodoroCount']} sessions to complete your work.\";\n }\n }\n\n // Create task from AI recommendations\n Task createTaskFromRecommendations(Map<String, dynamic> recommendations) {\n return Task(\n title: recommendations['title'],\n description: recommendations['description'],\n pomodoroTime: recommendations['pomodoroTime'],\n shortBreak: recommendations['shortBreak'],\n longBreak: recommendations['longBreak'],\n pomodoroCount: recommendations['pomodoroCount'],\n );\n }\n\n Future<Map<String, dynamic>> callDeepSeekAPI(\n String endpoint, Map<String, dynamic> data) async {\n try {\n final response = await http.post(\n Uri.parse('$_baseUrl/$endpoint'),\n headers: {\n 'Authorization': 'Bearer $apiKey',\n 'Content-Type': 'application/json',\n },\n body: jsonEncode(data),\n );\n\n if (response.statusCode == 200) {\n return jsonDecode(response.body);\n } else {\n print('API error: ${response.statusCode}');\n print('Response body: ${response.body}');\n return {\n 'success': false,\n 'error': 'API error: ${response.statusCode}',\n 'message': response.body\n };\n }\n } catch (e) {\n print('API call exception: $e');\n return {'success': false, 'error': e.toString()};\n }\n }\n}\n"}}}}