ttttim3's picture
Update agent code
90d0b3d verified
Raw History Blame Contribute Delete
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")
@lru_cache(maxsize=1)
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)