config.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """Application configuration."""
  2. import os
  3. from pathlib import Path
  4. # Load .env file if exists (P3: Kimi API config)
  5. # Use stdlib parser to avoid python-dotenv dependency
  6. _env_path = Path(__file__).resolve().parent.parent / ".env"
  7. if _env_path.exists():
  8. try:
  9. with open(_env_path, "r", encoding="utf-8") as f:
  10. for line in f:
  11. line = line.strip()
  12. if line and not line.startswith("#") and "=" in line:
  13. key, _, value = line.partition("=")
  14. key = key.strip()
  15. value = value.strip().strip('"').strip("'")
  16. if key and key not in os.environ:
  17. os.environ[key] = value
  18. except Exception:
  19. pass
  20. # Project paths
  21. BACKEND_DIR = Path(__file__).resolve().parent
  22. PROJECT_ROOT = BACKEND_DIR.parent.parent.parent
  23. # Database (SQLite for Phase 2, migrate to PostgreSQL later)
  24. DB_PATH = os.environ.get("AFM_DB_PATH", str(BACKEND_DIR / "afm_sim.db"))
  25. DATABASE_URL = f"sqlite:///{DB_PATH}"
  26. # Server
  27. HOST = os.environ.get("AFM_HOST", "127.0.0.1")
  28. PORT = int(os.environ.get("AFM_PORT", "8000"))
  29. # CORS (allow frontend dev server)
  30. CORS_ORIGINS = os.environ.get(
  31. "AFM_CORS_ORIGINS",
  32. "http://localhost:5173,http://127.0.0.1:5173,http://localhost:3000"
  33. ).split(",")
  34. # App metadata
  35. APP_NAME = "PCB Axial Flux Motor Simulation System"
  36. APP_VERSION = "1.1.0"
  37. APP_DESCRIPTION = "Web-based simulation plan generation and optimization system for PCB axial flux motors"
  38. # ============================================================
  39. # P3: Kimi AI Configuration
  40. # ============================================================
  41. KIMI_API_KEY = os.environ.get("KIMI_API_KEY", "")
  42. KIMI_BASE_URL = os.environ.get("KIMI_BASE_URL", "https://api.kimi.com/coding/v1")
  43. KIMI_MODEL = os.environ.get("KIMI_MODEL", "k3")
  44. KIMI_MAX_TOKENS = int(os.environ.get("KIMI_MAX_TOKENS", "4096"))
  45. KIMI_TEMPERATURE = float(os.environ.get("KIMI_TEMPERATURE", "1.0"))
  46. KIMI_TIMEOUT = int(os.environ.get("KIMI_TIMEOUT", "120"))
  47. KIMI_MAX_RETRIES = int(os.environ.get("KIMI_MAX_RETRIES", "3"))
  48. # Prompt templates directory
  49. PROMPTS_DIR = BACKEND_DIR / "prompts"
  50. # Schema version (P3: V2 with fidelity/search/calibration fields)
  51. SCHEMA_VERSION = "2.0"