Spaces:
Running on Zero
Running on Zero
Download config/settings.py from Catalna/ginchiee-bot: direct link, hf CLI and curl.
- Browser
- Download file 3.68 kB
-
https://huggingface.co/spaces/Catalna/ginchiee-bot/resolve/main/config/settings.py
- Command line
-
hf download hf://spaces/Catalna/ginchiee-bot/config/settings.py
-
curl -L -o settings.py https://huggingface.co/spaces/Catalna/ginchiee-bot/resolve/main/config/settings.py
3.68 kB
| """ | |
| config/settings.py | |
| Centralized configuration loader. | |
| Every required credential is validated at import time so the process fails | |
| loudly on startup instead of silently behaving differently in production. | |
| """ | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def _require(name: str, *aliases: str) -> str: | |
| """Return the first non-empty env var among name and aliases.""" | |
| for candidate in (name, *aliases): | |
| value = os.getenv(candidate) | |
| if value: | |
| return value | |
| raise KeyError( | |
| f"Neither {name} nor any of its aliases {aliases} is set in the environment. " | |
| "Set it in .env (local) or as a Space Secret (Hugging Face)." | |
| ) | |
| # ββ Telegram ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| TELEGRAM_BOT_TOKEN: str = _require("TELEGRAM_BOT_TOKEN", "BOT_TOKEN") | |
| # ββ Gemini βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| GEMINI_API_KEY: str = _require("GEMINI_API_KEY", "GEMINI_KEY") | |
| GEMINI_MODEL: str = os.getenv("GEMINI_MODEL", "gemini-flash-lite-latest") | |
| # Generation parameters. The defaults previously produced flat, formal, | |
| # over-long replies; these bias the model toward short, warm, chatty output. | |
| AI_TEMPERATURE: float = float(os.getenv("AI_TEMPERATURE", "0.95")) | |
| AI_TOP_P: float = float(os.getenv("AI_TOP_P", "0.95")) | |
| AI_MAX_OUTPUT_TOKENS: int = int(os.getenv("AI_MAX_OUTPUT_TOKENS", "220")) | |
| AI_MAX_RETRIES: int = int(os.getenv("AI_MAX_RETRIES", "1")) | |
| # ββ Database ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Postgres connection string, e.g. | |
| # postgresql://user:password@host/dbname?sslmode=require | |
| DATABASE_URL: str = _require("DATABASE_URL") | |
| # ββ Logging βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO") | |
| # ββ App βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| APP_TIMEZONE: str = "Asia/Jakarta" | |
| # Optional allow-list of Telegram user ids. When set, only these users may talk | |
| # to the bot; leave empty to allow everyone. | |
| _ALLOWED_IDS = os.getenv("ALLOWED_USER_IDS", "").strip() | |
| ALLOWED_USER_IDS: frozenset[int] = ( | |
| frozenset(int(part.strip()) for part in _ALLOWED_IDS.split(",") if part.strip()) | |
| if _ALLOWED_IDS | |
| else frozenset() | |
| ) | |
| # ββ Personality βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| BOT_NAME: str = "Ginchiee" | |
| BOT_PERSONALITY: str = "playful_supportive" | |
| # Style guardrails applied to every user-facing reply. | |
| MAX_REPLY_SENTENCES: int = 3 | |
| MAX_REPLY_EMOJI: int = 2 | |
| MAX_REPLY_CHARS: int = 450 | |
| # ββ Nutrition βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| WATER_TARGET_ML: int = 2500 | |
| MAX_CONVERSATION_HISTORY: int = 10 | |