{"repo": "300dpi-co/pixly", "files": {"app/Services/BlogAIService.php": {"99e7b33467817c60024f776bd28554aa74d4d15d": {"t": 1785746146.9516237, "n": 10838, "h": "3a34e1f53e91c405", "c": "apiKey = config('api.deepseek.key', '');\n $this->endpoint = config('api.deepseek.endpoint', 'https://api.deepseek.com');\n $this->model = config('api.deepseek.model', 'deepseek-chat');\n }\n\n /**\n * Generate a complete blog post\n */\n public function generatePost(string $topic, string $tone = 'professional', string $length = 'medium', string $keywords = ''): array\n {\n $wordCounts = [\n 'short' => '500-700',\n 'medium' => '1000-1200',\n 'long' => '1800-2200',\n ];\n\n $targetWords = $wordCounts[$length] ?? '1000-1200';\n\n $prompt = $this->buildGenerationPrompt($topic, $tone, $targetWords, $keywords);\n\n $response = $this->callAPI($prompt);\n\n return $this->parseGeneratedContent($response, $topic);\n }\n\n /**\n * Improve existing content\n */\n public function improveContent(string $content, string $action = 'improve'): array\n {\n $prompts = [\n 'improve' => \"Improve the following blog content. Make it more engaging, clear, and well-structured while maintaining the original message. Fix any grammatical errors and improve the flow:\\n\\n{$content}\\n\\nProvide only the improved content, no explanations.\",\n\n 'expand' => \"Expand the following content with more details, examples, and explanations. Add relevant information to make it more comprehensive. Double the length while keeping it focused:\\n\\n{$content}\\n\\nProvide only the expanded content.\",\n\n 'summarize' => \"Summarize the following content into a concise version that retains the key points. Reduce it to about 30% of the original length:\\n\\n{$content}\\n\\nProvide only the summarized content.\",\n\n 'seo' => \"Optimize the following content for SEO. Add relevant keywords naturally, improve headings for better structure, and make it more search-engine friendly while maintaining readability:\\n\\n{$content}\\n\\nProvide only the optimized content.\",\n ];\n\n $prompt = $prompts[$action] ?? $prompts['improve'];\n\n $response = $this->callAPI($prompt);\n\n return [\n 'content' => $this->cleanContent($response),\n ];\n }\n\n /**\n * Generate SEO metadata\n */\n public function generateMetadata(string $title, string $content): array\n {\n $prompt = \"Based on this blog post, generate SEO metadata:\n\nTitle: {$title}\nContent (excerpt): \" . substr(strip_tags($content), 0, 500) . \"\n\nProvide in this exact JSON format:\n{\n \\\"meta_title\\\": \\\"SEO optimized title under 60 chars\\\",\n \\\"meta_description\\\": \\\"Compelling meta description under 160 chars\\\",\n \\\"keywords\\\": \\\"keyword1, keyword2, keyword3, keyword4, keyword5\\\"\n}\n\nReturn ONLY the JSON, no other text.\";\n\n $response = $this->callAPI($prompt);\n\n try {\n $data = json_decode($response, true);\n if ($data) {\n return $data;\n }\n } catch (\\Exception $e) {\n // Fall through to defaults\n }\n\n return [\n 'meta_title' => substr($title, 0, 60),\n 'meta_description' => substr(strip_tags($content), 0, 160),\n 'keywords' => '',\n ];\n }\n\n /**\n * Generate tags from content\n */\n public function generateTags(string $title, string $content): array\n {\n $prompt = \"Analyze this blog post and suggest 5-8 relevant tags (single words or short phrases).\n\nTitle: {$title}\nContent: \" . substr(strip_tags($content), 0, 1000) . \"\n\nReturn ONLY a comma-separated list of tags, nothing else. Example: technology, artificial intelligence, machine learning, data science\";\n\n $response = $this->callAPI($prompt);\n\n $tags = array_filter(array_map('trim', explode(',', $response)));\n return array_slice($tags, 0, 8);\n }\n\n /**\n * Build generation prompt\n */\n private function buildGenerationPrompt(string $topic, string $tone, string $wordCount, string $keywords): string\n {\n $toneInstructions = [\n 'professional' => 'Use a professional, authoritative tone. Be informative and credible.',\n 'casual' => 'Use a casual, conversational tone. Be friendly and approachable.',\n 'friendly' => 'Use a warm, friendly tone. Be encouraging and supportive.',\n 'authoritative' => 'Use an expert, authoritative tone. Demonstrate deep knowledge.',\n 'humorous' => 'Use a light, humorous tone where appropriate. Keep it engaging and fun.',\n ];\n\n $toneGuide = $toneInstructions[$tone] ?? $toneInstructions['professional'];\n\n $keywordGuide = $keywords ? \"\\n\\nIncorporate these SEO keywords naturally: {$keywords}\" : '';\n\n return \"Write a comprehensive blog post about: {$topic}\n\nREQUIREMENTS:\n- Word count: {$wordCount} words\n- {$toneGuide}\n- Use proper HTML formatting with

,

,

,