Skip to content

Commit

Permalink
Merge pull request #962 from DhruvKadam-git/master
Browse files Browse the repository at this point in the history
Update gptr-logs-handler.py
assafelovic authored Oct 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 2e429d6 + 5b0aa21 commit e1f0fc5
Showing 1 changed file with 23 additions and 14 deletions.
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(
@@ -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

0 comments on commit e1f0fc5

Please sign in to comment.