mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 19:41:23 +00:00
feat: implement python repl tool arun (#7125)
Description: implement python repl tool arun Tag maintainer: @agola11
This commit is contained in:
parent
9cfb311ecb
commit
bf9e4ef35f
@ -1,6 +1,7 @@
|
|||||||
"""A tool for running python code in a REPL."""
|
"""A tool for running python code in a REPL."""
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
|
import asyncio
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
@ -68,7 +69,13 @@ class PythonREPLTool(BaseTool):
|
|||||||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Use the tool asynchronously."""
|
"""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):
|
class PythonAstREPLTool(BaseTool):
|
||||||
|
Loading…
Reference in New Issue
Block a user