HamidOmarov commited on
Commit
649d2d5
·
1 Parent(s): 8ea6d3a

fix(runtime): pick writable DATA_DIR via storage module; create dirs on startup; remove hardcoded /data

Browse files
app.py CHANGED
@@ -1,2 +1,3 @@
1
  # app.py (repo kГ¶kГјndЙ™)
2
  from app.api import app # FastAPI instance
 
 
1
  # app.py (repo kГ¶kГјndЙ™)
2
  from app.api import app # FastAPI instance
3
+
app/__init__.py CHANGED
@@ -0,0 +1 @@
 
 
1
+ 
app/api.py CHANGED
@@ -1,4 +1,5 @@
1
- # app/api.py
 
2
  from __future__ import annotations
3
 
4
  import time
@@ -200,3 +201,15 @@ def reset_index():
200
  return {"message": "index reset", "ntotal": getattr(rag.index, "ntotal", 0)}
201
  except Exception as e:
202
  raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON
2
+ # app/api.py
3
  from __future__ import annotations
4
 
5
  import time
 
201
  return {"message": "index reset", "ntotal": getattr(rag.index, "ntotal", 0)}
202
  except Exception as e:
203
  raise HTTPException(status_code=500, detail=str(e))
204
+
205
+ @app.on_event("startup")
206
+ async def _ensure_dirs():
207
+ try:
208
+ INDEX_DIR.mkdir(parents=True, exist_ok=True)
209
+ # HISTORY_JSON parent is DATA_DIR
210
+ HISTORY_JSON.parent.mkdir(parents=True, exist_ok=True)
211
+ except Exception:
212
+ # boot-un dayanmasının qarşısını alaq
213
+ pass
214
+
215
+
app/metrics.py CHANGED
@@ -40,3 +40,4 @@ class StatsTracker:
40
  }
41
 
42
  tracker = StatsTracker()
 
 
40
  }
41
 
42
  tracker = StatsTracker()
43
+
app/paths.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from pathlib import Path
3
- DATA_DIR = Path(os.getenv("DATA_DIR", "/data"))
4
  DATA_DIR.mkdir(parents=True, exist_ok=True)
5
  INDEX_DIR = DATA_DIR / "index"; INDEX_DIR.mkdir(exist_ok=True)
6
  HISTORY_JSON = DATA_DIR / "history.json"
 
 
1
  import os
2
  from pathlib import Path
3
+ DATA_DIR = Path(os.getenv("DATA_DIR", str(DATA_DIR)))
4
  DATA_DIR.mkdir(parents=True, exist_ok=True)
5
  INDEX_DIR = DATA_DIR / "index"; INDEX_DIR.mkdir(exist_ok=True)
6
  HISTORY_JSON = DATA_DIR / "history.json"
7
+
app/rag/__init__.py CHANGED
@@ -0,0 +1 @@
 
 
1
+ 
app/rag_system.py CHANGED
@@ -361,3 +361,4 @@ __all__ = [
361
  "UPLOAD_DIR",
362
  "INDEX_DIR",
363
  ]
 
 
361
  "UPLOAD_DIR",
362
  "INDEX_DIR",
363
  ]
364
+
app/routes_stats.py CHANGED
@@ -11,3 +11,4 @@ def get_stats():
11
  def get_history():
12
  s = tracker.get_stats()
13
  return {"history": s["lastN_questions"], "total_chunks": s["total_chunks"]}
 
 
11
  def get_history():
12
  s = tracker.get_stats()
13
  return {"history": s["lastN_questions"], "total_chunks": s["total_chunks"]}
14
+
app/schemas.py CHANGED
@@ -23,3 +23,4 @@ class HistoryItem(BaseModel):
23
  class HistoryResponse(BaseModel):
24
  session_id: str
25
  history: List[HistoryItem]
 
 
23
  class HistoryResponse(BaseModel):
24
  session_id: str
25
  history: List[HistoryItem]
26
+
app/store.py CHANGED
@@ -10,3 +10,4 @@ def add_history(session_id: str, role: str, content: str):
10
 
11
  def get_history(session_id: str) -> List[dict]:
12
  return _history.get(session_id, [])
 
 
10
 
11
  def get_history(session_id: str) -> List[dict]:
12
  return _history.get(session_id, [])
13
+
app/utils.py CHANGED
@@ -7,3 +7,4 @@ def ensure_session(session_id: str | None) -> str:
7
 
8
  def http400(msg: str):
9
  raise HTTPException(status_code=400, detail=msg)
 
 
7
 
8
  def http400(msg: str):
9
  raise HTTPException(status_code=400, detail=msg)
10
+
boot.py CHANGED
@@ -30,3 +30,4 @@ if __name__ == "__main__":
30
  if last_err:
31
  raise last_err
32
  sys.exit(1)
 
 
30
  if last_err:
31
  raise last_err
32
  sys.exit(1)
33
+
main.py CHANGED
@@ -13,3 +13,4 @@ async def generate_alias(
13
  @app.get("/health")
14
  def health_alias():
15
  return {"status": "ok"}
 
 
13
  @app.get("/health")
14
  def health_alias():
15
  return {"status": "ok"}
16
+