diff options
author | Diogo Sousa <montezdesousa@gmail.com> | 2024-05-21 18:58:30 +0100 |
---|---|---|
committer | Diogo Sousa <montezdesousa@gmail.com> | 2024-05-21 18:58:30 +0100 |
commit | 83482f4894a5f7fc5a9c7dae8b9fdce6b8088465 (patch) | |
tree | 47f9844683e8e5c3753da7026a6c2a5cd604aba6 | |
parent | 5aa90e2fb3af669b970dfa55709ea6eaa5ba3463 (diff) |
fix: rename defaults field to commands
-rw-r--r-- | openbb_platform/core/openbb_core/app/model/defaults.py | 5 | ||||
-rw-r--r-- | openbb_platform/core/openbb_core/app/static/container.py | 33 |
2 files changed, 31 insertions, 7 deletions
diff --git a/openbb_platform/core/openbb_core/app/model/defaults.py b/openbb_platform/core/openbb_core/app/model/defaults.py index 89cea5cbfb4..97e00df559b 100644 --- a/openbb_platform/core/openbb_core/app/model/defaults.py +++ b/openbb_platform/core/openbb_core/app/model/defaults.py @@ -10,8 +10,9 @@ class Defaults(BaseModel): model_config = ConfigDict(validate_assignment=True) - routes: Dict[str, Dict[str, Optional[Union[str, List[str]]]]] = Field( - default_factory=dict + commands: Dict[str, Dict[str, Optional[Union[str, List[str]]]]] = Field( + default_factory=dict, + alias="routes", # routes was deprecated in favor of commands ) def __repr__(self) -> str: diff --git a/openbb_platform/core/openbb_core/app/static/container.py b/openbb_platform/core/openbb_core/app/static/container.py index 0bda67f6ee7..ed21652e910 100644 --- a/openbb_platform/core/openbb_core/app/static/container.py +++ b/openbb_platform/core/openbb_core/app/static/container.py @@ -33,13 +33,36 @@ class Container: return all(getattr(credentials, r, None) for r in required) def _get_provider( - self, choice: Optional[str], cmd: str, available: Tuple[str, ...] + self, choice: Optional[str], command: str, default_fallback: Tuple[str, ...] ) -> str: - """Get the provider to use in execution.""" + """Get the provider to use in execution. + + If no choice is specified, the configured fallback is used. A provider is used + when its required credentials are populated. + + Parameters + ---------- + choice: Optional[str] + The provider choice, for example 'fmp'. + command: str + The command to get the provider for, for example 'equity.price.historical' + default_fallback: Tuple[str, ...] + A tuple of available providers for the given command to use as default fallback. + + Returns + ------- + str + The provider to use in the command. + + Raises + ------ + OpenBBError + Raises error when all the providers in the fallback failed. + """ if choice is None: - routes = self._command_runner.user_settings.defaults.routes - provider = routes.get(cmd, {}).get("provider", []) or available - providers = [provider] if isinstance(provider, str) else provider + commands = self._command_runner.user_settings.defaults.commands + fallback = commands.get(command, {}).get("provider", []) or default_fallback + providers = [fallback] if isinstance(fallback, str) else fallback for p in providers: if self._check_credentials(p): return p |