mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 01:09:05 +08:00
fix: replace Enum with StrEnum
This commit is contained in:
parent
93c3699128
commit
a61da6cf95
@ -1,4 +1,4 @@
|
|||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -69,7 +69,7 @@ class AgentEntity(BaseModel):
|
|||||||
Agent Entity.
|
Agent Entity.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Strategy(Enum):
|
class Strategy(StrEnum):
|
||||||
"""
|
"""
|
||||||
Agent Strategy.
|
Agent Strategy.
|
||||||
"""
|
"""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
|
|
||||||
class CommonParameterType(Enum):
|
class CommonParameterType(StrEnum):
|
||||||
SECRET_INPUT = "secret-input"
|
SECRET_INPUT = "secret-input"
|
||||||
TEXT_INPUT = "text-input"
|
TEXT_INPUT = "text-input"
|
||||||
SELECT = "select"
|
SELECT = "select"
|
||||||
@ -12,19 +12,20 @@ class CommonParameterType(Enum):
|
|||||||
SYSTEM_FILES = "system-files"
|
SYSTEM_FILES = "system-files"
|
||||||
BOOLEAN = "boolean"
|
BOOLEAN = "boolean"
|
||||||
APP_SELECTOR = "app-selector"
|
APP_SELECTOR = "app-selector"
|
||||||
# TOOL_SELECTOR = "tool-selector"
|
|
||||||
MODEL_SELECTOR = "model-selector"
|
MODEL_SELECTOR = "model-selector"
|
||||||
TOOLS_SELECTOR = "array[tools]"
|
TOOLS_SELECTOR = "array[tools]"
|
||||||
|
|
||||||
|
# TOOL_SELECTOR = "tool-selector"
|
||||||
|
|
||||||
class AppSelectorScope(Enum):
|
|
||||||
|
class AppSelectorScope(StrEnum):
|
||||||
ALL = "all"
|
ALL = "all"
|
||||||
CHAT = "chat"
|
CHAT = "chat"
|
||||||
WORKFLOW = "workflow"
|
WORKFLOW = "workflow"
|
||||||
COMPLETION = "completion"
|
COMPLETION = "completion"
|
||||||
|
|
||||||
|
|
||||||
class ModelSelectorScope(Enum):
|
class ModelSelectorScope(StrEnum):
|
||||||
LLM = "llm"
|
LLM = "llm"
|
||||||
TEXT_EMBEDDING = "text-embedding"
|
TEXT_EMBEDDING = "text-embedding"
|
||||||
RERANK = "rerank"
|
RERANK = "rerank"
|
||||||
@ -34,7 +35,7 @@ class ModelSelectorScope(Enum):
|
|||||||
VISION = "vision"
|
VISION = "vision"
|
||||||
|
|
||||||
|
|
||||||
class ToolSelectorScope(Enum):
|
class ToolSelectorScope(StrEnum):
|
||||||
ALL = "all"
|
ALL = "all"
|
||||||
CUSTOM = "custom"
|
CUSTOM = "custom"
|
||||||
BUILTIN = "builtin"
|
BUILTIN = "builtin"
|
||||||
|
@ -59,7 +59,7 @@ class PluginParameter(BaseModel):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
def as_normal_type(typ: enum.Enum):
|
def as_normal_type(typ: enum.StrEnum):
|
||||||
if typ.value in {
|
if typ.value in {
|
||||||
PluginParameterType.SECRET_INPUT,
|
PluginParameterType.SECRET_INPUT,
|
||||||
PluginParameterType.SELECT,
|
PluginParameterType.SELECT,
|
||||||
@ -68,7 +68,7 @@ def as_normal_type(typ: enum.Enum):
|
|||||||
return typ.value
|
return typ.value
|
||||||
|
|
||||||
|
|
||||||
def cast_parameter_value(typ: enum.Enum, value: Any, /):
|
def cast_parameter_value(typ: enum.StrEnum, value: Any, /):
|
||||||
try:
|
try:
|
||||||
match typ.value:
|
match typ.value:
|
||||||
case PluginParameterType.STRING | PluginParameterType.SECRET_INPUT | PluginParameterType.SELECT:
|
case PluginParameterType.STRING | PluginParameterType.SECRET_INPUT | PluginParameterType.SELECT:
|
||||||
@ -127,7 +127,7 @@ def cast_parameter_value(typ: enum.Enum, value: Any, /):
|
|||||||
raise ValueError(f"The tool parameter value {value} is not in correct type of {as_normal_type(typ)}.")
|
raise ValueError(f"The tool parameter value {value} is not in correct type of {as_normal_type(typ)}.")
|
||||||
|
|
||||||
|
|
||||||
def init_frontend_parameter(rule: PluginParameter, type: enum.Enum, value: Any):
|
def init_frontend_parameter(rule: PluginParameter, type: enum.StrEnum, value: Any):
|
||||||
"""
|
"""
|
||||||
init frontend parameter by rule
|
init frontend parameter by rule
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import enum
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
from typing import Generic, Optional, TypeVar
|
from typing import Generic, Optional, TypeVar
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
@ -31,7 +30,7 @@ class InstallPluginMessage(BaseModel):
|
|||||||
Message for installing a plugin.
|
Message for installing a plugin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Event(Enum):
|
class Event(StrEnum):
|
||||||
Info = "info"
|
Info = "info"
|
||||||
Done = "done"
|
Done = "done"
|
||||||
Error = "error"
|
Error = "error"
|
||||||
@ -127,7 +126,7 @@ class PluginDaemonInnerError(Exception):
|
|||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
class PluginInstallTaskStatus(enum.StrEnum):
|
class PluginInstallTaskStatus(StrEnum):
|
||||||
Pending = "pending"
|
Pending = "pending"
|
||||||
Running = "running"
|
Running = "running"
|
||||||
Success = "success"
|
Success = "success"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user