We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
exec command in PythonAstREPLTool is executed before redirecting the standard output.
Exec command should be moved under 'redirect_stdout' block like below.
def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Use the tool.""" try: if self.sanitize_input: query = sanitize_input(query) tree = ast.parse(query) module = ast.Module(tree.body[:-1], type_ignores=[]) # exec(ast.unparse(module), self.globals, self.locals) module_end = ast.Module(tree.body[-1:], type_ignores=[]) module_end_str = ast.unparse(module_end) # type: ignore io_buffer = StringIO() try: with redirect_stdout(io_buffer): # ------------------> moved exec command from above to here <--------------------------- exec(ast.unparse(module), self.globals, self.locals) ret = eval(module_end_str, self.globals, self.locals) if ret is None: return io_buffer.getvalue() else: return ret except Exception: with redirect_stdout(io_buffer): exec(module_end_str, self.globals, self.locals) return io_buffer.getvalue() except Exception as e: return "{}: {}".format(type(e).__name__, str(e))
The text was updated successfully, but these errors were encountered:
No branches or pull requests
exec command in PythonAstREPLTool is executed before redirecting the standard output.
Exec command should be moved under 'redirect_stdout' block like below.
The text was updated successfully, but these errors were encountered: