mirror of
https://github.com/langgenius/dify.git
synced 2026-03-04 15:26:21 +08:00
50 lines
1009 B
Python
50 lines
1009 B
Python
from collections.abc import Sequence
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
SupportedComparisonOperator = Literal[
|
|
# for string or array
|
|
"contains",
|
|
"not contains",
|
|
"start with",
|
|
"end with",
|
|
"is",
|
|
"is not",
|
|
"empty",
|
|
"not empty",
|
|
"in",
|
|
"not in",
|
|
"all of",
|
|
# for number
|
|
"=",
|
|
"≠",
|
|
">",
|
|
"<",
|
|
"≥",
|
|
"≤",
|
|
"null",
|
|
"not null",
|
|
# for file
|
|
"exists",
|
|
"not exists",
|
|
]
|
|
|
|
|
|
class SubCondition(BaseModel):
|
|
key: str
|
|
comparison_operator: SupportedComparisonOperator
|
|
value: str | Sequence[str] | None = None
|
|
|
|
|
|
class SubVariableCondition(BaseModel):
|
|
logical_operator: Literal["and", "or"]
|
|
conditions: list[SubCondition] = Field(default_factory=list)
|
|
|
|
|
|
class Condition(BaseModel):
|
|
variable_selector: list[str]
|
|
comparison_operator: SupportedComparisonOperator
|
|
value: str | Sequence[str] | bool | None = None
|
|
sub_variable_condition: SubVariableCondition | None = None
|