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

1 line
1.9 KiB
JSON

{"repo": "anthonyhernandez5150/quicksum", "files": {"ai.py": {"628788038d0dac3b4f6374d0d260deef1e35e457": {"t": 1785674364.2018306, "n": 1653, "h": "496a95a93abd59ad", "c": "import os\nimport requests\nfrom dotenv import load_dotenv\n\nload_dotenv()\nOPENROUTER_API_KEY = os.environ.get(\"OPENROUTER_API_KEY\")\n\ndef call_ai_api(prompt):\n \"\"\"\n Call the OpenRouter AI API to get a response for the given prompt.\n \n Args:\n prompt (str): The prompt to send to the AI model.\n \n Returns:\n str: The AI's response.\n \n Raises:\n ValueError: If OPENROUTER_API_KEY is not set in the environment.\n Exception: For other errors during the API call.\n \"\"\"\n if not OPENROUTER_API_KEY:\n raise ValueError(\"OPENROUTER_API_KEY is not set in the environment.\")\n\n url = \"https://openrouter.ai/api/v1/chat/completions\"\n headers = {\n \"Authorization\": f\"Bearer {OPENROUTER_API_KEY}\",\n \"Content-Type\": \"application/json\"\n }\n data = {\n \"model\": \"openai/gpt-3.5-turbo\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": (\n \"You are an expert summarizer. Summarize the user's note in 2-3 sentences. \"\n \"Only return the summary, not the original text.\"\n )\n },\n {\"role\": \"user\", \"content\": prompt}\n ]\n }\n\n response = requests.post(url, headers=headers, json=data)\n try:\n response.raise_for_status()\n except requests.exceptions.HTTPError:\n print(\"API Error:\", response.text) # This will show the real error in your terminal\n raise\n result = response.json()\n return result[\"choices\"][0][\"message\"][\"content\"]\n\n# Example usage\nif __name__ == \"__main__\":\n print(\"API KEY:\", OPENROUTER_API_KEY)"}}}}