From 1c3321d7c981e1fc08f239167ceb7cdfa702c63f Mon Sep 17 00:00:00 2001 From: Charlie Leopard Date: Tue, 29 Oct 2024 16:43:00 +0000 Subject: [PATCH] FS-70: Simplify logs by removing or demoting logs to debug (#9) --- backend/src/api/app.py | 1 - backend/src/llm/count_calls.py | 2 +- backend/src/llm/openai.py | 10 +++++++--- backend/src/router.py | 5 +---- backend/src/session/redis_session_middleware.py | 1 - backend/src/suggestions_generator.py | 5 +---- backend/src/supervisors/supervisor.py | 2 +- backend/src/utils/scratchpad.py | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/backend/src/api/app.py b/backend/src/api/app.py index 2588e3b55..50cdbab68 100644 --- a/backend/src/api/app.py +++ b/backend/src/api/app.py @@ -98,7 +98,6 @@ async def suggestions(): logger.info("Requesting chat suggestions") try: final_result = await generate_suggestions() - logger.info(f"Chat suggestions: {final_result}") return JSONResponse(status_code=200, content=final_result) except Exception as e: logger.exception(e) diff --git a/backend/src/llm/count_calls.py b/backend/src/llm/count_calls.py index a1fd9e6e5..13df1d71f 100644 --- a/backend/src/llm/count_calls.py +++ b/backend/src/llm/count_calls.py @@ -22,7 +22,7 @@ def reset(self): def count_calls(func): def wrapper(self=None, *args, **kwargs): counter.increment() - logging.info(f"Function {func.__name__} has been called {counter.count} times") + logging.debug(f"Function {func.__name__} has been called {counter.count} times") return func(self, *args, **kwargs) counter.reset() diff --git a/backend/src/llm/openai.py b/backend/src/llm/openai.py index a16be9f31..838b6944d 100644 --- a/backend/src/llm/openai.py +++ b/backend/src/llm/openai.py @@ -28,10 +28,14 @@ async def chat(self, model, system_prompt: str, user_prompt: str, return_json=Fa {"role": "user", "content": user_prompt}, ], temperature=0, - response_format={"type": "json_object"} if return_json else NOT_GIVEN, + response_format={ + "type": "json_object"} if return_json else NOT_GIVEN, ) - logger.info("OpenAI response: {0}".format(response)) content = response.choices[0].message.content + logger.info(f"OpenAI response: Finish reason: { + response.choices[0].finish_reason}, Content: {content}") + logger.debug(f"Token data: {response.usage}") + if isinstance(content, str): return content elif isinstance(content, list): @@ -39,5 +43,5 @@ async def chat(self, model, system_prompt: str, user_prompt: str, return_json=Fa else: return "Unexpected content format" except Exception as e: - logger.error("Error calling OpenAI model: {0}".format(e)) + logger.error(f"Error calling OpenAI model: {e}") return "An error occurred while processing the request." diff --git a/backend/src/router.py b/backend/src/router.py index 46be54cae..1784b8d26 100644 --- a/backend/src/router.py +++ b/backend/src/router.py @@ -33,10 +33,7 @@ async def build_plan(task, llm: LLM, scratchpad, model): await publish_log_info(LogPrefix.USER, f"Scratchpad so far: {scratchpad}", __name__) best_next_step = await llm.chat(model, response_format_prompt, best_next_step_prompt, return_json=True) - plan = to_json(best_next_step, "Failed to interpret LLM next step format from step string") - await publish_log_info(LogPrefix.USER, f"Next best step response: {json.dumps(plan, indent=4)}", __name__) - - return plan + return to_json(best_next_step, "Failed to interpret LLM next step format from step string") def find_agent_from_name(name): diff --git a/backend/src/session/redis_session_middleware.py b/backend/src/session/redis_session_middleware.py index fef8d4ded..41b280145 100644 --- a/backend/src/session/redis_session_middleware.py +++ b/backend/src/session/redis_session_middleware.py @@ -66,7 +66,6 @@ def get_redis_session(request: Request): if session_data and isinstance(session_data, str): parsed_session_data = try_parse_to_json(session_data) if parsed_session_data: - logger.info(f"Parsed session data: {parsed_session_data}") return parsed_session_data return {} diff --git a/backend/src/suggestions_generator.py b/backend/src/suggestions_generator.py index d28ba1350..cbe794bd1 100644 --- a/backend/src/suggestions_generator.py +++ b/backend/src/suggestions_generator.py @@ -5,11 +5,8 @@ from src.session import Message, get_session_chat from src.utils.config import Config -import logging - config = Config() engine = PromptEngine() -logger = logging.getLogger(__name__) suggestions_prompt = engine.load_prompt("generate_message_suggestions") model = config.suggestions_model @@ -38,7 +35,7 @@ def get_suggestions_model() -> str: def get_chat_history() -> List[str] | str: max_history_length = 4 raw_history = get_session_chat() - logger.info(f"Raw history: {raw_history}") + if raw_history is None: return "No chat history available." diff --git a/backend/src/supervisors/supervisor.py b/backend/src/supervisors/supervisor.py index 85c030e00..5b960d53f 100644 --- a/backend/src/supervisors/supervisor.py +++ b/backend/src/supervisors/supervisor.py @@ -33,9 +33,9 @@ async def solve_task(task, scratchpad, attempt=0) -> Tuple[str, str, str]: raise Exception(unsolvable_response) agent = await get_agent_for_task(task, scratchpad) - logger.info(f"Agent selected: {agent}") if agent is None: raise Exception(no_agent_response) + logger.info(f"Agent selected: {agent.name}") logger.info(f"Task is {task}") answer = await agent.invoke(task) parsed_json = json.loads(answer) diff --git a/backend/src/utils/scratchpad.py b/backend/src/utils/scratchpad.py index fad998c21..aa280c21b 100644 --- a/backend/src/utils/scratchpad.py +++ b/backend/src/utils/scratchpad.py @@ -25,5 +25,5 @@ def update_scratchpad(agent_name=None, question=None, result=None, error=None): def clear_scratchpad(): - logger.info("Scratchpad cleared") + logger.debug("Scratchpad cleared") scratchpad.clear()