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)
|
||||
except ValueError:
|
||||
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:
|
||||
params[field_name] = float(val)
|
||||
except ValueError:
|
||||
|
|
|
|||
|
|
@ -52,18 +52,7 @@ def python_function(text: str) -> str:
|
|||
|
||||
|
||||
PYTHON_BASIC_TYPES = [str, bool, int, float, tuple, list, dict, set]
|
||||
DIRECT_TYPES = [
|
||||
"str",
|
||||
"bool",
|
||||
"dict",
|
||||
"int",
|
||||
"float",
|
||||
"Any",
|
||||
"prompt",
|
||||
"code",
|
||||
"NestedDict",
|
||||
"table",
|
||||
]
|
||||
DIRECT_TYPES = ["str", "bool", "dict", "int", "float", "Any", "prompt", "code", "NestedDict", "table", "slider"]
|
||||
|
||||
|
||||
LOADERS_INFO: list[dict[str, Any]] = [
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from langflow.inputs.inputs import (
|
|||
NestedDictInput,
|
||||
PromptInput,
|
||||
SecretStrInput,
|
||||
SliderInput,
|
||||
StrInput,
|
||||
TableInput,
|
||||
)
|
||||
|
|
@ -30,6 +31,11 @@ def test_table_input_valid():
|
|||
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():
|
||||
with pytest.raises(ValidationError):
|
||||
TableInput(name="invalid_table", value="invalid")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue