File size: 1,969 Bytes
80dbe44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

import os
from typing import Optional
from pathlib import Path
from dotenv import load_dotenv

# Load .env file từ project root
project_root = Path(__file__).resolve().parents[2]
env_path = project_root / ".env"
load_dotenv(env_path)

class Settings:
    
    # API Settings (đơn giản)
    API_BASE_URL: str = os.getenv("API_BASE_URL", "http://localhost:3454/api")
    
    # Gemini AI Settings
    GEMINI_API_KEY: Optional[str] = os.getenv("GEMINI_API_KEY")
    
    # Model URLs (Hugging Face)
    HF_MODEL_BASE_URL: str = "https://huggingface.co/NGOC1712/transportation-models/resolve/main/"
    HF_MODEL_FILES: dict = {
        "xgboost_model": "xgboost_model.pkl",
        "label_encoders": "all_label_encoders.joblib",
        "shipment_encoders": "shipment_label_encoders.pkl",
        "scaler": "scaler_weight_freight.pkl"
    }
    HF_TOKEN: Optional[str] = os.getenv("ACCESS")
    FUNCTIONS_DIR: Path = Path(__file__).resolve().parents[1] / "domain" / "functions"
    
    # Logging Configuration
    LOG_LEVEL: str = "INFO"
    LOG_FILE_ENABLED: bool = True
    LOG_CONSOLE_ENABLED: bool = True
    LOG_ROTATION_SIZE: int = 10 * 1024 * 1024  # 10MB
    LOG_BACKUP_COUNT: int = 5
    LOG_RETENTION_DAYS: int = 30
    
    @classmethod
    def get_predict_url(cls) -> str:
        """Lấy URL đầy đủ cho predict endpoint"""
        return f"{cls.API_BASE_URL}/predict-transportation"
    
    @classmethod
    def get_chat_url(cls) -> str:
        """Lấy URL đầy đủ cho chat endpoint"""
        return f"{cls.API_BASE_URL}/chat"
    
    @classmethod
    def validate_gemini_key(cls) -> bool:
        """Kiểm tra xem Gemini API key có được thiết lập không"""
        return cls.GEMINI_API_KEY is not None and len(cls.GEMINI_API_KEY.strip()) > 0
    
    @classmethod
    def get_gemini_config(cls) -> dict:
        return {
            "api_key": cls.GEMINI_API_KEY
        }

# Global settings instance
settings = Settings()