""" Configuration management for the RAG system """ import os import json from typing import Optional, Dict from pathlib import Path from dotenv import load_dotenv # Load environment variables from .env file if it exists load_dotenv() class Config: """Centralized configuration management""" def __init__(self): self.base_dir = Path(__file__).parent.parent self.car_manual_dir = self.base_dir / "car_manual" self.output_dir = self.base_dir / "output" self.user_data_dir = self.base_dir / "user_data" self.config_file = self.base_dir / "config" / "vector_store_config.json" # Create necessary directories self.car_manual_dir.mkdir(exist_ok=True) self.output_dir.mkdir(exist_ok=True) self.user_data_dir.mkdir(exist_ok=True) # OpenAI settings self.openai_api_key = os.getenv("OPENAI_API_KEY") if not self.openai_api_key: # Provide helpful error message env_file = self.base_dir / ".env" raise ValueError( f"OPENAI_API_KEY not found!\n\n" f"Please set your OpenAI API key using one of these methods:\n" f"1. Create a .env file in the project root with: OPENAI_API_KEY=your-key-here\n" f"2. Set environment variable: export OPENAI_API_KEY=your-key-here (Linux/Mac) or " f"$env:OPENAI_API_KEY='your-key-here' (Windows PowerShell)\n" f"3. Set environment variable: set OPENAI_API_KEY=your-key-here (Windows CMD)\n\n" f"You can copy .env.example to .env and add your key there." ) self.model = "gpt-4o-mini" self.vector_store_name = "mercedes_manual_store" # Available topics self.available_topics = [ "Function of Active Distance Assist DISTRONIC", "Function of Active Lane Change Assist", "Function of Active Steering Assist", "Function of Active Stop-and-Go Assist" ] def get_vector_store_id(self) -> Optional[str]: """Load vector store ID from config file""" if self.config_file.exists(): try: with open(self.config_file, 'r') as f: config = json.load(f) return config.get('id') except Exception as e: print(f"Error loading vector store config: {e}") return None def save_vector_store_id(self, vector_store_id: str, name: str = None): """Save vector store ID to config file""" config = { 'id': vector_store_id, 'name': name or self.vector_store_name, 'created_at': str(Path(self.config_file).stat().st_mtime) } with open(self.config_file, 'w') as f: json.dump(config, f, indent=2) def get_pdf_files(self) -> list: """Get list of PDF files in car_manual directory""" pdf_files = list(self.car_manual_dir.glob("*.pdf")) return [str(f) for f in pdf_files]