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.
This commit is contained in:
parent
ade4511a87
commit
327758f00f
2 changed files with 3 additions and 4 deletions
|
@ -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)}"
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue