From 327758f00f4f5c5bd8d0dcd66a1d3f49262140fd Mon Sep 17 00:00:00 2001 From: ThomasTaroni Date: Fri, 25 Apr 2025 18:42:40 +0200 Subject: [PATCH] Refactor async logging logic in report generation. Removed unused log yielding in `main.py` to simplify the flow. Updated `send_json` in `deepresearch.py` to use an async generator for more flexible streaming of log data. --- src/main.py | 2 -- src/phoenix_technologies/gptresearch/deepresearch.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index b223552..f147b19 100644 --- a/src/main.py +++ b/src/main.py @@ -38,8 +38,6 @@ async def get_report_endpoint(request: ReportRequest): # Call the asynchronous get_report function generator = ReportGenerator(request.query, request.report_type) await generator.generate_report() - async for log in generator: - yield log except Exception as e: yield f"Error: {str(e)}" diff --git a/src/phoenix_technologies/gptresearch/deepresearch.py b/src/phoenix_technologies/gptresearch/deepresearch.py index d8e0adc..3724c99 100644 --- a/src/phoenix_technologies/gptresearch/deepresearch.py +++ b/src/phoenix_technologies/gptresearch/deepresearch.py @@ -9,10 +9,11 @@ class CustomLogsHandler: logs = [] self.logs = logs # Initialize logs to store data - async def send_json(self, data: Dict[str, Any]) -> None: + async def send_json(self, data: Dict[str, Any]) -> AsyncGenerator[str, Any]: """Send JSON data and log it.""" self.logs.append(data) # Append data to logs - print(f"My custom Log: {data}") # For demonstration, print the log + print(f"My custom Log: {data}") + yield f"My custom Log: {data}" class ReportGenerator: def __init__(self, query: str, report_type: str):