Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/ajunabia228_prophethacks2026-proj.json

1 line
2.4 KiB
JSON

{"repo": "ajunabia228/prophethacks2026-proj", "files": {"src/server.py": {"daf3d013843f01da9a9ed92e79a29d8d04edf15f": {"t": 1785674363.8250973, "n": 2134, "h": "9dcac21c56d02d49", "c": "\"\"\"\nRuns a FastAPI server that exposes an endpoint for forecasting probabilities of event outcomes using an OpenAI model. \nThe server receives event details, constructs a prompt, and returns calibrated probability estimates for each outcome in JSON format.\n\nhow to run:\n1. Create a virtual environment and install dependencies: `pip install fastapi uvicorn openai python-dotenv`\n2. Set your OpenRouter API key in a .env file: `OPENROUTER_API_KEY=sk-or-v1-...`\n3. Start the server: `python server.py`\n\nUsage:\n prophet forecast predict --events events.json --agent-url http://localhost:8000/predict -o predictions.json\n\n\nFor Render:\n 1. Create a Render web service with the following settings:\n - Environment: Python 3\n - Build Command: `pip install -r requirements.txt`\n - Start Command: `cd src && uvicorn server:app --host 0.0.0.0 --port $PORT`\n 2. Set the OPENROUTER_API_KEY environment variable in Render's dashboard.\n\n\"\"\"\n\n\nimport os\nfrom dotenv import load_dotenv\nfrom fastapi import FastAPI\n\napp = FastAPI(title=\"ProphetHacks 2026 Forecast Agent\")\n\n# Fix for ENVs not loading when not using our custom CLI setup\n# (make sure you have a .env file with OPENROUTER_API_KEY with your working director [ie: vscode workspace])\nload_dotenv()\nif not os.getenv(\"OPENROUTER_API_KEY\"):\n raise ValueError(\"OPENROUTER_API_KEY not found in environment variables. Please set it in a .env file or your environment.\")\n\n# necessary as envs must be loaded before creating the OpenAI client in my_agent.py\nfrom my_agent import predict\n\n@app.post(\"/predict\")\nasync def predict_endpoint(event: dict):\n \"\"\"Calls the predict function from my_agent.py\"\"\"\n return predict(event)\n\n# Just a simple health check endpoint to verify the server is running\n@app.get(\"/health\")\nasync def health():\n return {\"status\": \"healthy\"}\n\n@app.head(\"/ping\")\nasync def ping_head():\n return\n\n# Run the server with: uvicorn server:app --host\ndef main() -> None:\n import uvicorn\n\n port = int(os.getenv(\"LOCALHOST_PORT\", \"8000\"))\n uvicorn.run(\"server:app\", host=\"0.0.0.0\", port=port, reload=True)\n\nif __name__ == \"__main__\":\n main()"}}}}