add async for python repl (#9080)

This commit is contained in:
Harrison Chase 2023-08-10 16:07:06 -07:00 committed by GitHub
parent 105c787e5a
commit 45f0f9460a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,3 +131,15 @@ class PythonAstREPLTool(BaseTool):
return io_buffer.getvalue() return io_buffer.getvalue()
except Exception as e: except Exception as e:
return "{}: {}".format(type(e).__name__, str(e)) return "{}: {}".format(type(e).__name__, str(e))
async def _arun(
self,
query: str,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> Any:
"""Use the tool asynchronously."""
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(None, self._run, query)
return result