1 line
9.7 KiB
JSON
1 line
9.7 KiB
JSON
{"repo": "ahmed4040400/mobile2application", "files": {"lib/services/deepseek_service.dart": {"ff5dd57cd20425f796d45de86a9444deb10dba6a": {"t": 1785745921.6771307, "n": 4140, "h": "d68ad3e2fc873f00", "c": "import 'dart:convert';\nimport 'package:flutter_dotenv/flutter_dotenv.dart';\nimport 'package:http/http.dart' as http;\n\nclass DeepSeekService {\n static const String _baseUrl = 'https://api.deepseek.com/v1/chat/completions';\n \n String get _apiKey => dotenv.env['DEEPSEEK_API_KEY'] ?? '';\n\n /// Generate an Arabic story based on user choices\n Future<StoryResponse> generateStory({\n required String childName,\n required String storyType,\n required String friend,\n required String place,\n }) async {\n final prompt = '''\nأنت كاتب قصص أطفال محترف. اكتب قصة قصيرة باللغة العربية للأطفال.\n\nمعلومات القصة:\n- اسم البطل: $childName\n- نوع القصة: $storyType\n- صديق البطل: $friend\n- مكان المغامرة: $place\n\nالمطلوب:\n1. اكتب قصة مكونة من 4 أجزاء قصيرة (كل جزء 2-3 جمل)\n2. اجعل القصة ممتعة ومناسبة للأطفال\n3. في نهاية القصة، اكتب سؤالاً تفاعلياً للطفل مع 3 خيارات\n4. أجب بصيغة JSON فقط بدون أي نص إضافي\n\nصيغة الإجابة المطلوبة (JSON فقط):\n{\n \"title\": \"عنوان القصة\",\n \"pages\": [\n \"الجزء الأول من القصة\",\n \"الجزء الثاني من القصة\",\n \"الجزء الثالث من القصة\",\n \"الجزء الرابع من القصة\"\n ],\n \"question\": {\n \"text\": \"السؤال التفاعلي\",\n \"choices\": [\n {\"emoji\": \"🎁\", \"text\": \"الخيار الأول\"},\n {\"emoji\": \"🦉\", \"text\": \"الخيار الثاني\"},\n {\"emoji\": \"✨\", \"text\": \"الخيار الثالث\"}\n ]\n }\n}\n''';\n\n try {\n final response = await http.post(\n Uri.parse(_baseUrl),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $_apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-chat',\n 'messages': [\n {\n 'role': 'system',\n 'content': 'أنت كاتب قصص أطفال محترف. أجب دائماً بصيغة JSON فقط.',\n },\n {\n 'role': 'user',\n 'content': prompt,\n },\n ],\n 'temperature': 0.8,\n 'max_tokens': 1500,\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n final content = data['choices'][0]['message']['content'] as String;\n \n // Parse the JSON from the response\n final storyJson = _extractJson(content);\n return StoryResponse.fromJson(storyJson);\n } else {\n throw Exception('Failed to generate story: ${response.statusCode} - ${response.body}');\n }\n } catch (e) {\n throw Exception('Error generating story: $e');\n }\n }\n\n Map<String, dynamic> _extractJson(String content) {\n // Try to extract JSON from the response\n try {\n // First try direct parsing\n return jsonDecode(content);\n } catch (_) {\n // Try to find JSON in the content\n final jsonMatch = RegExp(r'\\{[\\s\\S]*\\}').firstMatch(content);\n if (jsonMatch != null) {\n return jsonDecode(jsonMatch.group(0)!);\n }\n throw Exception('Could not parse story JSON from response');\n }\n }\n}\n\nclass StoryResponse {\n final String title;\n final List<String> pages;\n final StoryQuestion question;\n\n StoryResponse({\n required this.title,\n required this.pages,\n required this.question,\n });\n\n factory StoryResponse.fromJson(Map<String, dynamic> json) {\n return StoryResponse(\n title: json['title'] ?? 'قصة جميلة',\n pages: List<String>.from(json['pages'] ?? []),\n question: StoryQuestion.fromJson(json['question'] ?? {}),\n );\n }\n}\n\nclass StoryQuestion {\n final String text;\n final List<StoryChoice> choices;\n\n StoryQuestion({\n required this.text,\n required this.choices,\n });\n\n factory StoryQuestion.fromJson(Map<String, dynamic> json) {\n return StoryQuestion(\n text: json['text'] ?? 'ماذا تختار؟',\n choices: (json['choices'] as List<dynamic>?)\n ?.map((c) => StoryChoice.fromJson(c))\n .toList() ??\n [],\n );\n }\n}\n\nclass StoryChoice {\n final String emoji;\n final String text;\n\n StoryChoice({\n required this.emoji,\n required this.text,\n });\n\n factory StoryChoice.fromJson(Map<String, dynamic> json) {\n return StoryChoice(\n emoji: json['emoji'] ?? '⭐',\n text: json['text'] ?? '',\n );\n }\n}\n"}, "a2af5197dcad1458a517b0f49c2c42402343d4c9": {"t": 1785757925.600046, "n": 4140, "h": "d68ad3e2fc873f00", "c": "import 'dart:convert';\nimport 'package:flutter_dotenv/flutter_dotenv.dart';\nimport 'package:http/http.dart' as http;\n\nclass DeepSeekService {\n static const String _baseUrl = 'https://api.deepseek.com/v1/chat/completions';\n \n String get _apiKey => dotenv.env['DEEPSEEK_API_KEY'] ?? '';\n\n /// Generate an Arabic story based on user choices\n Future<StoryResponse> generateStory({\n required String childName,\n required String storyType,\n required String friend,\n required String place,\n }) async {\n final prompt = '''\nأنت كاتب قصص أطفال محترف. اكتب قصة قصيرة باللغة العربية للأطفال.\n\nمعلومات القصة:\n- اسم البطل: $childName\n- نوع القصة: $storyType\n- صديق البطل: $friend\n- مكان المغامرة: $place\n\nالمطلوب:\n1. اكتب قصة مكونة من 4 أجزاء قصيرة (كل جزء 2-3 جمل)\n2. اجعل القصة ممتعة ومناسبة للأطفال\n3. في نهاية القصة، اكتب سؤالاً تفاعلياً للطفل مع 3 خيارات\n4. أجب بصيغة JSON فقط بدون أي نص إضافي\n\nصيغة الإجابة المطلوبة (JSON فقط):\n{\n \"title\": \"عنوان القصة\",\n \"pages\": [\n \"الجزء الأول من القصة\",\n \"الجزء الثاني من القصة\",\n \"الجزء الثالث من القصة\",\n \"الجزء الرابع من القصة\"\n ],\n \"question\": {\n \"text\": \"السؤال التفاعلي\",\n \"choices\": [\n {\"emoji\": \"🎁\", \"text\": \"الخيار الأول\"},\n {\"emoji\": \"🦉\", \"text\": \"الخيار الثاني\"},\n {\"emoji\": \"✨\", \"text\": \"الخيار الثالث\"}\n ]\n }\n}\n''';\n\n try {\n final response = await http.post(\n Uri.parse(_baseUrl),\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer $_apiKey',\n },\n body: jsonEncode({\n 'model': 'deepseek-chat',\n 'messages': [\n {\n 'role': 'system',\n 'content': 'أنت كاتب قصص أطفال محترف. أجب دائماً بصيغة JSON فقط.',\n },\n {\n 'role': 'user',\n 'content': prompt,\n },\n ],\n 'temperature': 0.8,\n 'max_tokens': 1500,\n }),\n );\n\n if (response.statusCode == 200) {\n final data = jsonDecode(response.body);\n final content = data['choices'][0]['message']['content'] as String;\n \n // Parse the JSON from the response\n final storyJson = _extractJson(content);\n return StoryResponse.fromJson(storyJson);\n } else {\n throw Exception('Failed to generate story: ${response.statusCode} - ${response.body}');\n }\n } catch (e) {\n throw Exception('Error generating story: $e');\n }\n }\n\n Map<String, dynamic> _extractJson(String content) {\n // Try to extract JSON from the response\n try {\n // First try direct parsing\n return jsonDecode(content);\n } catch (_) {\n // Try to find JSON in the content\n final jsonMatch = RegExp(r'\\{[\\s\\S]*\\}').firstMatch(content);\n if (jsonMatch != null) {\n return jsonDecode(jsonMatch.group(0)!);\n }\n throw Exception('Could not parse story JSON from response');\n }\n }\n}\n\nclass StoryResponse {\n final String title;\n final List<String> pages;\n final StoryQuestion question;\n\n StoryResponse({\n required this.title,\n required this.pages,\n required this.question,\n });\n\n factory StoryResponse.fromJson(Map<String, dynamic> json) {\n return StoryResponse(\n title: json['title'] ?? 'قصة جميلة',\n pages: List<String>.from(json['pages'] ?? []),\n question: StoryQuestion.fromJson(json['question'] ?? {}),\n );\n }\n}\n\nclass StoryQuestion {\n final String text;\n final List<StoryChoice> choices;\n\n StoryQuestion({\n required this.text,\n required this.choices,\n });\n\n factory StoryQuestion.fromJson(Map<String, dynamic> json) {\n return StoryQuestion(\n text: json['text'] ?? 'ماذا تختار؟',\n choices: (json['choices'] as List<dynamic>?)\n ?.map((c) => StoryChoice.fromJson(c))\n .toList() ??\n [],\n );\n }\n}\n\nclass StoryChoice {\n final String emoji;\n final String text;\n\n StoryChoice({\n required this.emoji,\n required this.text,\n });\n\n factory StoryChoice.fromJson(Map<String, dynamic> json) {\n return StoryChoice(\n emoji: json['emoji'] ?? '⭐',\n text: json['text'] ?? '',\n );\n }\n}\n"}}}} |