Spaces:
Build error
Build error
| """ | |
| Central configuration for the University Admissions RAG Chatbot. | |
| All parameters are environment-variable-driven with sensible defaults. | |
| """ | |
| import os | |
| from dataclasses import dataclass, field | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| class ModelConfig: | |
| model_id: str = "ibm-granite/granite-4.1-3b-instruct" | |
| max_new_tokens: int = 512 | |
| temperature: float = 0.3 | |
| top_p: float = 0.9 | |
| repetition_penalty: float = 1.15 | |
| do_sample: bool = True | |
| device_map: str = "auto" | |
| torch_dtype: str = "auto" # resolved at runtime | |
| class EmbeddingConfig: | |
| model_name: str = "sentence-transformers/all-MiniLM-L6-v2" | |
| batch_size: int = 64 | |
| normalize_embeddings: bool = True | |
| class ChunkingConfig: | |
| chunk_size: int = 600 | |
| chunk_overlap: int = 80 | |
| separators: list = field(default_factory=lambda: ["\n\n", "\n", ". ", " ", ""]) | |
| class RetrievalConfig: | |
| top_k: int = 4 | |
| score_threshold: float = 0.0 # cosine similarity lower-bound (FAISS L2 inverse) | |
| index_path: str = "faiss_index" | |
| index_file: str = "faiss_index/index.faiss" | |
| metadata_file: str = "faiss_index/metadata.pkl" | |
| class AppConfig: | |
| title: str = "🎓 University Admissions Assistant" | |
| description: str = ( | |
| "Ask me anything about admissions requirements, programs, fees, " | |
| "scholarships, deadlines, and more. Powered by IBM Granite 4.1 3B Instruct." | |
| ) | |
| max_file_size_mb: int = 20 | |
| allowed_extensions: tuple = (".pdf", ".docx", ".txt") | |
| data_dir: str = "data" | |
| log_dir: str = "logs" | |
| max_history_turns: int = 6 # pairs kept in context | |
| class Config: | |
| model: ModelConfig = field(default_factory=ModelConfig) | |
| embedding: EmbeddingConfig = field(default_factory=EmbeddingConfig) | |
| chunking: ChunkingConfig = field(default_factory=ChunkingConfig) | |
| retrieval: RetrievalConfig = field(default_factory=RetrievalConfig) | |
| app: AppConfig = field(default_factory=AppConfig) | |
| def hf_token(self) -> str | None: | |
| return os.environ.get("HF_TOKEN") | |
| def validate(self) -> None: | |
| if not self.hf_token: | |
| raise EnvironmentError( | |
| "HF_TOKEN environment variable is not set. " | |
| "Export it or add it to your .env file." | |
| ) | |
| # Singleton | |
| cfg = Config() | |