{"repo": "andrecarlos26/isat", "files": {"backend/model_analysis_module/explanation.py": {"be011ad79b61e3311fd353314ce0f423f99193d7": {"t": 1786068457.6330802, "n": 1821, "h": "954fe7db5b7855ee", "c": "import os\r\nimport requests\r\nimport json\r\n\r\nOPENROUTER_API_KEY = os.getenv(\"OPENROUTER_API_KEY\")\r\nOPENROUTER_URL = \"https://openrouter.ai/api/v1/chat/completions\"\r\n\r\nBASE_PROMPT = \"\"\"Below is information about the decision-making process of a Multi-Layer Perceptron (MLP) model, which attempts to predict how long it will take before system memory is exhausted.\r\n\r\nWrite a human-readable explanation of how the model arrives at its predictions. The explanation should be suitable for system administrators and include the following:\r\n\r\nA high-level overview of the model’s decision-making process (e.g., how input features are processed and how predictions are generated)\r\nWhether the model appears to be making correct predictions, based on available metrics\r\nAny evidence of bias or systematic errors in the model’s behavior\r\nConfidence level or uncertainty in its predictions\r\nStrategic implications for system management or resource planning based on the model’s outputs\r\n\r\nThe explanation should avoid technical jargon where possible and focus on helping human operators make informed decisions using the model’s outputs.\"\"\"\r\n\r\ndef get_openrouter_explanation(summary: str) -> str:\r\n \"\"\"\r\n Sends the summary + base prompt to OpenRouter and returns the explanatory text.\r\n \"\"\"\r\n prompt = f\"{BASE_PROMPT}\\n\\n{summary}\"\r\n resp = requests.post(\r\n OPENROUTER_URL,\r\n headers={\r\n \"Authorization\": f\"Bearer {OPENROUTER_API_KEY}\",\r\n \"Content-Type\": \"application/json; charset=utf-8\"\r\n },\r\n data=json.dumps({\r\n \"model\": \"deepseek/deepseek-chat-v3-0324:free\",\r\n \"messages\": [{\"role\": \"user\", \"content\": prompt}]\r\n })\r\n )\r\n resp.raise_for_status()\r\n data = resp.json()\r\n return data[\"choices\"][0][\"message\"][\"content\"]\r\n"}}}}