Spaces:
Paused
Paused
Download src/utils/prompt_loader.py from sam2009897/AstraWeave: direct link, hf CLI and curl.
- Browser
- Download file 547 Bytes
-
https://huggingface.co/spaces/sam2009897/AstraWeave/resolve/main/src/utils/prompt_loader.py
- Command line
-
hf download hf://spaces/sam2009897/AstraWeave/src/utils/prompt_loader.py
-
curl -L -o prompt_loader.py https://huggingface.co/spaces/sam2009897/AstraWeave/resolve/main/src/utils/prompt_loader.py
547 Bytes
| import os | |
| _PROMPT_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "prompts") | |
| _CACHE: dict[str, str] = {} | |
| def load_prompt(name: str) -> str: | |
| if name in _CACHE: | |
| return _CACHE[name] | |
| path = os.path.join(_PROMPT_DIR, f"{name}.txt") | |
| if not os.path.isfile(path): | |
| raise FileNotFoundError(f"Prompt file not found: {path}") | |
| with open(path, "r", encoding="utf-8") as f: | |
| content = f.read().strip() | |
| _CACHE[name] = content | |
| return content | |
| def clear_cache(): | |
| _CACHE.clear() | |