1 line
7.1 KiB
JSON
1 line
7.1 KiB
JSON
{"repo": "aliarain/salahapp", "files": {"JazakAllah-Revamped/lib/data/services/deepseek_service.dart": {"a3a24356ba8f21ae7c1605ddb74a39e81d27e8df": {"t": 1785745919.6997008, "n": 3365, "h": "c2960949a65e8f52", "c": "import 'dart:convert';\nimport 'dart:io';\nimport 'package:flutter_dotenv/flutter_dotenv.dart';\nimport 'package:http/http.dart' as http;\n\nclass DeepseekService {\n final String _apiKey = dotenv.env['DEEPSEEK_API_KEY'] ?? '';\n final String _apiUrl = 'https://api.deepseek.com/v1/chat/completions';\n\n Future<Map<String, dynamic>?> scanTimetable(File imageFile) async {\n if (_apiKey.isEmpty) {\n throw Exception(\n 'Deepseek API key not found. Please check your .env file.');\n }\n\n try {\n // Convert image to base64\n final bytes = await imageFile.readAsBytes();\n final base64Image = base64Encode(bytes);\n\n // Prepare the request\n final response = await http.post(\n Uri.parse(_apiUrl),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $_apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-vision',\n 'messages': [\n {\n 'role': 'system',\n 'content':\n 'You are an expert at extracting prayer times from mosque timetables. Extract the prayer times in a structured JSON format with fields for each prayer (fajr, dhuhr, asr, maghrib, isha) and any additional information like jummah times. If there are multiple months, focus on the current month. Return only the JSON data without any explanations.'\n },\n {\n 'role': 'user',\n 'content': [\n {\n 'type': 'text',\n 'text':\n 'Extract the prayer times from this timetable image. Return the data in JSON format with fields for each prayer time (fajr, dhuhr, asr, maghrib, isha) and any additional information like jummah times. If there are multiple months, focus on the current month.'\n },\n {\n 'type': 'image_url',\n 'image_url': {'url': 'data:image/jpeg;base64,$base64Image'}\n }\n ]\n }\n ],\n 'max_tokens': 4000\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n final content = data['choices'][0]['message']['content'];\n\n // Extract JSON from the response\n try {\n // Try to parse the entire content as JSON\n return jsonDecode(content);\n } catch (e) {\n // If that fails, try to extract JSON from the text\n final jsonMatch =\n RegExp(r'```json\\s*([\\s\\S]*?)\\s*```').firstMatch(content);\n if (jsonMatch != null && jsonMatch.groupCount >= 1) {\n return jsonDecode(jsonMatch.group(1)!);\n }\n\n // If no JSON block, try to find anything that looks like JSON\n final jsonStart = content.indexOf('{');\n final jsonEnd = content.lastIndexOf('}');\n\n if (jsonStart >= 0 && jsonEnd > jsonStart) {\n final jsonStr = content.substring(jsonStart, jsonEnd + 1);\n return jsonDecode(jsonStr);\n }\n\n throw Exception('Could not extract JSON from the response');\n }\n } else {\n throw Exception(\n 'Failed to process image: ${response.statusCode} ${response.body}');\n }\n } catch (e) {\n print('Error in scanTimetable: $e');\n return null;\n }\n }\n}\n"}, "441bf76bfb1cf452063d58945d3d42a0668d6352": {"t": 1785757918.2894511, "n": 3365, "h": "c2960949a65e8f52", "c": "import 'dart:convert';\nimport 'dart:io';\nimport 'package:flutter_dotenv/flutter_dotenv.dart';\nimport 'package:http/http.dart' as http;\n\nclass DeepseekService {\n final String _apiKey = dotenv.env['DEEPSEEK_API_KEY'] ?? '';\n final String _apiUrl = 'https://api.deepseek.com/v1/chat/completions';\n\n Future<Map<String, dynamic>?> scanTimetable(File imageFile) async {\n if (_apiKey.isEmpty) {\n throw Exception(\n 'Deepseek API key not found. Please check your .env file.');\n }\n\n try {\n // Convert image to base64\n final bytes = await imageFile.readAsBytes();\n final base64Image = base64Encode(bytes);\n\n // Prepare the request\n final response = await http.post(\n Uri.parse(_apiUrl),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $_apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-vision',\n 'messages': [\n {\n 'role': 'system',\n 'content':\n 'You are an expert at extracting prayer times from mosque timetables. Extract the prayer times in a structured JSON format with fields for each prayer (fajr, dhuhr, asr, maghrib, isha) and any additional information like jummah times. If there are multiple months, focus on the current month. Return only the JSON data without any explanations.'\n },\n {\n 'role': 'user',\n 'content': [\n {\n 'type': 'text',\n 'text':\n 'Extract the prayer times from this timetable image. Return the data in JSON format with fields for each prayer time (fajr, dhuhr, asr, maghrib, isha) and any additional information like jummah times. If there are multiple months, focus on the current month.'\n },\n {\n 'type': 'image_url',\n 'image_url': {'url': 'data:image/jpeg;base64,$base64Image'}\n }\n ]\n }\n ],\n 'max_tokens': 4000\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n final content = data['choices'][0]['message']['content'];\n\n // Extract JSON from the response\n try {\n // Try to parse the entire content as JSON\n return jsonDecode(content);\n } catch (e) {\n // If that fails, try to extract JSON from the text\n final jsonMatch =\n RegExp(r'```json\\s*([\\s\\S]*?)\\s*```').firstMatch(content);\n if (jsonMatch != null && jsonMatch.groupCount >= 1) {\n return jsonDecode(jsonMatch.group(1)!);\n }\n\n // If no JSON block, try to find anything that looks like JSON\n final jsonStart = content.indexOf('{');\n final jsonEnd = content.lastIndexOf('}');\n\n if (jsonStart >= 0 && jsonEnd > jsonStart) {\n final jsonStr = content.substring(jsonStart, jsonEnd + 1);\n return jsonDecode(jsonStr);\n }\n\n throw Exception('Could not extract JSON from the response');\n }\n } else {\n throw Exception(\n 'Failed to process image: ${response.statusCode} ${response.body}');\n }\n } catch (e) {\n print('Error in scanTimetable: $e');\n return null;\n }\n }\n}\n"}}}} |