-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Set provider fallback based on credentials (#6446)
* feat: allow provider fallback based on credentials * fix: rename prop and raise error * fix: raise if all providers fail * fix: remove dead line * fix: rename defaults field to commands * rename key and update docs * fix: rename some stuff * fix bug * fix: mypy * fix: unittests * docstring * fix: provider field description * fix: error messages * fix: msg * feat: update defaults class * feat: update defaults class * unit tests * fix test * msg * fix: add website documentation * fix: detailed error message * update core ruff version * fix test * rebuild --------- Co-authored-by: Igor Radovanovic <[email protected]>
- Loading branch information
1 parent
d3802c5
commit 01a71a8
Showing
40 changed files
with
950 additions
and
1,086 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
"""Defaults model.""" | ||
|
||
from typing import Dict, Optional | ||
from typing import Dict, List, Optional | ||
from warnings import warn | ||
|
||
from pydantic import BaseModel, ConfigDict, Field | ||
from pydantic import BaseModel, ConfigDict, Field, model_validator | ||
|
||
from openbb_core.app.model.abstract.warning import OpenBBWarning | ||
|
||
|
||
class Defaults(BaseModel): | ||
"""Defaults.""" | ||
|
||
model_config = ConfigDict(validate_assignment=True) | ||
model_config = ConfigDict(validate_assignment=True, populate_by_name=True) | ||
|
||
routes: Dict[str, Dict[str, Optional[str]]] = Field(default_factory=dict) | ||
commands: Dict[str, Dict[str, Optional[List[str]]]] = Field( | ||
default_factory=dict, | ||
alias="routes", | ||
) | ||
|
||
def __repr__(self) -> str: | ||
"""Return string representation.""" | ||
return f"{self.__class__.__name__}\n\n" + "\n".join( | ||
f"{k}: {v}" for k, v in self.model_dump().items() | ||
) | ||
|
||
@model_validator(mode="before") | ||
@classmethod | ||
def validate_before(cls, values: dict) -> dict: | ||
"""Validate model (before).""" | ||
key = "commands" | ||
if "routes" in values: | ||
warn( | ||
message="'routes' is deprecated. Use 'commands' instead.", | ||
category=OpenBBWarning, | ||
) | ||
key = "routes" | ||
|
||
new_values: Dict[str, Dict[str, Optional[List[str]]]] = {"commands": {}} | ||
for k, v in values.get(key, {}).items(): | ||
clean_k = k.strip("/").replace("/", ".") | ||
provider = v.get("provider") if v else None | ||
if isinstance(provider, str): | ||
v["provider"] = [provider] | ||
new_values["commands"][clean_k] = v | ||
return new_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.