mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 21:39:21 +08:00
feat: support app-selector, model-selector and tool-selector as parameters
This commit is contained in:
parent
e9d69f020a
commit
6baa98f166
@ -12,7 +12,8 @@ class CommonParameterType(Enum):
|
|||||||
SYSTEM_FILES = "system-files"
|
SYSTEM_FILES = "system-files"
|
||||||
BOOLEAN = "boolean"
|
BOOLEAN = "boolean"
|
||||||
APP_SELECTOR = "app-selector"
|
APP_SELECTOR = "app-selector"
|
||||||
MODEL_CONFIG = "model-config"
|
TOOL_SELECTOR = "tool-selector"
|
||||||
|
MODEL_SELECTOR = "model-selector"
|
||||||
|
|
||||||
|
|
||||||
class AppSelectorScope(Enum):
|
class AppSelectorScope(Enum):
|
||||||
@ -22,7 +23,7 @@ class AppSelectorScope(Enum):
|
|||||||
COMPLETION = "completion"
|
COMPLETION = "completion"
|
||||||
|
|
||||||
|
|
||||||
class ModelConfigScope(Enum):
|
class ModelSelectorScope(Enum):
|
||||||
LLM = "llm"
|
LLM = "llm"
|
||||||
TEXT_EMBEDDING = "text-embedding"
|
TEXT_EMBEDDING = "text-embedding"
|
||||||
RERANK = "rerank"
|
RERANK = "rerank"
|
||||||
@ -30,3 +31,10 @@ class ModelConfigScope(Enum):
|
|||||||
SPEECH2TEXT = "speech2text"
|
SPEECH2TEXT = "speech2text"
|
||||||
MODERATION = "moderation"
|
MODERATION = "moderation"
|
||||||
VISION = "vision"
|
VISION = "vision"
|
||||||
|
|
||||||
|
|
||||||
|
class ToolSelectorScope(Enum):
|
||||||
|
ALL = "all"
|
||||||
|
CUSTOM = "custom"
|
||||||
|
BUILTIN = "builtin"
|
||||||
|
WORKFLOW = "workflow"
|
||||||
|
@ -3,7 +3,7 @@ from typing import Optional, Union
|
|||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
from core.entities.parameter_entities import AppSelectorScope, CommonParameterType, ModelConfigScope
|
from core.entities.parameter_entities import AppSelectorScope, CommonParameterType, ModelSelectorScope
|
||||||
from core.model_runtime.entities.model_entities import ModelType
|
from core.model_runtime.entities.model_entities import ModelType
|
||||||
from core.tools.entities.common_entities import I18nObject
|
from core.tools.entities.common_entities import I18nObject
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ class ProviderConfig(BasicProviderConfig):
|
|||||||
value: str = Field(..., description="The value of the option")
|
value: str = Field(..., description="The value of the option")
|
||||||
label: I18nObject = Field(..., description="The label of the option")
|
label: I18nObject = Field(..., description="The label of the option")
|
||||||
|
|
||||||
scope: AppSelectorScope | ModelConfigScope | None = None
|
scope: AppSelectorScope | ModelSelectorScope | None = None
|
||||||
required: bool = False
|
required: bool = False
|
||||||
default: Optional[Union[int, str]] = None
|
default: Optional[Union[int, str]] = None
|
||||||
options: Optional[list[Option]] = None
|
options: Optional[list[Option]] = None
|
||||||
|
@ -5,7 +5,12 @@ from typing import Any, Optional, Union
|
|||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_serializer, field_validator
|
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_serializer, field_validator
|
||||||
|
|
||||||
from core.entities.parameter_entities import AppSelectorScope, CommonParameterType, ModelConfigScope
|
from core.entities.parameter_entities import (
|
||||||
|
AppSelectorScope,
|
||||||
|
CommonParameterType,
|
||||||
|
ModelSelectorScope,
|
||||||
|
ToolSelectorScope,
|
||||||
|
)
|
||||||
from core.entities.provider_entities import ProviderConfig
|
from core.entities.provider_entities import ProviderConfig
|
||||||
from core.tools.entities.common_entities import I18nObject
|
from core.tools.entities.common_entities import I18nObject
|
||||||
|
|
||||||
@ -209,6 +214,9 @@ class ToolParameter(BaseModel):
|
|||||||
SECRET_INPUT = CommonParameterType.SECRET_INPUT.value
|
SECRET_INPUT = CommonParameterType.SECRET_INPUT.value
|
||||||
FILE = CommonParameterType.FILE.value
|
FILE = CommonParameterType.FILE.value
|
||||||
FILES = CommonParameterType.FILES.value
|
FILES = CommonParameterType.FILES.value
|
||||||
|
APP_SELECTOR = CommonParameterType.APP_SELECTOR.value
|
||||||
|
TOOL_SELECTOR = CommonParameterType.TOOL_SELECTOR.value
|
||||||
|
MODEL_SELECTOR = CommonParameterType.MODEL_SELECTOR.value
|
||||||
|
|
||||||
# deprecated, should not use.
|
# deprecated, should not use.
|
||||||
SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
|
SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
|
||||||
@ -271,6 +279,14 @@ class ToolParameter(BaseModel):
|
|||||||
else:
|
else:
|
||||||
return value[0]
|
return value[0]
|
||||||
return value
|
return value
|
||||||
|
case (
|
||||||
|
ToolParameter.ToolParameterType.TOOL_SELECTOR
|
||||||
|
| ToolParameter.ToolParameterType.MODEL_SELECTOR
|
||||||
|
| ToolParameter.ToolParameterType.APP_SELECTOR
|
||||||
|
):
|
||||||
|
if not isinstance(value, dict):
|
||||||
|
raise ValueError("The selector must be a dictionary.")
|
||||||
|
return value
|
||||||
case _:
|
case _:
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
@ -287,7 +303,7 @@ class ToolParameter(BaseModel):
|
|||||||
human_description: Optional[I18nObject] = Field(default=None, description="The description presented to the user")
|
human_description: Optional[I18nObject] = Field(default=None, description="The description presented to the user")
|
||||||
placeholder: Optional[I18nObject] = Field(default=None, description="The placeholder presented to the user")
|
placeholder: Optional[I18nObject] = Field(default=None, description="The placeholder presented to the user")
|
||||||
type: ToolParameterType = Field(..., description="The type of the parameter")
|
type: ToolParameterType = Field(..., description="The type of the parameter")
|
||||||
scope: AppSelectorScope | ModelConfigScope | None = None
|
scope: AppSelectorScope | ModelSelectorScope | ToolSelectorScope | None = None
|
||||||
form: ToolParameterForm = Field(..., description="The form of the parameter, schema/form/llm")
|
form: ToolParameterForm = Field(..., description="The form of the parameter, schema/form/llm")
|
||||||
llm_description: Optional[str] = None
|
llm_description: Optional[str] = None
|
||||||
required: Optional[bool] = False
|
required: Optional[bool] = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user