{"repo": "abdelmonem-dev/ai-chatbot", "files": {"app/Http/Controllers/AIChatbotController.php": {"1173ca724245b7308b8075ae987195578094ad1e": {"t": 1785746155.8322701, "n": 2346, "h": "7bb227e9820d796b", "c": "client = new Client();\n $this->apiKey = config('services.ai.api_key');\n }\n\n public function chat(Request $request)\n {\n $userMessage = $request->input('message');\n\n // If the API key is not set, send a default response\n if (!$this->apiKey) {\n return $this->sendFallbackResponse('Hello'); // Return fallback response directly\n }\n\n try {\n // Make a request to the AI API (e.g., DeepSeek or OpenAI)\n $response = $this->client->post('https://api.deepseek.com', [\n 'headers' => [\n 'Authorization' => 'Bearer ' . $this->apiKey,\n 'Content-Type' => 'application/json',\n ],\n 'json' => [\n 'model' => 'deepseek-chat', // Replace with the correct model name\n 'messages' => [ // Corrected 'message' key to 'messages'\n ['role' => 'user', 'content' => $userMessage], // Send the user's message\n ],\n ],\n ]);\n\n $responseData = json_decode($response->getBody(), true);\n\n // Return the AI's response\n return response()->json([\n 'response' => $responseData['choices'][0]['message']['content'],\n ]);\n } catch (\\Exception $e) {\n // Log the error for debugging purposes\n Log::error('AI API request failed: ' . $e->getMessage());\n\n // Fallback message when API fails\n return $this->sendFallbackResponse('Hello'); // Default fallback message\n }\n }\n\n // Helper method to return a fallback response\n private function sendFallbackResponse($message)\n {\n $responseData = [\n 'candidates' => [\n [\n 'content' => [\n 'parts' => [\n ['text' => $message]\n ]\n ]\n ]\n ]\n ];\n\n return response()->json($responseData);\n }\n}\n"}, "517deb942f4bd6603ffa34cbc3c29b64d9d26fb2": {"t": 1785760258.755598, "n": 2346, "h": "7bb227e9820d796b", "c": "client = new Client();\n $this->apiKey = config('services.ai.api_key');\n }\n\n public function chat(Request $request)\n {\n $userMessage = $request->input('message');\n\n // If the API key is not set, send a default response\n if (!$this->apiKey) {\n return $this->sendFallbackResponse('Hello'); // Return fallback response directly\n }\n\n try {\n // Make a request to the AI API (e.g., DeepSeek or OpenAI)\n $response = $this->client->post('https://api.deepseek.com', [\n 'headers' => [\n 'Authorization' => 'Bearer ' . $this->apiKey,\n 'Content-Type' => 'application/json',\n ],\n 'json' => [\n 'model' => 'deepseek-chat', // Replace with the correct model name\n 'messages' => [ // Corrected 'message' key to 'messages'\n ['role' => 'user', 'content' => $userMessage], // Send the user's message\n ],\n ],\n ]);\n\n $responseData = json_decode($response->getBody(), true);\n\n // Return the AI's response\n return response()->json([\n 'response' => $responseData['choices'][0]['message']['content'],\n ]);\n } catch (\\Exception $e) {\n // Log the error for debugging purposes\n Log::error('AI API request failed: ' . $e->getMessage());\n\n // Fallback message when API fails\n return $this->sendFallbackResponse('Hello'); // Default fallback message\n }\n }\n\n // Helper method to return a fallback response\n private function sendFallbackResponse($message)\n {\n $responseData = [\n 'candidates' => [\n [\n 'content' => [\n 'parts' => [\n ['text' => $message]\n ]\n ]\n ]\n ]\n ];\n\n return response()->json($responseData);\n }\n}\n"}}, "README.md": {"1173ca724245b7308b8075ae987195578094ad1e": {"t": 1786067734.6183357, "n": 3969, "h": "b089b29d45cd66ea", "c": "

šŸ¤– AI Chatbot Web Application

\n\n

\n A chatbot web application built with Laravel (backend) and JavaScript (frontend). The chatbot integrates with external AI APIs (e.g., OpenAI, DeepSeek) to provide real-time, intelligent responses. It supports features like file uploads, message history, and fallback responses for a seamless user experience.\n

\n\n---\n\n## ✨ Features\n\n
\n
\n

Real-time Chat

\n

Instant messaging with AI-powered responses.

\n
\n
\n

File Upload

\n

Upload images and other files during conversations.

\n
\n
\n

AI Integration

\n

Connects with third-party AI services for intelligent responses.

\n
\n
\n

Fallback Responses

\n

Default responses (\"Hello\") in case of API failure.

\n
\n
\n

Modern UI

\n

Sleek and user-friendly chat interface.

\n
\n
\n\n---\n\n## šŸ› ļø Prerequisites\n\nBefore you begin, ensure you have the following installed:\n```\n- PHP 8.0 or higher\n- Composer\n- Node.js (for frontend dependencies)\n- vite\n- A valid AI API key (e.g., OpenAI, DeepSeek)\n```\n\n\n## šŸš€ Installation\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/your-username/ai-chatbot.git\ncd ai-chatbot\nRun HTML\n2. Install Backend Dependencies\nInstall PHP dependencies using Composer:\n```\ncomposer install\n```\n4. Install Frontend Dependencies\nInstall Node.js dependencies:\n```\nnpm install\n```\n\n4. Configure Environment\nCopy the .env.example file to .env and update it with your API key and other settings:\ncp .env.example .env\nEdit the .env file:\n```\nAI_API_KEY=your-api-key-here\nAI_API_URL=https://api.deepseek.com/v1/chat/completions\n```\n6. Generate Application Key\nGenerate a unique application key:\n```\nphp artisan key:generate\n```\n8. Run Database Migrations \n```\nphp artisan migrate\n```\n\n9. Start the Application\n```\nphp artisan serve\n```\nVisit http://127.0.0.1:8000 in your browser to access the application.\n\nšŸ’” Usage\nChatting with the Bot\nOpen the application in your browser.\n\nType your message in the chat input field and press Enter or click the Send button.\n\nThe bot will process your message and respond instantly.\n\nFile Upload\nYou can upload files (e.g., images) during the chat. The file will be sent to the backend for processing.\n\nAPI Integration\nThe backend uses Guzzle to interact with the AI API.\n```\nIf the API fails, the chatbot will return a fallback response (\"Hello\").\n```\nšŸ“‚ Project Structure\nBackend (Laravel)\napp/Http/Controllers/AIChatbotController.php: Handles chatbot logic and API integration.\n\nroutes/web.php: Defines routes for the chatbot functionality.\n\n.env: Stores environment variables, including the AI API key.\n```\nFrontend (JavaScript/HTML/CSS)\nfor the front end, I used a depository for Patrik Persson\n\nPatrik Persson : ai-chatbot-html-css-javascript \n```\n\nšŸ¤ Contributing\nContributions are welcome! Please follow these steps:\n\nFork the repository.\n\nCreate a new branch (git checkout -b feature/YourFeatureName).\n\nCommit your changes (git commit -m 'Add some feature').\n\nPush to the branch (git push origin feature/YourFeatureName).\n\nOpen a pull request.\n\nšŸ“„ License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n\n"}}}}