Spaces:
Sleeping
Sleeping
Download paths.py from StudentCompanion/alu-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/StudentCompanion/alu-chatbot/resolve/main/paths.py
- Command line
-
hf download hf://spaces/StudentCompanion/alu-chatbot/paths.py
-
curl -L -o paths.py https://huggingface.co/spaces/StudentCompanion/alu-chatbot/resolve/main/paths.py
2.03 kB
| """ | |
| Where this service keeps its files. One definition, imported everywhere. | |
| Three modules previously worked this out for themselves and disagreed: | |
| retrieval_engine.py honoured the DATA_DIR environment variable, | |
| document_processor.py and prompt_engine/templates.py hardcoded "./data". | |
| On Hugging Face nothing sets DATA_DIR, so all three resolved to the same | |
| place by coincidence and the mismatch was invisible. | |
| Set DATA_DIR to anything else — mounting persistent storage during a | |
| migration, say — and they diverge: uploads land in one directory while | |
| retrieval searches another. Nothing raises. The upload reports success and | |
| the document simply never becomes answerable. | |
| Importing from here means that can't happen again. | |
| """ | |
| import os | |
| from pathlib import Path | |
| # Root for everything this service writes. Override with DATA_DIR to point | |
| # at a mounted volume; every module below follows automatically. | |
| DATA_DIR = Path(os.environ.get("DATA_DIR", "./data")) | |
| # Uploaded source files (PDF/DOCX/TXT) and their extracted text. Unlike the | |
| # vector store, these have no other source — they cannot be rebuilt, so this | |
| # is the directory that genuinely needs durable storage. | |
| DOCUMENTS_DIR = DATA_DIR / "documents" | |
| # Metadata index for the above. | |
| METADATA_FILE = DATA_DIR / "document_metadata.json" | |
| # ChromaDB's on-disk store. Derived data: sheet_sync rebuilds it from each | |
| # university's Sheet on boot, so losing it costs a slow start, not content. | |
| VECTOR_DB_DIR = DATA_DIR / "vectordb" | |
| # Editable prompt templates. | |
| PROMPTS_DIR = DATA_DIR / "prompts" | |
| # Curated JSON knowledge shipped with the image rather than written at | |
| # runtime, so it stays separate from DATA_DIR. | |
| ALU_BRAIN_DIR = Path(os.environ.get("ALU_BRAIN_DIR", "./alu_brain")) | |
| def ensure_dirs() -> None: | |
| """Create the directories this service writes to. | |
| Called at import by the modules that need them. Safe to call repeatedly. | |
| """ | |
| for d in (DATA_DIR, DOCUMENTS_DIR, VECTOR_DB_DIR, PROMPTS_DIR): | |
| d.mkdir(parents=True, exist_ok=True) | |