Allow changing perf timer log level. Info log time for webpage read

This commit is contained in:
Debanjum Singh Solanky 2024-10-15 17:56:21 -07:00
parent c841abe13f
commit 11c64791aa
3 changed files with 10 additions and 11 deletions

View file

@ -183,7 +183,7 @@ async def read_webpage_and_extract_content(
extracted_info = None
try:
if is_none_or_empty(content):
with timer(f"Reading web page with {web_scraper.value} at '{url}' took", logger):
with timer(f"Reading web page with {web_scraper.value} at '{url}' took", logger, log_level=logging.INFO):
if web_scraper == ServerChatSettings.WebScraper.FIRECRAWL:
if FIRECRAWL_TO_EXTRACT:
extracted_info = await read_webpage_and_extract_content_with_firecrawl(url, subqueries, agent)

View file

@ -571,7 +571,6 @@ async def extract_relevant_info(
personality_context=personality_context,
)
with timer("Chat actor: Extract relevant information from data", logger):
response = await send_message_to_model_wrapper(
extract_relevant_information,
prompts.system_prompt_extract_relevant_information,

View file

@ -164,9 +164,9 @@ def get_class_by_name(name: str) -> object:
class timer:
"""Context manager to log time taken for a block of code to run"""
def __init__(self, message: str, logger: logging.Logger, device: torch.device = None):
def __init__(self, message: str, logger: logging.Logger, device: torch.device = None, log_level=logging.DEBUG):
self.message = message
self.logger = logger
self.logger = logger.debug if log_level == logging.DEBUG else logger.info
self.device = device
def __enter__(self):
@ -176,9 +176,9 @@ class timer:
def __exit__(self, *_):
elapsed = perf_counter() - self.start
if self.device is None:
self.logger.debug(f"{self.message}: {elapsed:.3f} seconds")
self.logger(f"{self.message}: {elapsed:.3f} seconds")
else:
self.logger.debug(f"{self.message}: {elapsed:.3f} seconds on device: {self.device}")
self.logger(f"{self.message}: {elapsed:.3f} seconds on device: {self.device}")
class LRU(OrderedDict):