fix: pythonfunction component execution (#3747)
* Added CodeInput to types * Fixed PythonFunction to execute and return data or message * [autofix.ci] apply automated fixes * Added callable to outputs of pythonfunction * [autofix.ci] apply automated fixes * Updated function and tests * Fixed lint issues * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
bf640be53f
commit
0b1198efc4
7 changed files with 94 additions and 17 deletions
|
|
@ -3,6 +3,7 @@ from pydantic import ValidationError
|
|||
|
||||
from langflow.inputs.inputs import (
|
||||
BoolInput,
|
||||
CodeInput,
|
||||
DataInput,
|
||||
DictInput,
|
||||
DropdownInput,
|
||||
|
|
@ -99,6 +100,11 @@ def test_prompt_input_valid():
|
|||
assert prompt_input.value == "Enter your name"
|
||||
|
||||
|
||||
def test_code_input_valid():
|
||||
code_input = CodeInput(name="valid_code", value="def hello():\n print('Hello, World!')")
|
||||
assert code_input.value == "def hello():\n print('Hello, World!')"
|
||||
|
||||
|
||||
def test_multiline_input_valid():
|
||||
multiline_input = MultilineInput(name="valid_multiline", value="This is a\nmultiline input")
|
||||
assert multiline_input.value == "This is a\nmultiline input"
|
||||
|
|
@ -214,7 +220,10 @@ def test_instantiate_input_comprehensive():
|
|||
"FloatInput": {"name": "float_input", "value": 10.5},
|
||||
"BoolInput": {"name": "bool_input", "value": True},
|
||||
"DictInput": {"name": "dict_input", "value": {"key": "value"}},
|
||||
"MultiselectInput": {"name": "multiselect_input", "value": ["option1", "option2"]},
|
||||
"MultiselectInput": {
|
||||
"name": "multiselect_input",
|
||||
"value": ["option1", "option2"],
|
||||
},
|
||||
}
|
||||
|
||||
for input_type, data in valid_data.items():
|
||||
|
|
|
|||
|
|
@ -14,8 +14,13 @@ def test_python_function_component():
|
|||
# Act
|
||||
# function must be a string representation
|
||||
function = "def function():\n return 'Hello, World!'"
|
||||
python_function_component.function_code = function
|
||||
# result is the callable function
|
||||
result = python_function_component.build(function)
|
||||
result = python_function_component.get_function_callable()
|
||||
result_message = python_function_component.execute_function_message()
|
||||
result_data = python_function_component.execute_function_data()
|
||||
|
||||
# Assert
|
||||
assert result() == "Hello, World!"
|
||||
assert result_message.text == "Hello, World!"
|
||||
assert result_data[0].text == "Hello, World!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue