nothing / app /config.py
devarshia5's picture
Upload 25 files
a5f2c4b verified
Raw
History Blame Contribute Delete
2.16 kB
"""Config for the Antaram CLI wrapper (no model API; auth + Postgres are env-driven)."""
from __future__ import annotations
import os
from dotenv import load_dotenv
load_dotenv()
def _int_env(name: str, default: int) -> int:
raw = os.environ.get(name)
if raw is None:
return default
raw = raw.split("#")[0].strip() # tolerate inline comments
try:
return int(raw)
except ValueError:
return default
# Legacy single gateway key (kept for back-compat; real auth is API keys in Postgres).
PROXY_API_KEY = os.environ.get("PROXY_API_KEY", "").strip()
# --- Postgres (Aiven). Paste the full connection string into .env as DATABASE_URL. ---
DATABASE_URL = os.environ.get("DATABASE_URL", "").strip()
# --- Superadmin login ---
SUPERADMIN_USER = os.environ.get("SUPERADMIN_USER", "superadmin").strip()
SUPERADMIN_PASSWORD = os.environ.get("SUPERADMIN_PASSWORD", "").strip()
# --- Expiry policy ---
LOGIN_SESSION_TTL_HOURS = _int_env("LOGIN_SESSION_TTL_HOURS", 24) # user/admin login
DEFAULT_API_KEY_TTL_DAYS = _int_env("DEFAULT_API_KEY_TTL_DAYS", 14) # 2 weeks; 0 = lifetime
# --- Access control ---
# If true, /v1/chat/completions requires a valid provider API key.
REQUIRE_API_KEY = os.environ.get("REQUIRE_API_KEY", "true").split("#")[0].strip().lower() == "true"
# --- Response cap (prevent token outage on runaway generations) ---
MAX_RESPONSE_CHARS = _int_env("MAX_RESPONSE_CHARS", 8000) # ~2k tokens
# --- Per-user isolation: each API key gets its own home dir under here ---
HOMES_BASE = os.environ.get("ANTARAM_HOMES", "").strip() # blank -> ~/.antaram_homes
# --- Attachments: ephemeral tmp (HF free tier has no persistent disk) ---
ATTACH_TMP_DIR = os.environ.get("ATTACH_TMP_DIR", "").strip() # blank -> system temp (/tmp on Linux)
# --- Hidden web console path (admin-only) ---
# The chat GUI is NOT served at "/". It is served ONLY at this secret slug, which
# should be set to a long, unguessable value via the CONSOLE_PATH env/secret and
# shared with no one but the admin. Leading/trailing slashes are ignored.
CONSOLE_PATH = os.environ.get("CONSOLE_PATH", "console").strip().strip("/")