Skip to content

Commit

Permalink
Merge branch 'release/4.1.7' of https://github.com/OpenBB-finance/Ope…
Browse files Browse the repository at this point in the history
…nBBTerminal into release/4.1.7
  • Loading branch information
deeleeramone committed Apr 19, 2024
2 parents f1d7d7f + 6739fa1 commit f8a754f
Show file tree
Hide file tree
Showing 43 changed files with 1,593 additions and 856 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Servers(BaseModel):
description: str = "Local OpenBB development server"


class FastAPISettings(BaseModel):
class APISettings(BaseModel):
"""Settings model for FastAPI configuration."""

model_config = ConfigDict(frozen=True)
Expand Down
37 changes: 0 additions & 37 deletions openbb_platform/core/openbb_core/app/model/custom_parameter.py

This file was deleted.

28 changes: 28 additions & 0 deletions openbb_platform/core/openbb_core/app/model/field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Custom field for OpenBB."""

from typing import Any, List, Optional

from pydantic.fields import FieldInfo


class OpenBBField(FieldInfo):
"""Custom field for OpenBB."""

def __repr__(self):
"""Override FieldInfo __repr__."""
# We use repr() to avoid decoding special characters like \n
if self.choices:
return f"OpenBBField(description={repr(self.description)}, choices={repr(self.choices)})"
return f"OpenBBField(description={repr(self.description)})"

def __init__(self, description: str, choices: Optional[List[Any]] = None):
"""Initialize OpenBBField."""
json_schema_extra = {"choices": choices} if choices else None
super().__init__(description=description, json_schema_extra=json_schema_extra) # type: ignore[arg-type]

@property
def choices(self) -> Optional[List[Any]]:
"""Custom choices."""
if self.json_schema_extra:
return self.json_schema_extra.get("choices") # type: ignore[union-attr,return-value]
return None
18 changes: 18 additions & 0 deletions openbb_platform/core/openbb_core/app/model/obbject.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ def to_dict(
del results["index"]
return results

def to_llm(self) -> Union[Dict[Hashable, Any], List[Dict[Hashable, Any]]]:
"""Convert results field to an LLM compatible output.
Returns
-------
Union[Dict[Hashable, Any], List[Dict[Hashable, Any]]]
Dictionary of lists or list of dictionaries if orient is "records".
"""
df = self.to_dataframe(index=None)

results = df.to_json(
orient="records",
date_format="iso",
date_unit="s",
)

return results

def show(self, **kwargs: Any) -> None:
"""Display chart."""
# pylint: disable=no-member
Expand Down
24 changes: 14 additions & 10 deletions openbb_platform/core/openbb_core/app/model/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@
class Preferences(BaseModel):
"""Preferences for the OpenBB platform."""

data_directory: str = str(Path.home() / "OpenBBUserData")
export_directory: str = str(Path.home() / "OpenBBUserData" / "exports")
user_styles_directory: str = str(Path.home() / "OpenBBUserData" / "styles" / "user")
cache_directory: str = str(Path.home() / "OpenBBUserData" / "cache")
chart_style: Literal["dark", "light"] = "dark"
data_directory: str = str(Path.home() / "OpenBBUserData")
export_directory: str = str(Path.home() / "OpenBBUserData" / "exports")
metadata: bool = True
output_type: Literal[
"OBBject", "dataframe", "polars", "numpy", "dict", "chart", "llm"
] = Field(
default="OBBject",
description="Python default output type.",
validate_default=True,
)
plot_enable_pywry: bool = True
plot_pywry_width: PositiveInt = 1400
plot_pywry_height: PositiveInt = 762
plot_open_export: bool = (
False # Whether to open plot image exports after they are created
)
table_style: Literal["dark", "light"] = "dark"
plot_pywry_height: PositiveInt = 762
plot_pywry_width: PositiveInt = 1400
request_timeout: PositiveInt = 15
metadata: bool = True
output_type: Literal["OBBject", "dataframe", "polars", "numpy", "dict", "chart"] = (
Field(default="OBBject", description="Python default output type.")
)
show_warnings: bool = True
table_style: Literal["dark", "light"] = "dark"
user_styles_directory: str = str(Path.home() / "OpenBBUserData" / "styles" / "user")

model_config = ConfigDict(validate_assignment=True)

Expand Down
23 changes: 23 additions & 0 deletions openbb_platform/core/openbb_core/app/model/python_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Python configuration settings model."""

from typing import List, Optional

from pydantic import BaseModel, Field, PositiveInt


class PythonSettings(BaseModel):
"""Settings model for Python interface configuration."""

docstring_sections: List[str] = Field(
default_factory=lambda: ["description", "parameters", "returns", "examples"],
description="Sections to include in autogenerated docstrings.",
)
docstring_max_length: Optional[PositiveInt] = Field(
default=None, description="Maximum length of autogenerated docstrings."
)

def __repr__(self) -> str:
"""Return a string representation of the model."""
return f"{self.__class__.__name__}\n\n" + "\n".join(
f"{k}: {v}" for k, v in self.model_dump().items()
)
8 changes: 6 additions & 2 deletions openbb_platform/core/openbb_core/app/model/system_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
USER_SETTINGS_PATH,
)
from openbb_core.app.model.abstract.tagged import Tagged
from openbb_core.app.model.fast_api_settings import FastAPISettings
from openbb_core.app.model.api_settings import APISettings
from openbb_core.app.model.python_settings import PythonSettings
from openbb_core.app.version import CORE_VERSION, VERSION


Expand Down Expand Up @@ -46,7 +47,10 @@ class SystemSettings(Tagged):
log_collect: bool = True

# API section
api_settings: FastAPISettings = Field(default_factory=FastAPISettings)
api_settings: APISettings = Field(default_factory=APISettings)

# Python section
python_settings: PythonSettings = Field(default_factory=PythonSettings)

# Others
debug_mode: bool = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SystemService(metaclass=SingletonMeta):
"headless",
"logging_sub_app",
"api_settings",
"python_settings",
"debug_mode",
}

Expand Down
Loading

0 comments on commit f8a754f

Please sign in to comment.