config.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # E2 fix: use utf-8-sig to handle BOM from deploy.ps1 generated files
  10. with open(_env_path, "r", encoding="utf-8-sig") as f:
  11. for line in f:
  12. line = line.strip()
  13. if line and not line.startswith("#") and "=" in line:
  14. key, _, value = line.partition("=")
  15. key = key.strip()
  16. value = value.strip().strip('"').strip("'")
  17. # E2 fix: skip empty env vars so .env values are not shadowed
  18. if key and not os.environ.get(key):
  19. os.environ[key] = value
  20. except Exception:
  21. pass
  22. # Project paths
  23. BACKEND_DIR = Path(__file__).resolve().parent
  24. PROJECT_ROOT = BACKEND_DIR.parent.parent.parent
  25. # Database (SQLite for Phase 2, migrate to PostgreSQL later)
  26. DB_PATH = os.environ.get("AFM_DB_PATH", str(BACKEND_DIR / "afm_sim.db"))
  27. DATABASE_URL = f"sqlite:///{DB_PATH}"
  28. # Server
  29. HOST = os.environ.get("AFM_HOST", "127.0.0.1")
  30. PORT = int(os.environ.get("AFM_PORT", "8000"))
  31. # CORS (allow frontend dev server)
  32. CORS_ORIGINS = os.environ.get(
  33. "AFM_CORS_ORIGINS",
  34. "http://localhost:5173,http://127.0.0.1:5173,http://localhost:3000"
  35. ).split(",")
  36. # App metadata
  37. APP_NAME = "PCB Axial Flux Motor Simulation System"
  38. APP_VERSION = "1.1.0"
  39. APP_DESCRIPTION = "Web-based simulation plan generation and optimization system for PCB axial flux motors"
  40. # ============================================================
  41. # P3: Kimi AI Configuration
  42. # ============================================================
  43. KIMI_API_KEY = os.environ.get("KIMI_API_KEY", "")
  44. KIMI_BASE_URL = os.environ.get("KIMI_BASE_URL", "https://api.kimi.com/coding/v1")
  45. KIMI_MODEL = os.environ.get("KIMI_MODEL", "k3")
  46. KIMI_MAX_TOKENS = int(os.environ.get("KIMI_MAX_TOKENS", "4096"))
  47. KIMI_TEMPERATURE = float(os.environ.get("KIMI_TEMPERATURE", "1.0"))
  48. KIMI_TIMEOUT = int(os.environ.get("KIMI_TIMEOUT", "120"))
  49. KIMI_MAX_RETRIES = int(os.environ.get("KIMI_MAX_RETRIES", "3"))
  50. # Prompt templates directory. BACKEND_DIR is web/backend/app (config.py lives
  51. # in app/), while the prompts tree is web/backend/prompts - one level up.
  52. PROMPTS_DIR = BACKEND_DIR.parent / "prompts"
  53. # Schema version (P3: V2 with fidelity/search/calibration fields)
  54. SCHEMA_VERSION = "2.0"