Cadlabs/python tool sanitization (#4754)

Co-authored-by: BenSchZA <BenSchZA@users.noreply.github.com>
This commit is contained in:
Davis Chase
2023-05-17 19:46:12 -07:00
committed by GitHub
parent 0dc304ca80
commit e28bdf4453
2 changed files with 45 additions and 4 deletions

View File

@@ -3,7 +3,11 @@ import sys
import pytest
from langchain.tools.python.tool import PythonAstREPLTool, PythonREPLTool
from langchain.tools.python.tool import (
PythonAstREPLTool,
PythonREPLTool,
sanitize_input,
)
def test_python_repl_tool_single_input() -> None:
@@ -21,3 +25,30 @@ def test_python_ast_repl_tool_single_input() -> None:
tool = PythonAstREPLTool()
assert tool.is_single_input
assert tool.run("1 + 1") == 2
def test_sanitize_input() -> None:
query = """
```
p = 5
```
"""
expected = "p = 5"
actual = sanitize_input(query)
assert expected == actual
query = """
```python
p = 5
```
"""
expected = "p = 5"
actual = sanitize_input(query)
assert expected == actual
query = """
p = 5
"""
expected = "p = 5"
actual = sanitize_input(query)
assert expected == actual