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

Update gptr-logs-handler.py #962

Merged
merged 1 commit into from
Oct 29, 2024
Merged
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
37 changes: 23 additions & 14 deletions tests/gptr-logs-handler.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
from typing import Dict, Any
import logging
from typing import List, Dict, Any
import asyncio
from gpt_researcher import GPTResearcher

class CustomLogsHandler:
"""A custom Logs handler class to handle JSON data."""
def __init__(self):
self.logs = [] # Initialize logs to store data
self.logs: List[Dict[str, Any]] = [] # Initialize logs to store data
logging.basicConfig(level=logging.INFO) # Set up logging configuration

async def send_json(self, data: Dict[str, Any]) -> None:
"""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

async def run():
# Define the necessary parameters with sample values

"""Send JSON data and log it, with error handling."""
try:
self.logs.append(data) # Append data to logs
logging.info(f"My custom Log: {data}") # Use logging instead of print
except Exception as e:
logging.error(f"Error logging data: {e}") # Log any errors

def clear_logs(self) -> None:
"""Clear the logs."""
self.logs.clear() # Clear the logs list
logging.info("Logs cleared.") # Log the clearing action

async def run() -> None:
"""Run the research process and generate a report."""
query = "What happened in the latest burning man floods?"
report_type = "research_report" # Type of report to generate
report_source = "online" # Could specify source like 'online', 'books', etc.
tone = "informative" # Tone of the report ('informative', 'casual', etc.)
config_path = None # Path to a config file, if needed
report_type = "research_report"
report_source = "online"
tone = "informative"
config_path = None

# Initialize researcher with a custom WebSocket
custom_logs_handler = CustomLogsHandler()

researcher = GPTResearcher(
Expand All @@ -35,6 +43,7 @@ async def run():

await researcher.conduct_research() # Conduct the research
report = await researcher.write_report() # Write the research report
logging.info("Report generated successfully.") # Log report generation

return report

Expand Down