config.py 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import logging
  2. import os
  3. from typing import Optional, List
  4. from pydantic import BaseModel, Field, ConfigDict, computed_field
  5. class EnvValue:
  6. DEV: str = "dev"
  7. PROD: str = "prod"
  8. class Env:
  9. @property
  10. def env(self) -> str:
  11. return os.getenv("ENV", EnvValue.DEV).lower()
  12. def is_prod(self) -> bool:
  13. return self.env == EnvValue.PROD
  14. def is_dev(self) -> bool:
  15. return self.env == EnvValue.DEV
  16. def __str__(self):
  17. return self.env
  18. ENV = Env()
  19. # 服务配置
  20. SERVER_PORT = 20335
  21. LOGGING_LEVEL = logging.INFO if ENV.is_prod() else logging.DEBUG
  22. # Bing search
  23. LLM_SEARCH_HOST = "http://lq.lianqiai.cn:20333" if ENV.is_dev() else "https://ac.zjugis.com:8511"
  24. class UserSearchRequest(BaseModel):
  25. request_id: str
  26. query: str
  27. class BaseResponse(BaseModel):
  28. request_id: str
  29. result: Optional[str] = None