mirror of
https://github.com/zebrajr/localGPT.git
synced 2026-01-15 12:15:10 +00:00
fix: implement automatic database path detection for multi-environment compatibility
- Add environment auto-detection in ChatDatabase class - Support both local development and Docker container paths - Local development: uses 'backend/chat_data.db' (relative path) - Docker containers: uses '/app/backend/chat_data.db' (absolute path) - Maintain backward compatibility with explicit path overrides - Update RAG API server to use auto-detection This resolves the SQLite database connection error that occurred when running LocalGPT in local development environments while maintaining compatibility with Docker deployments. Fixes: Database path hardcoded to Docker container path Tested: Local development and Docker environment detection Breaking: No breaking changes - maintains backward compatibility
This commit is contained in:
@@ -5,8 +5,16 @@ from datetime import datetime
|
||||
from typing import List, Dict, Optional, Tuple
|
||||
|
||||
class ChatDatabase:
|
||||
def __init__(self, db_path: str = "/app/backend/chat_data.db"):
|
||||
self.db_path = db_path
|
||||
def __init__(self, db_path: str = None):
|
||||
if db_path is None:
|
||||
# Auto-detect environment and set appropriate path
|
||||
import os
|
||||
if os.path.exists("/app"): # Docker environment
|
||||
self.db_path = "/app/backend/chat_data.db"
|
||||
else: # Local development environment
|
||||
self.db_path = "backend/chat_data.db"
|
||||
else:
|
||||
self.db_path = db_path
|
||||
self.init_database()
|
||||
|
||||
def init_database(self):
|
||||
|
||||
@@ -17,7 +17,8 @@ from rag_system.main import get_agent
|
||||
from rag_system.factory import get_indexing_pipeline
|
||||
|
||||
# Initialize database connection once at module level
|
||||
db = ChatDatabase("backend/chat_data.db")
|
||||
# Use auto-detection for environment-appropriate path
|
||||
db = ChatDatabase()
|
||||
|
||||
# Get the desired agent mode from environment variables, defaulting to 'default'
|
||||
# This allows us to easily switch between 'default', 'fast', 'react', etc.
|
||||
|
||||
Reference in New Issue
Block a user