Spaces:
Configuration error
Configuration error
Download openhands/storage/settings/file_settings_store.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/storage/settings/file_settings_store.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/storage/settings/file_settings_store.py
-
curl -L -o file_settings_store.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/storage/settings/file_settings_store.py
1.29 kB
| from __future__ import annotations | |
| import json | |
| from dataclasses import dataclass | |
| from openhands.core.config.app_config import AppConfig | |
| from openhands.server.settings import Settings | |
| from openhands.storage import get_file_store | |
| from openhands.storage.files import FileStore | |
| from openhands.storage.settings.settings_store import SettingsStore | |
| from openhands.utils.async_utils import call_sync_from_async | |
| class FileSettingsStore(SettingsStore): | |
| file_store: FileStore | |
| path: str = 'settings.json' | |
| async def load(self) -> Settings | None: | |
| try: | |
| json_str = await call_sync_from_async(self.file_store.read, self.path) | |
| kwargs = json.loads(json_str) | |
| settings = Settings(**kwargs) | |
| return settings | |
| except FileNotFoundError: | |
| return None | |
| async def store(self, settings: Settings) -> None: | |
| json_str = settings.model_dump_json(context={'expose_secrets': True}) | |
| await call_sync_from_async(self.file_store.write, self.path, json_str) | |
| async def get_instance( | |
| cls, config: AppConfig, user_id: str | None | |
| ) -> FileSettingsStore: | |
| file_store = get_file_store(config.file_store, config.file_store_path) | |
| return FileSettingsStore(file_store) | |