mirror of
https://github.com/hwchase17/langchain.git
synced 2026-01-25 14:35:49 +00:00
Fixed Ast Python Repl for Chatgpt multiline commands (#2406)
Resolves issue https://github.com/hwchase17/langchain/issues/2252 --------- Co-authored-by: Abhik Singla <abhiksingla@microsoft.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
"""Test functionality of Python REPL."""
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from langchain.python import PythonREPL
|
||||
from langchain.tools.python.tool import PythonREPLTool
|
||||
from langchain.tools.python.tool import PythonAstREPLTool, PythonREPLTool
|
||||
|
||||
_SAMPLE_CODE = """
|
||||
```
|
||||
@@ -11,6 +14,14 @@ multiply()
|
||||
```
|
||||
"""
|
||||
|
||||
_AST_SAMPLE_CODE = """
|
||||
```
|
||||
def multiply():
|
||||
return(5*6)
|
||||
multiply()
|
||||
```
|
||||
"""
|
||||
|
||||
|
||||
def test_python_repl() -> None:
|
||||
"""Test functionality when globals/locals are not provided."""
|
||||
@@ -60,6 +71,15 @@ def test_functionality_multiline() -> None:
|
||||
assert output == "30\n"
|
||||
|
||||
|
||||
def test_python_ast_repl_multiline() -> None:
|
||||
"""Test correct functionality for ChatGPT multiline commands."""
|
||||
if sys.version_info < (3, 9):
|
||||
pytest.skip("Python 3.9+ is required for this test")
|
||||
tool = PythonAstREPLTool()
|
||||
output = tool.run(_AST_SAMPLE_CODE)
|
||||
assert output == 30
|
||||
|
||||
|
||||
def test_function() -> None:
|
||||
"""Test correct functionality."""
|
||||
chain = PythonREPL()
|
||||
|
||||
Reference in New Issue
Block a user