Spaces:
Running
Running
Commit
·
1768b63
1
Parent(s):
2690221
fix(runtime): add app.storage module; make app a package; use relative import
Browse files- app/storage.py +32 -0
app/storage.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# storage.py (no BOM)
|
2 |
+
import os, tempfile
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
def _first_writable(candidates):
|
6 |
+
for c in candidates:
|
7 |
+
if not c:
|
8 |
+
continue
|
9 |
+
try:
|
10 |
+
p = Path(c)
|
11 |
+
p.mkdir(parents=True, exist_ok=True)
|
12 |
+
t = p / ".write_test"
|
13 |
+
t.write_text("ok", encoding="utf-8")
|
14 |
+
try:
|
15 |
+
t.unlink()
|
16 |
+
except OSError:
|
17 |
+
pass
|
18 |
+
return p
|
19 |
+
except Exception:
|
20 |
+
continue
|
21 |
+
return Path(tempfile.mkdtemp(prefix="rag_"))
|
22 |
+
|
23 |
+
DATA_DIR = _first_writable([
|
24 |
+
os.getenv("DATA_DIR") or None,
|
25 |
+
"/data",
|
26 |
+
"/app/data",
|
27 |
+
str(Path.home() / ".cache" / "rag_data"),
|
28 |
+
"/tmp/rag_data",
|
29 |
+
])
|
30 |
+
|
31 |
+
INDEX_DIR = DATA_DIR / "index"
|
32 |
+
HISTORY_JSON = DATA_DIR / "history.json"
|