fix: pass slider input values correctly, add test (#5735)
* ✨ (base.py): Update field validation to include "slider" type in addition to "float" type for better parameter handling 📝 (constants.py): Add "slider" type to the list of DIRECT_TYPES for consistency and completeness * ✅ (test_inputs.py): add unit test for SliderInput class to ensure it initializes with correct value * 🐛 (base.py): fix comparison of field type with a list by changing it to a set to ensure correct condition evaluation * [autofix.ci] apply automated fixes * fix format * [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
99f2ef6115
commit
c39bb39772
3 changed files with 8 additions and 13 deletions
|
|
@ -395,7 +395,7 @@ class Vertex:
|
||||||
params[field_name] = int(val)
|
params[field_name] = int(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
params[field_name] = val
|
params[field_name] = val
|
||||||
elif field.get("type") == "float" and val is not None:
|
elif field.get("type") in {"float", "slider"} and val is not None:
|
||||||
try:
|
try:
|
||||||
params[field_name] = float(val)
|
params[field_name] = float(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,7 @@ def python_function(text: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
PYTHON_BASIC_TYPES = [str, bool, int, float, tuple, list, dict, set]
|
PYTHON_BASIC_TYPES = [str, bool, int, float, tuple, list, dict, set]
|
||||||
DIRECT_TYPES = [
|
DIRECT_TYPES = ["str", "bool", "dict", "int", "float", "Any", "prompt", "code", "NestedDict", "table", "slider"]
|
||||||
"str",
|
|
||||||
"bool",
|
|
||||||
"dict",
|
|
||||||
"int",
|
|
||||||
"float",
|
|
||||||
"Any",
|
|
||||||
"prompt",
|
|
||||||
"code",
|
|
||||||
"NestedDict",
|
|
||||||
"table",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
LOADERS_INFO: list[dict[str, Any]] = [
|
LOADERS_INFO: list[dict[str, Any]] = [
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from langflow.inputs.inputs import (
|
||||||
NestedDictInput,
|
NestedDictInput,
|
||||||
PromptInput,
|
PromptInput,
|
||||||
SecretStrInput,
|
SecretStrInput,
|
||||||
|
SliderInput,
|
||||||
StrInput,
|
StrInput,
|
||||||
TableInput,
|
TableInput,
|
||||||
)
|
)
|
||||||
|
|
@ -30,6 +31,11 @@ def test_table_input_valid():
|
||||||
assert data.value == [{"key": "value"}, {"key2": "value2"}]
|
assert data.value == [{"key": "value"}, {"key2": "value2"}]
|
||||||
|
|
||||||
|
|
||||||
|
def test_slider_input_valid():
|
||||||
|
data = SliderInput(name="valid_slider", value=10)
|
||||||
|
assert data.value == 10
|
||||||
|
|
||||||
|
|
||||||
def test_table_input_invalid():
|
def test_table_input_invalid():
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
TableInput(name="invalid_table", value="invalid")
|
TableInput(name="invalid_table", value="invalid")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue