From aa73019d700beff7e7cc1744dfffa957e2548b64 Mon Sep 17 00:00:00 2001 From: Hafeez <90968109+hafeezhmha@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:46:03 +0530 Subject: [PATCH] Update Self_Improving_Search.py for windows --- Self_Improving_Search.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Self_Improving_Search.py b/Self_Improving_Search.py index 2f3bd76..03cac8f 100644 --- a/Self_Improving_Search.py +++ b/Self_Improving_Search.py @@ -35,19 +35,20 @@ for name in ['root', 'duckduckgo_search', 'requests', 'urllib3']: logging.getLogger(name).propagate = False class OutputRedirector: - def __init__(self, stream=None): - self.stream = stream or StringIO() - self.original_stdout = sys.stdout - self.original_stderr = sys.stderr + """Windows-compatible output redirection""" + def __init__(self, stream=None): + self.stream = stream or StringIO() + self.original_stdout = sys.stdout + self.original_stderr = sys.stderr + + def __enter__(self): + sys.stdout = self.stream + sys.stderr = self.stream + return self.stream - def __enter__(self): - sys.stdout = self.stream - sys.stderr = self.stream - return self.stream - - def __exit__(self, exc_type, exc_val, exc_tb): - sys.stdout = self.original_stdout - sys.stderr = self.original_stderr + def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout = self.original_stdout + sys.stderr = self.original_stderr class EnhancedSelfImprovingSearch: def __init__(self, llm: LLMWrapper, parser: UltimateLLMResponseParser, max_attempts: int = 5):