openhands_config.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.settings.file_settings_store.FileSettingsStore'
  16. )
  17. conversation_store_class: str = (
  18. 'openhands.storage.conversation.file_conversation_store.FileConversationStore'
  19. )
  20. def verify_config(self):
  21. if self.config_cls:
  22. raise ValueError('Unexpected config path provided')
  23. def verify_github_repo_list(self, installation_id: int | None):
  24. if self.app_mode == AppMode.OSS and installation_id:
  25. raise HTTPException(
  26. status_code=400,
  27. detail='Unexpected installation ID',
  28. )
  29. def get_config(self):
  30. config = {
  31. 'APP_MODE': self.app_mode,
  32. 'GITHUB_CLIENT_ID': self.github_client_id,
  33. 'POSTHOG_CLIENT_KEY': self.posthog_client_key,
  34. }
  35. return config
  36. def load_openhands_config():
  37. config_cls = os.environ.get('OPENHANDS_CONFIG_CLS', None)
  38. logger.info(f'Using config class {config_cls}')
  39. openhands_config_cls = get_impl(OpenhandsConfig, config_cls)
  40. openhands_config = openhands_config_cls()
  41. openhands_config.verify_config()
  42. return openhands_config