Harrison/multiline commands (#2280)

Co-authored-by: Marc Päpper <mpaepper@users.noreply.github.com>
doc
Harrison Chase 1 year ago committed by GitHub
parent a9dddd8a32
commit acfda4d1d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,9 +25,12 @@ class PythonREPLTool(BaseTool):
"with `print(...)`."
)
python_repl: PythonREPL = Field(default_factory=_get_default_python_repl)
sanitize_input: bool = True
def _run(self, query: str) -> str:
"""Use the tool."""
if self.sanitize_input:
query = query.strip().strip("```")
return self.python_repl.run(query)
async def _arun(self, query: str) -> str:

@ -1,6 +1,15 @@
"""Test functionality of Python REPL."""
from langchain.python import PythonREPL
from langchain.tools.python.tool import PythonREPLTool
_SAMPLE_CODE = """
```
def multiply():
print(5*6)
multiply()
```
"""
def test_python_repl() -> None:
@ -43,6 +52,14 @@ def test_functionality() -> None:
assert output == "2\n"
def test_functionality_multiline() -> None:
"""Test correct functionality for ChatGPT multiline commands."""
chain = PythonREPL()
tool = PythonREPLTool(python_repl=chain)
output = tool.run(_SAMPLE_CODE)
assert output == "30\n"
def test_function() -> None:
"""Test correct functionality."""
chain = PythonREPL()

Loading…
Cancel
Save