Skip to content

Commit

Permalink
Merge pull request #21 from OpenBB-finance/misc/verbosity-flag
Browse files Browse the repository at this point in the history
Add verbosity flag.
  • Loading branch information
mnicstruwig authored May 31, 2024
2 parents 83257b4 + df66ab5 commit 4e24bae
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
16 changes: 12 additions & 4 deletions openbb_agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
get_valid_list_of_providers,
map_name_to_openbb_function_description,
)
from .utils import get_dependencies
from .utils import configure_logging, get_dependencies

logger = logging.getLogger(__name__)


def openbb_agent(
query: str, openbb_tools: list[str] | None = None, openbb_pat: str | None = None
query: str,
openbb_tools: list[str] | None = None,
openbb_pat: str | None = None,
verbose: bool = True,
) -> str:
"""Answer a query using the OpenBB Agent equipped with tools.
Expand Down Expand Up @@ -54,14 +57,16 @@ def openbb_agent(
... openbb_tools=['.equity.price.quote'])
"""
configure_logging(verbose)
if openbb_pat:
from openbb import obb

obb.account.login(pat=openbb_pat)

tool_vector_index = _handle_tool_vector_index(openbb_tools)
subquestions = generate_subquestions_from_query(user_query=query)

logger.info("Generating subquestions for user query: %s", query)
subquestions = generate_subquestions_from_query(user_query=query)
logger.info("Generated subquestions: %s", subquestions)

answered_subquestions = []
Expand All @@ -85,7 +90,9 @@ def openbb_agent(
)


async def aopenbb_agent(query: str, openbb_tools: list[str] | None = None) -> str:
async def aopenbb_agent(
query: str, openbb_tools: list[str] | None = None, verbose: bool = True
) -> str:
"""Answer a query using the OpenBB Agent equipped with tools.
Async variant of `openbb_agent`.
Expand All @@ -111,6 +118,7 @@ async def aopenbb_agent(query: str, openbb_tools: list[str] | None = None) -> st
... openbb_tools=['.equity.price.quote'])
"""
configure_logging(verbose)
tool_vector_index = _handle_tool_vector_index(openbb_tools)

subquestions = await agenerate_subquestions_from_query(user_query=query)
Expand Down
48 changes: 48 additions & 0 deletions openbb_agents/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
import logging.config
import os

from .models import AnsweredSubQuestion, SubQuestion
Expand All @@ -7,6 +9,52 @@ def get_verbosity() -> bool:
return os.environ.get("VERBOSE", "False") == "True"


def configure_logging(verbose: bool):
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "%(asctime)s - %(levelname)s - %(name)s - %(message)s",
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout", # Default is stderr
"formatter": "standard",
},
},
"loggers": {
"openbb_agents.agent": {
"handlers": ["console"],
"level": "INFO" if verbose else "CRITICAL",
"propagate": False,
},
"openbb_agents.utils": {
"handlers": ["console"],
"level": "INFO" if verbose else "CRITICAL",
"propagate": False,
},
"openbb_agents.tools": {
"handlers": ["console"],
"level": "INFO" if verbose else "CRITICAL",
"propagate": False,
},
"openbb_agents.chains": {
"handlers": ["console"],
"level": "INFO" if verbose else "CRITICAL",
"propagate": False,
},
},
"root": {
"handlers": ["console"],
"level": "WARNING" if verbose else "CRITICAL",
},
}
logging.config.dictConfig(logging_config)


def get_dependencies(
answered_subquestions: list[AnsweredSubQuestion], subquestion: SubQuestion
) -> list[AnsweredSubQuestion]:
Expand Down

0 comments on commit 4e24bae

Please sign in to comment.