Commit
·
a4d66c0
1
Parent(s):
96e6d20
Improve database path handling with Docker detection and fallback to /tmp
Browse files- config.py +5 -2
- src/context_manager.py +7 -2
config.py
CHANGED
|
@@ -18,8 +18,11 @@ class Settings(BaseSettings):
|
|
| 18 |
|
| 19 |
# Database settings
|
| 20 |
# Use /tmp for writable location in Docker containers
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Session settings
|
| 25 |
session_timeout: int = int(os.getenv("SESSION_TIMEOUT", "3600"))
|
|
|
|
| 18 |
|
| 19 |
# Database settings
|
| 20 |
# Use /tmp for writable location in Docker containers
|
| 21 |
+
# Check if we're in Docker (HF Spaces) - if so, use /tmp
|
| 22 |
+
_default_db_path = "/tmp/sessions.db" if os.path.exists("/.dockerenv") or os.path.exists("/tmp") else "sessions.db"
|
| 23 |
+
db_path: str = os.getenv("DB_PATH", _default_db_path)
|
| 24 |
+
_default_faiss_path = "/tmp/embeddings.faiss" if os.path.exists("/.dockerenv") or os.path.exists("/tmp") else "embeddings.faiss"
|
| 25 |
+
faiss_index_path: str = os.getenv("FAISS_INDEX_PATH", _default_faiss_path)
|
| 26 |
|
| 27 |
# Session settings
|
| 28 |
session_timeout: int = int(os.getenv("SESSION_TIMEOUT", "3600"))
|
src/context_manager.py
CHANGED
|
@@ -62,8 +62,13 @@ class EfficientContextManager:
|
|
| 62 |
}
|
| 63 |
# Use provided db_path or get from config/env, default to /tmp for Docker
|
| 64 |
if db_path is None:
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
self.db_path = db_path
|
| 68 |
# Ensure directory exists
|
| 69 |
db_dir = os.path.dirname(self.db_path)
|
|
|
|
| 62 |
}
|
| 63 |
# Use provided db_path or get from config/env, default to /tmp for Docker
|
| 64 |
if db_path is None:
|
| 65 |
+
try:
|
| 66 |
+
from config import settings
|
| 67 |
+
db_path = settings.db_path
|
| 68 |
+
except (ImportError, AttributeError):
|
| 69 |
+
# Fallback: check environment variable or use /tmp
|
| 70 |
+
import os
|
| 71 |
+
db_path = os.getenv("DB_PATH", "/tmp/sessions.db")
|
| 72 |
self.db_path = db_path
|
| 73 |
# Ensure directory exists
|
| 74 |
db_dir = os.path.dirname(self.db_path)
|