bees-knees/prophet/config.py
Marty Oehme 4ef2ce14d6
Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled
feat: Allow setting port as PORT env var
This seems important for render hosting, as described in
https://render.com/docs/web-services#port-binding.
2025-07-22 06:09:09 +02:00

53 lines
1.1 KiB
Python

import os
# Load environment variables from .env
from dataclasses import dataclass
from dotenv import load_dotenv
_ = load_dotenv()
@dataclass
class AppConfig:
PORT: int
@classmethod
def from_env(cls) -> "AppConfig":
PORT = os.getenv("PORT", "8000")
return cls(PORT=int(PORT))
@dataclass
class AiConfig:
API_KEY: str
@classmethod
def from_env(cls) -> "AiConfig":
API_KEY = os.getenv("GROQ_API_KEY", "")
if not API_KEY:
raise ValueError(f"{API_KEY} cannot be empty")
return cls(**{"API_KEY": API_KEY})
@dataclass
class SupaConfig:
URL: str
KEY: str
TABLE: str
@classmethod
def from_env(cls) -> "SupaConfig":
URL = os.getenv("SUPABASE_URL", "")
KEY = os.getenv("SUPABASE_KEY", "")
TABLE = os.getenv("SUPABASE_TABLE", "improvements")
values: dict[str, str] = {"URL": URL, "KEY": KEY, "TABLE": TABLE}
for name, val in values.items():
if not val:
raise ValueError(f"SUPABASE_{name} cannot be empty")
return cls(**values)