openhands_config.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import os
  2. from fastapi import HTTPException
  3. from openhands.core.logger import openhands_logger as logger
  4. from openhands.server.types import AppMode, OpenhandsConfigInterface
  5. from openhands.utils.import_utils import get_impl
  6. class OpenhandsConfig(OpenhandsConfigInterface):
  7. config_cls = os.environ.get('OPENHANDS_CONFIG_CLS', None)
  8. app_mode = AppMode.OSS
  9. posthog_client_key = 'phc_3ESMmY9SgqEAGBB6sMGK5ayYHkeUuknH2vP6FmWH9RA'
  10. github_client_id = os.environ.get('GITHUB_APP_CLIENT_ID', '')
  11. attach_conversation_middleware_path = (
  12. 'openhands.server.middleware.AttachConversationMiddleware'
  13. )
  14. settings_store_class: str = (
  15. 'openhands.storage.file_settings_store.FileSettingsStore'
  16. )
  17. def verify_config(self):
  18. if self.config_cls:
  19. raise ValueError('Unexpected config path provided')
  20. def verify_github_repo_list(self, installation_id: int | None):
  21. if self.app_mode == AppMode.OSS and installation_id:
  22. raise HTTPException(
  23. status_code=400,
  24. detail='Unexpected installation ID',
  25. )
  26. def get_config(self):
  27. config = {
  28. 'APP_MODE': self.app_mode,
  29. 'GITHUB_CLIENT_ID': self.github_client_id,
  30. 'POSTHOG_CLIENT_KEY': self.posthog_client_key,
  31. }
  32. return config
  33. def load_openhands_config():
  34. config_cls = os.environ.get('OPENHANDS_CONFIG_CLS', None)
  35. logger.info(f'Using config class {config_cls}')
  36. openhands_config_cls = get_impl(OpenhandsConfig, config_cls)
  37. openhands_config = openhands_config_cls()
  38. openhands_config.verify_config()
  39. return openhands_config