Spaces:
Running
Running
Download app/doc_manager.py from 640510702phithak/LLM-RAG-API: direct link, hf CLI and curl.
- Browser
- Download file 520 Bytes
-
https://huggingface.co/spaces/640510702phithak/LLM-RAG-API/resolve/main/app/doc_manager.py
- Command line
-
hf download hf://spaces/640510702phithak/LLM-RAG-API/app/doc_manager.py
-
curl -L -o doc_manager.py https://huggingface.co/spaces/640510702phithak/LLM-RAG-API/resolve/main/app/doc_manager.py
520 Bytes
| import json | |
| import os | |
| from app.config import DOCS_JSON | |
| def load_docs(): | |
| if os.path.exists(DOCS_JSON) and os.path.getsize(DOCS_JSON) > 0: | |
| with open(DOCS_JSON, encoding="utf-8") as f: | |
| return json.load(f) | |
| return [] | |
| def save_docs(docs): | |
| with open(DOCS_JSON, "w", encoding="utf-8") as f: | |
| json.dump(docs, f, ensure_ascii=False, indent=2) | |
| def find_doc_by_title(docs, title): | |
| for i, d in enumerate(docs): | |
| if d["title"] == title: | |
| return i, d | |
| return -1, None | |