mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat(api): Implement checkbox input support in Workflow and Chat App
This commit is contained in:
@ -3,6 +3,17 @@ import re
|
|||||||
from core.app.app_config.entities import ExternalDataVariableEntity, VariableEntity, VariableEntityType
|
from core.app.app_config.entities import ExternalDataVariableEntity, VariableEntity, VariableEntityType
|
||||||
from core.external_data_tool.factory import ExternalDataToolFactory
|
from core.external_data_tool.factory import ExternalDataToolFactory
|
||||||
|
|
||||||
|
_ALLOWED_VARIABLE_ENTITY_TYPE = frozenset(
|
||||||
|
[
|
||||||
|
VariableEntityType.TEXT_INPUT,
|
||||||
|
VariableEntityType.SELECT,
|
||||||
|
VariableEntityType.PARAGRAPH,
|
||||||
|
VariableEntityType.NUMBER,
|
||||||
|
VariableEntityType.EXTERNAL_DATA_TOOL,
|
||||||
|
VariableEntityType.CHECKBOX,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BasicVariablesConfigManager:
|
class BasicVariablesConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -47,6 +58,7 @@ class BasicVariablesConfigManager:
|
|||||||
VariableEntityType.PARAGRAPH,
|
VariableEntityType.PARAGRAPH,
|
||||||
VariableEntityType.NUMBER,
|
VariableEntityType.NUMBER,
|
||||||
VariableEntityType.SELECT,
|
VariableEntityType.SELECT,
|
||||||
|
VariableEntityType.CHECKBOX,
|
||||||
}:
|
}:
|
||||||
variable = variables[variable_type]
|
variable = variables[variable_type]
|
||||||
variable_entities.append(
|
variable_entities.append(
|
||||||
@ -96,8 +108,17 @@ class BasicVariablesConfigManager:
|
|||||||
variables = []
|
variables = []
|
||||||
for item in config["user_input_form"]:
|
for item in config["user_input_form"]:
|
||||||
key = list(item.keys())[0]
|
key = list(item.keys())[0]
|
||||||
if key not in {"text-input", "select", "paragraph", "number", "external_data_tool"}:
|
# if key not in {"text-input", "select", "paragraph", "number", "external_data_tool"}:
|
||||||
raise ValueError("Keys in user_input_form list can only be 'text-input', 'paragraph' or 'select'")
|
if key not in {
|
||||||
|
VariableEntityType.TEXT_INPUT,
|
||||||
|
VariableEntityType.SELECT,
|
||||||
|
VariableEntityType.PARAGRAPH,
|
||||||
|
VariableEntityType.NUMBER,
|
||||||
|
VariableEntityType.EXTERNAL_DATA_TOOL,
|
||||||
|
VariableEntityType.CHECKBOX,
|
||||||
|
}:
|
||||||
|
allowed_keys = ", ".join(i.value for i in _ALLOWED_VARIABLE_ENTITY_TYPE)
|
||||||
|
raise ValueError(f"Keys in user_input_form list can only be {allowed_keys}")
|
||||||
|
|
||||||
form_item = item[key]
|
form_item = item[key]
|
||||||
if "label" not in form_item:
|
if "label" not in form_item:
|
||||||
|
|||||||
@ -97,6 +97,7 @@ class VariableEntityType(StrEnum):
|
|||||||
EXTERNAL_DATA_TOOL = "external_data_tool"
|
EXTERNAL_DATA_TOOL = "external_data_tool"
|
||||||
FILE = "file"
|
FILE = "file"
|
||||||
FILE_LIST = "file-list"
|
FILE_LIST = "file-list"
|
||||||
|
CHECKBOX = "checkbox"
|
||||||
|
|
||||||
|
|
||||||
class VariableEntity(BaseModel):
|
class VariableEntity(BaseModel):
|
||||||
|
|||||||
@ -144,6 +144,11 @@ class BaseAppGenerator:
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"{variable_entity.variable} in input form must be less than {variable_entity.max_length} files"
|
f"{variable_entity.variable} in input form must be less than {variable_entity.max_length} files"
|
||||||
)
|
)
|
||||||
|
case VariableEntityType.CHECKBOX:
|
||||||
|
if not isinstance(value, bool):
|
||||||
|
raise ValueError(f"{variable_entity.variable} in input form must be a valid boolean value")
|
||||||
|
case _:
|
||||||
|
raise AssertionError("this statement should be unreachable.")
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user