feat: implement python repl tool arun (#7125)

Description: implement python repl tool arun
Tag maintainer: @agola11
This commit is contained in:
Shuqian 2023-07-05 08:15:49 +08:00 committed by GitHub
parent 9cfb311ecb
commit bf9e4ef35f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
"""A tool for running python code in a REPL."""
import ast
import asyncio
import re
import sys
from contextlib import redirect_stdout
@ -68,7 +69,13 @@ class PythonREPLTool(BaseTool):
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> Any:
"""Use the tool asynchronously."""
raise NotImplementedError("PythonReplTool does not support async")
if self.sanitize_input:
query = sanitize_input(query)
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(None, self.run, query)
return result
class PythonAstREPLTool(BaseTool):