mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +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"
|
||||
BOOLEAN = "boolean"
|
||||
APP_SELECTOR = "app-selector"
|
||||
MODEL_CONFIG = "model-config"
|
||||
TOOL_SELECTOR = "tool-selector"
|
||||
MODEL_SELECTOR = "model-selector"
|
||||
|
||||
|
||||
class AppSelectorScope(Enum):
|
||||
|
@ -22,7 +23,7 @@ class AppSelectorScope(Enum):
|
|||
COMPLETION = "completion"
|
||||
|
||||
|
||||
class ModelConfigScope(Enum):
|
||||
class ModelSelectorScope(Enum):
|
||||
LLM = "llm"
|
||||
TEXT_EMBEDDING = "text-embedding"
|
||||
RERANK = "rerank"
|
||||
|
@ -30,3 +31,10 @@ class ModelConfigScope(Enum):
|
|||
SPEECH2TEXT = "speech2text"
|
||||
MODERATION = "moderation"
|
||||
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 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.tools.entities.common_entities import I18nObject
|
||||
|
||||
|
@ -168,7 +168,7 @@ class ProviderConfig(BasicProviderConfig):
|
|||
value: str = Field(..., description="The value 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
|
||||
default: Optional[Union[int, str]] = 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 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.tools.entities.common_entities import I18nObject
|
||||
|
||||
|
@ -209,6 +214,9 @@ class ToolParameter(BaseModel):
|
|||
SECRET_INPUT = CommonParameterType.SECRET_INPUT.value
|
||||
FILE = CommonParameterType.FILE.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.
|
||||
SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.value
|
||||
|
@ -271,6 +279,14 @@ class ToolParameter(BaseModel):
|
|||
else:
|
||||
return value[0]
|
||||
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 _:
|
||||
return str(value)
|
||||
|
||||
|
@ -287,7 +303,7 @@ class ToolParameter(BaseModel):
|
|||
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")
|
||||
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")
|
||||
llm_description: Optional[str] = None
|
||||
required: Optional[bool] = False
|
||||
|
|
Loading…
Reference in New Issue
Block a user