Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbosity flag. #21

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading