{"repo": "ashikurweb/event-management", "files": {"config/services.php": {"6862c0d383b33e1f066fa016ccb544b4a037347e": {"t": 1785745780.1322808, "n": 5365, "h": "f37c248ac0df0217", "c": " [\n 'key' => env('POSTMARK_API_KEY'),\n ],\n\n 'resend' => [\n 'key' => env('RESEND_API_KEY'),\n ],\n\n 'ses' => [\n 'key' => env('AWS_ACCESS_KEY_ID'),\n 'secret' => env('AWS_SECRET_ACCESS_KEY'),\n 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),\n ],\n\n 'slack' => [\n 'notifications' => [\n 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),\n 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),\n ],\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Social Authentication Services\n |--------------------------------------------------------------------------\n |\n | Configuration for social login providers (Google, Facebook, GitHub)\n |\n */\n\n 'google' => [\n 'client_id' => env('GOOGLE_CLIENT_ID'),\n 'client_secret' => env('GOOGLE_CLIENT_SECRET'),\n 'redirect' => env('GOOGLE_REDIRECT_URI', env('APP_URL') . '/auth/google/callback'),\n ],\n\n 'facebook' => [\n 'client_id' => env('FACEBOOK_CLIENT_ID'),\n 'client_secret' => env('FACEBOOK_CLIENT_SECRET'),\n 'redirect' => env('FACEBOOK_REDIRECT_URI', env('APP_URL') . '/auth/facebook/callback'),\n ],\n\n 'github' => [\n 'client_id' => env('GITHUB_CLIENT_ID'),\n 'client_secret' => env('GITHUB_CLIENT_SECRET'),\n 'redirect' => env('GITHUB_REDIRECT_URI', env('APP_URL') . '/auth/github/callback'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | OpenAI Configuration\n |--------------------------------------------------------------------------\n |\n | Configuration for OpenAI API used by AI Assistant\n |\n */\n\n 'openai' => [\n 'api_key' => env('OPENAI_API_KEY'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Groq AI Configuration (FREE TIER AVAILABLE)\n |--------------------------------------------------------------------------\n |\n | Groq provides fast AI inference with a generous free tier.\n | Get your free API key: https://console.groq.com/keys\n |\n */\n\n 'groq' => [\n 'api_key' => env('GROQ_API_KEY'),\n 'enabled' => env('GROQ_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Qwen 2.5 Coder Configuration (BEST FOR CODING)\n |--------------------------------------------------------------------------\n |\n | Qwen 2.5 Coder is specialized for code generation, SQL, migrations,\n | REST API development, and database design.\n | Recommended for: Laravel migrations, controllers, SQL queries, APIs\n |\n | Get API key from:\n | - OpenRouter: https://openrouter.ai/ (Recommended)\n | - Hugging Face: https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct\n |\n */\n\n 'qwen' => [\n 'api_key' => env('QWEN_API_KEY'),\n 'api_url' => env('QWEN_API_URL', 'https://openrouter.ai/api/v1/chat/completions'),\n 'model' => env('QWEN_MODEL', 'qwen/qwen-2.5-coder-32b-instruct'),\n 'enabled' => env('QWEN_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | DeepSeek R1 Configuration (BEST FOR REASONING)\n |--------------------------------------------------------------------------\n |\n | DeepSeek R1 provides GPT-4 level reasoning for complex problems,\n | database design, event-driven architecture, and system design.\n | Recommended for: Complex reasoning, architecture, deep analysis\n |\n | Get API key from:\n | - DeepSeek Platform: https://platform.deepseek.com/\n | - OpenRouter: https://openrouter.ai/ (Alternative)\n |\n */\n\n 'deepseek' => [\n 'api_key' => env('DEEPSEEK_API_KEY'),\n 'api_url' => env('DEEPSEEK_API_URL', 'https://api.deepseek.com/v1/chat/completions'),\n 'model' => env('DEEPSEEK_MODEL', 'deepseek-r1-14b'),\n 'enabled' => env('DEEPSEEK_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | OpenRouter Configuration (SUPPORTS BOTH MODELS)\n |--------------------------------------------------------------------------\n |\n | OpenRouter provides access to multiple AI models including\n | Qwen 2.5 Coder and DeepSeek R1 through a single API.\n | Recommended for: Easy access to both models\n |\n | Get API key from: https://openrouter.ai/\n |\n */\n\n 'openrouter' => [\n 'api_key' => env('OPENROUTER_API_KEY'),\n 'api_url' => env('OPENROUTER_API_URL', 'https://openrouter.ai/api/v1/chat/completions'),\n 'model' => env('OPENROUTER_MODEL', 'qwen/qwen-2.5-coder-32b-instruct'),\n 'enabled' => env('OPENROUTER_ENABLED', false),\n ],\n\n];\n"}, "89f4025116d9919e9f91cc0e74c3d40953af8561": {"t": 1785756462.320785, "n": 5365, "h": "f37c248ac0df0217", "c": " [\n 'key' => env('POSTMARK_API_KEY'),\n ],\n\n 'resend' => [\n 'key' => env('RESEND_API_KEY'),\n ],\n\n 'ses' => [\n 'key' => env('AWS_ACCESS_KEY_ID'),\n 'secret' => env('AWS_SECRET_ACCESS_KEY'),\n 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),\n ],\n\n 'slack' => [\n 'notifications' => [\n 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),\n 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),\n ],\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Social Authentication Services\n |--------------------------------------------------------------------------\n |\n | Configuration for social login providers (Google, Facebook, GitHub)\n |\n */\n\n 'google' => [\n 'client_id' => env('GOOGLE_CLIENT_ID'),\n 'client_secret' => env('GOOGLE_CLIENT_SECRET'),\n 'redirect' => env('GOOGLE_REDIRECT_URI', env('APP_URL') . '/auth/google/callback'),\n ],\n\n 'facebook' => [\n 'client_id' => env('FACEBOOK_CLIENT_ID'),\n 'client_secret' => env('FACEBOOK_CLIENT_SECRET'),\n 'redirect' => env('FACEBOOK_REDIRECT_URI', env('APP_URL') . '/auth/facebook/callback'),\n ],\n\n 'github' => [\n 'client_id' => env('GITHUB_CLIENT_ID'),\n 'client_secret' => env('GITHUB_CLIENT_SECRET'),\n 'redirect' => env('GITHUB_REDIRECT_URI', env('APP_URL') . '/auth/github/callback'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | OpenAI Configuration\n |--------------------------------------------------------------------------\n |\n | Configuration for OpenAI API used by AI Assistant\n |\n */\n\n 'openai' => [\n 'api_key' => env('OPENAI_API_KEY'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Groq AI Configuration (FREE TIER AVAILABLE)\n |--------------------------------------------------------------------------\n |\n | Groq provides fast AI inference with a generous free tier.\n | Get your free API key: https://console.groq.com/keys\n |\n */\n\n 'groq' => [\n 'api_key' => env('GROQ_API_KEY'),\n 'enabled' => env('GROQ_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Qwen 2.5 Coder Configuration (BEST FOR CODING)\n |--------------------------------------------------------------------------\n |\n | Qwen 2.5 Coder is specialized for code generation, SQL, migrations,\n | REST API development, and database design.\n | Recommended for: Laravel migrations, controllers, SQL queries, APIs\n |\n | Get API key from:\n | - OpenRouter: https://openrouter.ai/ (Recommended)\n | - Hugging Face: https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct\n |\n */\n\n 'qwen' => [\n 'api_key' => env('QWEN_API_KEY'),\n 'api_url' => env('QWEN_API_URL', 'https://openrouter.ai/api/v1/chat/completions'),\n 'model' => env('QWEN_MODEL', 'qwen/qwen-2.5-coder-32b-instruct'),\n 'enabled' => env('QWEN_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | DeepSeek R1 Configuration (BEST FOR REASONING)\n |--------------------------------------------------------------------------\n |\n | DeepSeek R1 provides GPT-4 level reasoning for complex problems,\n | database design, event-driven architecture, and system design.\n | Recommended for: Complex reasoning, architecture, deep analysis\n |\n | Get API key from:\n | - DeepSeek Platform: https://platform.deepseek.com/\n | - OpenRouter: https://openrouter.ai/ (Alternative)\n |\n */\n\n 'deepseek' => [\n 'api_key' => env('DEEPSEEK_API_KEY'),\n 'api_url' => env('DEEPSEEK_API_URL', 'https://api.deepseek.com/v1/chat/completions'),\n 'model' => env('DEEPSEEK_MODEL', 'deepseek-r1-14b'),\n 'enabled' => env('DEEPSEEK_ENABLED', false),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | OpenRouter Configuration (SUPPORTS BOTH MODELS)\n |--------------------------------------------------------------------------\n |\n | OpenRouter provides access to multiple AI models including\n | Qwen 2.5 Coder and DeepSeek R1 through a single API.\n | Recommended for: Easy access to both models\n |\n | Get API key from: https://openrouter.ai/\n |\n */\n\n 'openrouter' => [\n 'api_key' => env('OPENROUTER_API_KEY'),\n 'api_url' => env('OPENROUTER_API_URL', 'https://openrouter.ai/api/v1/chat/completions'),\n 'model' => env('OPENROUTER_MODEL', 'qwen/qwen-2.5-coder-32b-instruct'),\n 'enabled' => env('OPENROUTER_ENABLED', false),\n ],\n\n];\n"}, "b3fe80ef5625eda51904d4736ea798b47ccee2d9": {"t": 1785756463.502083, "n": 2829, "h": "fd881edc7e433019", "c": " [\n 'key' => env('POSTMARK_API_KEY'),\n ],\n\n 'resend' => [\n 'key' => env('RESEND_API_KEY'),\n ],\n\n 'ses' => [\n 'key' => env('AWS_ACCESS_KEY_ID'),\n 'secret' => env('AWS_SECRET_ACCESS_KEY'),\n 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),\n ],\n\n 'slack' => [\n 'notifications' => [\n 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),\n 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),\n ],\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Social Authentication Services\n |--------------------------------------------------------------------------\n |\n | Configuration for social login providers (Google, Facebook, GitHub)\n |\n */\n\n 'google' => [\n 'client_id' => env('GOOGLE_CLIENT_ID'),\n 'client_secret' => env('GOOGLE_CLIENT_SECRET'),\n 'redirect' => env('GOOGLE_REDIRECT_URI', env('APP_URL') . '/auth/google/callback'),\n ],\n\n 'facebook' => [\n 'client_id' => env('FACEBOOK_CLIENT_ID'),\n 'client_secret' => env('FACEBOOK_CLIENT_SECRET'),\n 'redirect' => env('FACEBOOK_REDIRECT_URI', env('APP_URL') . '/auth/facebook/callback'),\n ],\n\n 'github' => [\n 'client_id' => env('GITHUB_CLIENT_ID'),\n 'client_secret' => env('GITHUB_CLIENT_SECRET'),\n 'redirect' => env('GITHUB_REDIRECT_URI', env('APP_URL') . '/auth/github/callback'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | OpenAI Configuration\n |--------------------------------------------------------------------------\n |\n | Configuration for OpenAI API used by AI Assistant\n |\n */\n\n 'openai' => [\n 'api_key' => env('OPENAI_API_KEY'),\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Groq AI Configuration (FREE TIER AVAILABLE)\n |--------------------------------------------------------------------------\n |\n | Groq provides fast AI inference with a generous free tier.\n | Get your free API key: https://console.groq.com/keys\n |\n */\n\n 'groq' => [\n 'api_key' => env('GROQ_API_KEY'),\n 'enabled' => env('GROQ_ENABLED', false),\n ],\n\n];\n"}, "f05e97ae2b9dfccd12dd3cb775d4e046ccc5f5ea": {"t": 1785756464.621328, "n": 2013, "h": "2fcf891efd01cfcc", "c": " [\n 'key' => env('POSTMARK_API_KEY'),\n ],\n\n 'resend' => [\n 'key' => env('RESEND_API_KEY'),\n ],\n\n 'ses' => [\n 'key' => env('AWS_ACCESS_KEY_ID'),\n 'secret' => env('AWS_SECRET_ACCESS_KEY'),\n 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),\n ],\n\n 'slack' => [\n 'notifications' => [\n 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),\n 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),\n ],\n ],\n\n /*\n |--------------------------------------------------------------------------\n | Social Authentication Services\n |--------------------------------------------------------------------------\n |\n | Configuration for social login providers (Google, Facebook, GitHub)\n |\n */\n\n 'google' => [\n 'client_id' => env('GOOGLE_CLIENT_ID'),\n 'client_secret' => env('GOOGLE_CLIENT_SECRET'),\n 'redirect' => env('GOOGLE_REDIRECT_URI', env('APP_URL') . '/auth/google/callback'),\n ],\n\n 'facebook' => [\n 'client_id' => env('FACEBOOK_CLIENT_ID'),\n 'client_secret' => env('FACEBOOK_CLIENT_SECRET'),\n 'redirect' => env('FACEBOOK_REDIRECT_URI', env('APP_URL') . '/auth/facebook/callback'),\n ],\n\n 'github' => [\n 'client_id' => env('GITHUB_CLIENT_ID'),\n 'client_secret' => env('GITHUB_CLIENT_SECRET'),\n 'redirect' => env('GITHUB_REDIRECT_URI', env('APP_URL') . '/auth/github/callback'),\n ],\n\n];\n"}, "28f65827eb8f3e921893ab663610c35a95ae6f1b": {"t": 1785756465.7761455, "n": 1039, "h": "db4fafeac1c3e897", "c": " [\n 'key' => env('POSTMARK_API_KEY'),\n ],\n\n 'resend' => [\n 'key' => env('RESEND_API_KEY'),\n ],\n\n 'ses' => [\n 'key' => env('AWS_ACCESS_KEY_ID'),\n 'secret' => env('AWS_SECRET_ACCESS_KEY'),\n 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),\n ],\n\n 'slack' => [\n 'notifications' => [\n 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),\n 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),\n ],\n ],\n\n];\n"}}, "app/Services/AIAssistantService.php": {"6862c0d383b33e1f066fa016ccb544b4a037347e": {"t": 1786068385.1252623, "n": 16930, "h": "3241d35e1213b849", "c": " DeepSeek R1 > OpenRouter > Groq > OpenAI\n \n // 1. Qwen 2.5 Coder (Best for coding tasks)\n if (config('services.qwen.enabled') && !empty(config('services.qwen.api_key'))) {\n $this->provider = 'qwen';\n $this->apiKey = config('services.qwen.api_key');\n $this->apiUrl = config('services.qwen.api_url', 'https://openrouter.ai/api/v1/chat/completions');\n $this->model = config('services.qwen.model', 'qwen/qwen-2.5-coder-32b-instruct');\n }\n // 2. DeepSeek R1 (Best for reasoning)\n elseif (config('services.deepseek.enabled') && !empty(config('services.deepseek.api_key'))) {\n $this->provider = 'deepseek';\n $this->apiKey = config('services.deepseek.api_key');\n $this->apiUrl = config('services.deepseek.api_url', 'https://api.deepseek.com/v1/chat/completions');\n $this->model = config('services.deepseek.model', 'deepseek-r1-14b');\n }\n // 3. OpenRouter (Supports both models)\n elseif (config('services.openrouter.enabled') && !empty(config('services.openrouter.api_key'))) {\n $this->provider = 'openrouter';\n $this->apiKey = config('services.openrouter.api_key');\n $this->apiUrl = config('services.openrouter.api_url', 'https://openrouter.ai/api/v1/chat/completions');\n $this->model = config('services.openrouter.model', 'qwen/qwen-2.5-coder-32b-instruct');\n }\n // 4. Groq (Free alternative)\n elseif (config('services.groq.enabled') && !empty(config('services.groq.api_key'))) {\n $this->provider = 'groq';\n $this->apiKey = config('services.groq.api_key');\n $this->apiUrl = 'https://api.groq.com/openai/v1/chat/completions';\n $this->model = 'llama-3.1-8b-instant'; // Fast and free\n }\n // 5. OpenAI (Fallback)\n else {\n $this->provider = 'openai';\n $this->apiKey = config('services.openai.api_key');\n $this->apiUrl = 'https://api.openai.com/v1/chat/completions';\n $this->model = 'gpt-3.5-turbo';\n }\n }\n\n /**\n * Get current AI provider and model information\n */\n public function getProviderInfo(): array\n {\n return [\n 'provider' => $this->provider,\n 'model' => $this->model,\n 'is_configured' => !empty($this->apiKey),\n ];\n }\n\n /**\n * Process user message and get AI response\n */\n public function processMessage(string $message, array $context = []): array\n {\n try {\n // Check if API key is configured\n if (empty($this->apiKey)) {\n Log::error('AI Assistant Error: API key not configured for ' . $this->provider);\n return [\n 'success' => false,\n 'response' => 'AI Assistant is not configured. Please contact the administrator.',\n ];\n }\n\n // Get dashboard context\n $dashboardContext = $this->getDashboardContext();\n\n // Build system prompt\n $systemPrompt = $this->buildSystemPrompt($dashboardContext);\n\n // Make API call to AI provider\n $response = $this->callAI($systemPrompt, $message, $context);\n\n // Parse response and extract actions\n $parsedResponse = $this->parseResponse($response, $message);\n\n return [\n 'success' => true,\n 'response' => $parsedResponse['message'],\n 'action' => $parsedResponse['action'] ?? null,\n ];\n } catch (\\Exception $e) {\n $errorMessage = $e->getMessage();\n Log::error('AI Assistant Error: ' . $errorMessage);\n \n // Provide more specific error messages\n if (str_contains($errorMessage, 'insufficient_quota') || str_contains($errorMessage, 'quota')) {\n return [\n 'success' => false,\n 'response' => 'OpenAI API quota has been exceeded. Please check your OpenAI account billing and add credits.',\n ];\n }\n \n if (str_contains($errorMessage, 'invalid_api_key') || str_contains($errorMessage, 'authentication')) {\n return [\n 'success' => false,\n 'response' => 'Invalid API key. Please check the configuration.',\n ];\n }\n \n if (str_contains($errorMessage, 'rate_limit')) {\n return [\n 'success' => false,\n 'response' => 'Rate limit exceeded. Please wait a moment and try again.',\n ];\n }\n \n return [\n 'success' => false,\n 'response' => 'Sorry, I encountered an error. Please try again later. If the problem persists, contact support.',\n ];\n }\n }\n\n /**\n * Get dashboard context (events, statistics, etc.)\n */\n private function getDashboardContext(): array\n {\n $user = Auth::user();\n \n if (!$user) {\n return [];\n }\n\n $events = Event::where('organizer_id', $user->id)\n ->with('category')\n ->orderBy('created_at', 'desc')\n ->limit(10)\n ->get();\n\n $totalEvents = Event::where('organizer_id', $user->id)->count();\n $publishedEvents = Event::where('organizer_id', $user->id)\n ->where('status', 'published')\n ->count();\n $draftEvents = Event::where('organizer_id', $user->id)\n ->where('status', 'draft')\n ->count();\n\n return [\n 'user_name' => $user->name ?? $user->first_name . ' ' . $user->last_name,\n 'total_events' => $totalEvents,\n 'published_events' => $publishedEvents,\n 'draft_events' => $draftEvents,\n 'recent_events' => $events->map(function ($event) {\n return [\n 'id' => $event->id,\n 'title' => $event->title,\n 'status' => $event->status,\n 'start_date' => $event->start_date?->format('Y-m-d H:i'),\n ];\n })->toArray(),\n ];\n }\n\n /**\n * Build system prompt for AI\n */\n private function buildSystemPrompt(array $context): string\n {\n // Base prompt\n $prompt = \"You are an AI assistant for an event management dashboard called EventHub. \";\n $prompt .= \"You help users manage their events, view statistics, navigate the dashboard, \";\n $prompt .= \"and assist with coding tasks including Laravel migrations, SQL queries, REST APIs, \";\n $prompt .= \"and database design.\\n\\n\";\n \n // Add provider-specific instructions\n if ($this->provider === 'qwen' || $this->provider === 'openrouter') {\n $prompt .= \"**You are Qwen 2.5 Coder - Specialized in code generation.**\\n\";\n $prompt .= \"You excel at:\\n\";\n $prompt .= \"- Generating Laravel migrations, controllers, services\\n\";\n $prompt .= \"- Writing complex SQL queries, stored procedures, triggers\\n\";\n $prompt .= \"- Creating REST API endpoints and routes\\n\";\n $prompt .= \"- Database schema design and relationships\\n\";\n $prompt .= \"- Vue.js component generation\\n\";\n $prompt .= \"- Full-stack development tasks\\n\\n\";\n } elseif ($this->provider === 'deepseek') {\n $prompt .= \"**You are DeepSeek R1 - Specialized in advanced reasoning.**\\n\";\n $prompt .= \"You excel at:\\n\";\n $prompt .= \"- Complex problem solving and multi-step reasoning\\n\";\n $prompt .= \"- Advanced database architecture design\\n\";\n $prompt .= \"- Event-driven system architecture\\n\";\n $prompt .= \"- System-level analysis and planning\\n\";\n $prompt .= \"- Creative technical solutions\\n\\n\";\n }\n \n $prompt .= \"Current Dashboard Context:\\n\";\n $prompt .= \"- User: {$context['user_name']}\\n\";\n $prompt .= \"- Total Events: {$context['total_events']}\\n\";\n $prompt .= \"- Published Events: {$context['published_events']}\\n\";\n $prompt .= \"- Draft Events: {$context['draft_events']}\\n\";\n \n if (!empty($context['recent_events'])) {\n $prompt .= \"\\nRecent Events:\\n\";\n foreach ($context['recent_events'] as $event) {\n $prompt .= \"- {$event['title']} (Status: {$event['status']}, ID: {$event['id']})\\n\";\n }\n }\n\n $prompt .= \"\\n\\nAvailable Actions:\\n\";\n $prompt .= \"1. CREATE_EVENT - Navigate to event creation page\\n\";\n $prompt .= \"2. SHOW_EVENTS - Navigate to events list\\n\";\n $prompt .= \"3. SHOW_STATISTICS - Navigate to dashboard\\n\";\n $prompt .= \"4. SHOW_CATEGORIES - Navigate to categories\\n\";\n $prompt .= \"5. SHOW_SPEAKERS - Navigate to speakers\\n\";\n $prompt .= \"6. SHOW_TEAMS - Navigate to teams\\n\";\n\n $prompt .= \"\\n\\nWhen user asks to create an event, respond with: \";\n $prompt .= \"ACTION:CREATE_EVENT\\n\";\n $prompt .= \"When user asks to view events, respond with: ACTION:SHOW_EVENTS\\n\";\n $prompt .= \"When user asks about statistics or dashboard, respond with: ACTION:SHOW_STATISTICS\\n\";\n\n $prompt .= \"\\n\\nFor coding requests (migrations, SQL, APIs):\\n\";\n $prompt .= \"- Provide complete, working code\\n\";\n $prompt .= \"- Follow Laravel and Vue.js best practices\\n\";\n $prompt .= \"- Include proper error handling\\n\";\n $prompt .= \"- Add comments for complex logic\\n\";\n\n $prompt .= \"\\n\\nYour responses should be helpful, concise, and friendly. \";\n $prompt .= \"Always respond in the same language as the user's message. \";\n $prompt .= \"If the user asks in Bengali, respond in Bengali. \";\n $prompt .= \"If the user asks in English, respond in English.\";\n\n return $prompt;\n }\n\n /**\n * Call AI API (supports Qwen, DeepSeek, OpenRouter, Groq, and OpenAI)\n */\n private function callAI(string $systemPrompt, string $userMessage, array $context): array\n {\n if (empty($this->apiKey)) {\n throw new \\Exception('API key not configured for ' . $this->provider);\n }\n\n // Prepare headers\n $headers = [\n 'Content-Type' => 'application/json',\n ];\n\n // Add authorization header\n if ($this->provider === 'openrouter') {\n // OpenRouter requires HTTP-Referer and X-Title headers\n $headers['Authorization'] = 'Bearer ' . $this->apiKey;\n $headers['HTTP-Referer'] = config('app.url');\n $headers['X-Title'] = 'EventHub AI Assistant';\n } else {\n $headers['Authorization'] = 'Bearer ' . $this->apiKey;\n }\n\n // Prepare request payload\n $payload = [\n 'model' => $this->model,\n 'messages' => [\n [\n 'role' => 'system',\n 'content' => $systemPrompt,\n ],\n [\n 'role' => 'user',\n 'content' => $userMessage,\n ],\n ],\n 'temperature' => 0.7,\n ];\n\n // Adjust max_tokens based on provider and task type\n // For coding tasks, allow more tokens\n $isCodingTask = $this->isCodingTask($userMessage);\n $maxTokens = $isCodingTask ? 2000 : 1000;\n $payload['max_tokens'] = $maxTokens;\n\n // Provider-specific adjustments\n if ($this->provider === 'qwen' || $this->provider === 'openrouter') {\n // Qwen models work well with slightly higher temperature for creativity\n $payload['temperature'] = 0.8;\n } elseif ($this->provider === 'deepseek') {\n // DeepSeek R1 benefits from lower temperature for reasoning\n $payload['temperature'] = 0.6;\n }\n\n $response = Http::timeout(60)->withHeaders($headers)->post($this->apiUrl, $payload);\n\n if ($response->failed()) {\n $errorBody = $response->json();\n $errorMessage = $errorBody['error']['message'] ?? $errorBody['message'] ?? $response->body();\n throw new \\Exception($this->provider . ' API request failed: ' . $errorMessage);\n }\n\n return $response->json();\n }\n\n /**\n * Check if the user message is a coding task\n */\n private function isCodingTask(string $message): bool\n {\n $codingKeywords = [\n 'migration', 'sql', 'query', 'controller', 'service', 'api', 'endpoint',\n 'route', 'model', 'schema', 'database', 'table', 'trigger', 'procedure',\n 'function', 'component', 'vue', 'laravel', 'php', 'javascript', 'code',\n 'generate', 'create', 'write', 'build', 'implement'\n ];\n\n $messageLower = strtolower($message);\n foreach ($codingKeywords as $keyword) {\n if (str_contains($messageLower, $keyword)) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Parse AI response and extract actions\n */\n private function parseResponse(array $apiResponse, string $userMessage): array\n {\n $content = $apiResponse['choices'][0]['message']['content'] ?? '';\n \n // Extract action if present\n $action = null;\n if (preg_match('/ACTION:(\\w+)/', $content, $matches)) {\n $actionType = $matches[1];\n $content = preg_replace('/ACTION:\\w+\\s*/', '', $content);\n \n $action = $this->mapActionToRoute($actionType);\n }\n\n // Auto-detect actions from user message if no explicit action\n if (!$action) {\n $action = $this->detectActionFromMessage($userMessage);\n }\n\n return [\n 'message' => trim($content),\n 'action' => $action,\n ];\n }\n\n /**\n * Map action type to route\n */\n private function mapActionToRoute(string $actionType): ?array\n {\n $routes = [\n 'CREATE_EVENT' => [\n 'type' => 'create_event',\n 'url' => '/dashboard/events/create',\n ],\n 'SHOW_EVENTS' => [\n 'type' => 'navigate',\n 'url' => '/dashboard/events',\n ],\n 'SHOW_STATISTICS' => [\n 'type' => 'show_statistics',\n 'url' => '/dashboard',\n ],\n 'SHOW_CATEGORIES' => [\n 'type' => 'navigate',\n 'url' => '/dashboard/categories',\n ],\n 'SHOW_SPEAKERS' => [\n 'type' => 'navigate',\n 'url' => '/dashboard/speakers',\n ],\n 'SHOW_TEAMS' => [\n 'type' => 'navigate',\n 'url' => '/dashboard/teams',\n ],\n ];\n\n return $routes[$actionType] ?? null;\n }\n\n /**\n * Detect action from user message\n */\n private function detectActionFromMessage(string $message): ?array\n {\n $message = strtolower($message);\n\n // Create event\n if (preg_match('/create|new|add|make.*event/i', $message)) {\n return [\n 'type' => 'create_event',\n 'url' => '/dashboard/events/create',\n ];\n }\n\n // Show events\n if (preg_match('/show|view|list|see.*event/i', $message)) {\n return [\n 'type' => 'navigate',\n 'url' => '/dashboard/events',\n ];\n }\n\n // Show statistics/dashboard\n if (preg_match('/statistic|dashboard|overview|summary/i', $message)) {\n return [\n 'type' => 'show_statistics',\n 'url' => '/dashboard',\n ];\n }\n\n // Show categories\n if (preg_match('/categor/i', $message)) {\n return [\n 'type' => 'navigate',\n 'url' => '/dashboard/categories',\n ];\n }\n\n // Show speakers\n if (preg_match('/speaker/i', $message)) {\n return [\n 'type' => 'navigate',\n 'url' => '/dashboard/speakers',\n ];\n }\n\n // Show teams\n if (preg_match('/team/i', $message)) {\n return [\n 'type' => 'navigate',\n 'url' => '/dashboard/teams',\n ];\n }\n\n return null;\n }\n}\n\n"}}}}