Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/abdelmonem-dev_ai-chatbot.json
T

1 line
5.1 KiB
JSON

{"repo": "abdelmonem-dev/ai-chatbot", "files": {"app/Http/Controllers/AIChatbotController.php": {"1173ca724245b7308b8075ae987195578094ad1e": {"t": 1785746155.8322701, "n": 2346, "h": "7bb227e9820d796b", "c": "<?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse GuzzleHttp\\Client;\nuse Illuminate\\Support\\Facades\\Log;\n\nclass AIChatbotController extends Controller\n{\n protected $client;\n protected $apiKey;\n\n public function __construct()\n {\n $this->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": "<?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse GuzzleHttp\\Client;\nuse Illuminate\\Support\\Facades\\Log;\n\nclass AIChatbotController extends Controller\n{\n protected $client;\n protected $apiKey;\n\n public function __construct()\n {\n $this->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"}}}}