Download config.py from ttttim3/agents-course-final-assignment: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/ttttim3/agents-course-final-assignment/resolve/main/config.py
- Command line
-
hf download hf://spaces/ttttim3/agents-course-final-assignment/config.py
-
curl -L -o config.py https://huggingface.co/spaces/ttttim3/agents-course-final-assignment/resolve/main/config.py
1.27 kB
| """Model / API configuration. | |
| The NaviGator key is read from the NAVIGATOR_TOOLKIT_API_KEY environment variable. | |
| On macOS it falls back to the Keychain item "navigator-toolkit", so the key never | |
| has to be written into code or config files. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import subprocess | |
| from functools import lru_cache | |
| from openai import OpenAI | |
| NAVIGATOR_BASE_URL = os.getenv("NAVIGATOR_API_BASE_URL", "https://api.navigator.ai.ufl.edu/v1") | |
| MAIN_MODEL = os.getenv("AGENT_MODEL", "gpt-oss-120b") | |
| def navigator_api_key() -> str: | |
| key = os.getenv("NAVIGATOR_TOOLKIT_API_KEY") | |
| if key: | |
| return key | |
| try: | |
| key = subprocess.run( | |
| ["security", "find-generic-password", "-a", os.getenv("USER", ""), "-s", "navigator-toolkit", "-w"], | |
| capture_output=True, | |
| text=True, | |
| check=True, | |
| ).stdout.strip() | |
| except Exception: | |
| key = "" | |
| if not key: | |
| raise RuntimeError("Set NAVIGATOR_TOOLKIT_API_KEY (or store it in the macOS Keychain as 'navigator-toolkit').") | |
| return key | |
| def navigator_client(timeout: float = 300) -> OpenAI: | |
| return OpenAI(base_url=NAVIGATOR_BASE_URL, api_key=navigator_api_key(), timeout=timeout, max_retries=2) | |