""" config.py — Central configuration for the Personal Document Intel & Archiver All paths, model settings, and user-configurable patient info live here. """ import json import os from pathlib import Path BASE_DIR = Path(__file__).parent # ── Directory layout ──────────────────────────────────────────────────────── DATA_DIR = BASE_DIR / "data" DOCUMENTS_DIR = DATA_DIR / "documents" CACHE_DIR = BASE_DIR / "cache" MODELS_DIR = BASE_DIR / "models" ASSETS_DIR = BASE_DIR / "assets" # ── Model settings ────────────────────────────────────────────────────────── MODEL_PATH = MODELS_DIR / "qwen2.5-3b-instruct-q4_k_m.gguf" EMBEDDING_MODEL = "all-MiniLM-L6-v2" CHUNK_SIZE = 500 CHUNK_OVERLAP = 50 TOP_K_RETRIEVAL = 3 TEMPERATURE = 0.1 MAX_TOKENS = 512 CONTEXT_SIZE = 4096 # ── LM Studio endpoint ──────────────────────────────────────────────────────── LM_STUDIO_URL = "http://192.168.1.160:1234/v1/completions" # ── FAISS / chunk cache ───────────────────────────────────────────────────── FAISS_INDEX_PATH = CACHE_DIR / "index.faiss" CHUNKS_JSON_PATH = CACHE_DIR / "chunks.json" # ── Data store paths ──────────────────────────────────────────────────────── MEDICATIONS_JSON = DATA_DIR / "medications.json" APPOINTMENTS_JSON = DATA_DIR / "appointments.json" FOOD_CHART_JSON = DATA_DIR / "food_chart.json" PATIENT_CONFIG_JSON = DATA_DIR / "patient_config.json" # ── Patient info defaults (overridden by PATIENT_CONFIG_JSON at runtime) ──── _PATIENT_DEFAULTS = { "patient_name": "", "patient_dob": "", "insurance_info": "", "model_path": str(MODEL_PATH), "welcome_dismissed": False, "active_profile_id": "", } def _ensure_dirs(): """Create all required directories if they don't exist.""" for d in [DATA_DIR, DOCUMENTS_DIR, CACHE_DIR, MODELS_DIR, ASSETS_DIR]: d.mkdir(parents=True, exist_ok=True) def _ensure_model(): """ Stub: previously auto-downloaded a local GGUF for llama-cpp-python. Now we use the Hugging Face Inference API (hosted Qwen 2.5 7B), which needs no local model file. Kept as a no-op for backwards compatibility with any callers that still expect this function to exist. """ return def load_patient_config() -> dict: """Load patient config from disk, falling back to defaults.""" _ensure_dirs() if PATIENT_CONFIG_JSON.exists(): try: with open(PATIENT_CONFIG_JSON, "r", encoding="utf-8") as f: data = json.load(f) # Merge so any new keys from defaults are present merged = {**_PATIENT_DEFAULTS, **data} return merged except Exception: pass return dict(_PATIENT_DEFAULTS) def save_patient_config(cfg: dict): """Persist patient config to disk.""" _ensure_dirs() with open(PATIENT_CONFIG_JSON, "w", encoding="utf-8") as f: json.dump(cfg, f, indent=2) def get_model_path() -> Path: """Return the active model path (from saved config or default).""" cfg = load_patient_config() return Path(cfg.get("model_path", str(MODEL_PATH))) def load_active_profile_id() -> str: """Return persisted active care profile id, or empty string.""" return (load_patient_config().get("active_profile_id") or "").strip() def save_active_profile_id(profile_id: str | None): """Persist the active care profile id (empty string clears the session).""" cfg = load_patient_config() cfg["active_profile_id"] = profile_id or "" save_patient_config(cfg) # Ensure directories exist when module is first imported _ensure_dirs() _ensure_model()