Spaces:
Sleeping
Sleeping
[T011+] Env config: uv venv, .env loader, remote Ollama host + model
Browse files- app/config.py: dependency-free .env loader (OLLAMA_HOST/MODEL_ID/MODEL_PROVIDER)
- .env.example committed; .env gitignored (points at remote 192.168.0.233:11434,
MODEL_ID=qwen3.5:4b — qwen2.5:7b absent on host)
- app.py loads .env at startup; tests/conftest.py loads it for test runs
- venv recreated with uv
Co-authored-by: Codex <noreply@openai.com>
- .env.example +12 -0
- app/app.py +4 -0
- app/config.py +38 -0
- tests/conftest.py +9 -0
.env.example
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Refuge — environment configuration. Copy to `.env` (gitignored) and edit.
|
| 2 |
+
# These are read at startup by app/config.py (no python-dotenv dependency).
|
| 3 |
+
|
| 4 |
+
# Ollama server base URL. Leave unset for a local daemon (http://127.0.0.1:11434).
|
| 5 |
+
OLLAMA_HOST=http://127.0.0.1:11434
|
| 6 |
+
|
| 7 |
+
# Model to use. Must be a tool-calling-capable instruct model, <=32B.
|
| 8 |
+
# Spec default is qwen2.5:7b; pick what your Ollama host actually has.
|
| 9 |
+
MODEL_ID=qwen2.5:7b
|
| 10 |
+
|
| 11 |
+
# LLM provider: "ollama" (default) or a litellm provider name.
|
| 12 |
+
MODEL_PROVIDER=ollama
|
app/app.py
CHANGED
|
@@ -22,8 +22,12 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
| 22 |
|
| 23 |
import gradio as gr # noqa: E402
|
| 24 |
|
|
|
|
| 25 |
from app.design_tokens import root_css # noqa: E402
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
# Web fonts: Fraunces (display serif) + Inter (UI sans) per DESIGN.md §3.
|
| 28 |
FONT_IMPORT = (
|
| 29 |
"@import url('https://fonts.googleapis.com/css2?"
|
|
|
|
| 22 |
|
| 23 |
import gradio as gr # noqa: E402
|
| 24 |
|
| 25 |
+
from app.config import load_env # noqa: E402
|
| 26 |
from app.design_tokens import root_css # noqa: E402
|
| 27 |
|
| 28 |
+
# Load .env (OLLAMA_HOST, MODEL_ID, …) before anything reads the environment.
|
| 29 |
+
load_env()
|
| 30 |
+
|
| 31 |
# Web fonts: Fraunces (display serif) + Inter (UI sans) per DESIGN.md §3.
|
| 32 |
FONT_IMPORT = (
|
| 33 |
"@import url('https://fonts.googleapis.com/css2?"
|
app/config.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""app/config.py — minimal, dependency-free environment loading.
|
| 2 |
+
|
| 3 |
+
Reads a ``.env`` file at the repo root into ``os.environ`` (without overriding
|
| 4 |
+
values already set in the real environment). Avoids adding python-dotenv just to
|
| 5 |
+
read a handful of keys.
|
| 6 |
+
|
| 7 |
+
Recognised keys (see ``.env.example``):
|
| 8 |
+
* ``OLLAMA_HOST`` — base URL of the Ollama server (e.g. http://host:11434)
|
| 9 |
+
* ``MODEL_ID`` — model name to use (default ``qwen2.5:7b``)
|
| 10 |
+
* ``MODEL_PROVIDER`` — ``ollama`` (default) or a litellm provider
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from __future__ import annotations
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
| 19 |
+
ENV_FILE = REPO_ROOT / ".env"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def load_env(env_file: Path | None = None) -> None:
|
| 23 |
+
"""Load KEY=VALUE lines from ``.env`` into os.environ (non-overriding)."""
|
| 24 |
+
path = env_file or ENV_FILE
|
| 25 |
+
if not path.exists():
|
| 26 |
+
return
|
| 27 |
+
for raw in path.read_text(encoding="utf-8").splitlines():
|
| 28 |
+
line = raw.strip()
|
| 29 |
+
if not line or line.startswith("#") or "=" not in line:
|
| 30 |
+
continue
|
| 31 |
+
key, _, value = line.partition("=")
|
| 32 |
+
key = key.strip()
|
| 33 |
+
value = value.strip().strip('"').strip("'")
|
| 34 |
+
if key and key not in os.environ:
|
| 35 |
+
os.environ[key] = value
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
__all__ = ["load_env", "ENV_FILE", "REPO_ROOT"]
|
tests/conftest.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared pytest fixtures / setup.
|
| 2 |
+
|
| 3 |
+
Loads the repo `.env` (OLLAMA_HOST, MODEL_ID, …) so tests that hit the real
|
| 4 |
+
model use the same configuration as the running app.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from app.config import load_env
|
| 8 |
+
|
| 9 |
+
load_env()
|