mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 00:18:03 +08:00
add workflow logics
This commit is contained in:
@ -6,7 +6,6 @@ from core.application_queue_manager import ApplicationQueueManager, PublishFrom
|
||||
from core.callback_handler.index_tool_callback_handler import DatasetIndexToolCallbackHandler
|
||||
from core.entities.application_entities import (
|
||||
ApplicationGenerateEntity,
|
||||
AppMode,
|
||||
DatasetEntity,
|
||||
InvokeFrom,
|
||||
ModelConfigEntity,
|
||||
@ -16,7 +15,7 @@ from core.memory.token_buffer_memory import TokenBufferMemory
|
||||
from core.model_manager import ModelInstance
|
||||
from core.moderation.base import ModerationException
|
||||
from extensions.ext_database import db
|
||||
from models.model import App, Conversation, Message
|
||||
from models.model import App, Conversation, Message, AppMode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -250,6 +249,7 @@ class BasicApplicationRunner(AppRunner):
|
||||
invoke_from
|
||||
)
|
||||
|
||||
# TODO
|
||||
if (app_record.mode == AppMode.COMPLETION.value and dataset_config
|
||||
and dataset_config.retrieve_config.query_variable):
|
||||
query = inputs.get(dataset_config.retrieve_config.query_variable, "")
|
||||
|
||||
@ -28,7 +28,7 @@ from core.entities.application_entities import (
|
||||
ModelConfigEntity,
|
||||
PromptTemplateEntity,
|
||||
SensitiveWordAvoidanceEntity,
|
||||
TextToSpeechEntity,
|
||||
TextToSpeechEntity, VariableEntity,
|
||||
)
|
||||
from core.entities.model_entities import ModelStatus
|
||||
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
|
||||
@ -93,7 +93,7 @@ class ApplicationManager:
|
||||
app_id=app_id,
|
||||
app_model_config_id=app_model_config_id,
|
||||
app_model_config_dict=app_model_config_dict,
|
||||
app_orchestration_config_entity=self._convert_from_app_model_config_dict(
|
||||
app_orchestration_config_entity=self.convert_from_app_model_config_dict(
|
||||
tenant_id=tenant_id,
|
||||
app_model_config_dict=app_model_config_dict
|
||||
),
|
||||
@ -234,7 +234,7 @@ class ApplicationManager:
|
||||
logger.exception(e)
|
||||
raise e
|
||||
|
||||
def _convert_from_app_model_config_dict(self, tenant_id: str, app_model_config_dict: dict) \
|
||||
def convert_from_app_model_config_dict(self, tenant_id: str, app_model_config_dict: dict) \
|
||||
-> AppOrchestrationConfigEntity:
|
||||
"""
|
||||
Convert app model config dict to entity.
|
||||
@ -384,8 +384,10 @@ class ApplicationManager:
|
||||
config=external_data_tool['config']
|
||||
)
|
||||
)
|
||||
|
||||
properties['variables'] = []
|
||||
|
||||
# current external_data_tools
|
||||
# variables and external_data_tools
|
||||
for variable in copy_app_model_config_dict.get('user_input_form', []):
|
||||
typ = list(variable.keys())[0]
|
||||
if typ == 'external_data_tool':
|
||||
@ -397,6 +399,30 @@ class ApplicationManager:
|
||||
config=val['config']
|
||||
)
|
||||
)
|
||||
elif typ in [VariableEntity.Type.TEXT_INPUT.value, VariableEntity.Type.PARAGRAPH.value]:
|
||||
properties['variables'].append(
|
||||
VariableEntity(
|
||||
type=VariableEntity.Type.TEXT_INPUT,
|
||||
variable=variable[typ].get('variable'),
|
||||
description=variable[typ].get('description'),
|
||||
label=variable[typ].get('label'),
|
||||
required=variable[typ].get('required', False),
|
||||
max_length=variable[typ].get('max_length'),
|
||||
default=variable[typ].get('default'),
|
||||
)
|
||||
)
|
||||
elif typ == VariableEntity.Type.SELECT.value:
|
||||
properties['variables'].append(
|
||||
VariableEntity(
|
||||
type=VariableEntity.Type.SELECT,
|
||||
variable=variable[typ].get('variable'),
|
||||
description=variable[typ].get('description'),
|
||||
label=variable[typ].get('label'),
|
||||
required=variable[typ].get('required', False),
|
||||
options=variable[typ].get('options'),
|
||||
default=variable[typ].get('default'),
|
||||
)
|
||||
)
|
||||
|
||||
# show retrieve source
|
||||
show_retrieve_source = False
|
||||
|
||||
@ -9,26 +9,6 @@ from core.model_runtime.entities.message_entities import PromptMessageRole
|
||||
from core.model_runtime.entities.model_entities import AIModelEntity
|
||||
|
||||
|
||||
class AppMode(Enum):
|
||||
COMPLETION = 'completion' # will be deprecated in the future
|
||||
WORKFLOW = 'workflow' # instead of 'completion'
|
||||
CHAT = 'chat'
|
||||
AGENT = 'agent'
|
||||
|
||||
@classmethod
|
||||
def value_of(cls, value: str) -> 'AppMode':
|
||||
"""
|
||||
Get value of given mode.
|
||||
|
||||
:param value: mode value
|
||||
:return: mode
|
||||
"""
|
||||
for mode in cls:
|
||||
if mode.value == value:
|
||||
return mode
|
||||
raise ValueError(f'invalid mode value {value}')
|
||||
|
||||
|
||||
class ModelConfigEntity(BaseModel):
|
||||
"""
|
||||
Model Config Entity.
|
||||
@ -106,6 +86,38 @@ class PromptTemplateEntity(BaseModel):
|
||||
advanced_completion_prompt_template: Optional[AdvancedCompletionPromptTemplateEntity] = None
|
||||
|
||||
|
||||
class VariableEntity(BaseModel):
|
||||
"""
|
||||
Variable Entity.
|
||||
"""
|
||||
class Type(Enum):
|
||||
TEXT_INPUT = 'text-input'
|
||||
SELECT = 'select'
|
||||
PARAGRAPH = 'paragraph'
|
||||
|
||||
@classmethod
|
||||
def value_of(cls, value: str) -> 'VariableEntity.Type':
|
||||
"""
|
||||
Get value of given mode.
|
||||
|
||||
:param value: mode value
|
||||
:return: mode
|
||||
"""
|
||||
for mode in cls:
|
||||
if mode.value == value:
|
||||
return mode
|
||||
raise ValueError(f'invalid variable type value {value}')
|
||||
|
||||
variable: str
|
||||
label: str
|
||||
description: Optional[str] = None
|
||||
type: Type
|
||||
required: bool = False
|
||||
max_length: Optional[int] = None
|
||||
options: Optional[list[str]] = None
|
||||
default: Optional[str] = None
|
||||
|
||||
|
||||
class ExternalDataVariableEntity(BaseModel):
|
||||
"""
|
||||
External Data Variable Entity.
|
||||
@ -245,6 +257,7 @@ class AppOrchestrationConfigEntity(BaseModel):
|
||||
"""
|
||||
model_config: ModelConfigEntity
|
||||
prompt_template: PromptTemplateEntity
|
||||
variables: list[VariableEntity] = []
|
||||
external_data_variables: list[ExternalDataVariableEntity] = []
|
||||
agent: Optional[AgentEntity] = None
|
||||
|
||||
@ -256,7 +269,7 @@ class AppOrchestrationConfigEntity(BaseModel):
|
||||
show_retrieve_source: bool = False
|
||||
more_like_this: bool = False
|
||||
speech_to_text: bool = False
|
||||
text_to_speech: dict = {}
|
||||
text_to_speech: Optional[TextToSpeechEntity] = None
|
||||
sensitive_word_avoidance: Optional[SensitiveWordAvoidanceEntity] = None
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ from typing import Optional, cast
|
||||
|
||||
from core.entities.application_entities import (
|
||||
AdvancedCompletionPromptTemplateEntity,
|
||||
AppMode,
|
||||
ModelConfigEntity,
|
||||
PromptTemplateEntity,
|
||||
)
|
||||
@ -24,6 +23,7 @@ from core.model_runtime.entities.model_entities import ModelPropertyKey
|
||||
from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel
|
||||
from core.prompt.prompt_builder import PromptBuilder
|
||||
from core.prompt.prompt_template import PromptTemplateParser
|
||||
from models.model import AppMode
|
||||
|
||||
|
||||
class ModelMode(enum.Enum):
|
||||
|
||||
0
api/core/workflow/__init__.py
Normal file
0
api/core/workflow/__init__.py
Normal file
32
api/core/workflow/entities/NodeEntities.py
Normal file
32
api/core/workflow/entities/NodeEntities.py
Normal file
@ -0,0 +1,32 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class NodeType(Enum):
|
||||
"""
|
||||
Node Types.
|
||||
"""
|
||||
START = 'start'
|
||||
END = 'end'
|
||||
DIRECT_ANSWER = 'direct-answer'
|
||||
LLM = 'llm'
|
||||
KNOWLEDGE_RETRIEVAL = 'knowledge-retrieval'
|
||||
IF_ELSE = 'if-else'
|
||||
CODE = 'code'
|
||||
TEMPLATE_TRANSFORM = 'template-transform'
|
||||
QUESTION_CLASSIFIER = 'question-classifier'
|
||||
HTTP_REQUEST = 'http-request'
|
||||
TOOL = 'tool'
|
||||
VARIABLE_ASSIGNER = 'variable-assigner'
|
||||
|
||||
@classmethod
|
||||
def value_of(cls, value: str) -> 'BlockType':
|
||||
"""
|
||||
Get value of given block type.
|
||||
|
||||
:param value: block type value
|
||||
:return: block type
|
||||
"""
|
||||
for block_type in cls:
|
||||
if block_type.value == value:
|
||||
return block_type
|
||||
raise ValueError(f'invalid block type value {value}')
|
||||
0
api/core/workflow/entities/__init__.py
Normal file
0
api/core/workflow/entities/__init__.py
Normal file
0
api/core/workflow/nodes/__init__.py
Normal file
0
api/core/workflow/nodes/__init__.py
Normal file
0
api/core/workflow/nodes/end/__init__.py
Normal file
0
api/core/workflow/nodes/end/__init__.py
Normal file
0
api/core/workflow/nodes/end/end_node.py
Normal file
0
api/core/workflow/nodes/end/end_node.py
Normal file
25
api/core/workflow/nodes/end/entities.py
Normal file
25
api/core/workflow/nodes/end/entities.py
Normal file
@ -0,0 +1,25 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class EndNodeOutputType(Enum):
|
||||
"""
|
||||
END Node Output Types.
|
||||
|
||||
none, plain-text, structured
|
||||
"""
|
||||
NONE = 'none'
|
||||
PLAIN_TEXT = 'plain-text'
|
||||
STRUCTURED = 'structured'
|
||||
|
||||
@classmethod
|
||||
def value_of(cls, value: str) -> 'OutputType':
|
||||
"""
|
||||
Get value of given output type.
|
||||
|
||||
:param value: output type value
|
||||
:return: output type
|
||||
"""
|
||||
for output_type in cls:
|
||||
if output_type.value == value:
|
||||
return output_type
|
||||
raise ValueError(f'invalid output type value {value}')
|
||||
0
api/core/workflow/workflow_engine_manager.py
Normal file
0
api/core/workflow/workflow_engine_manager.py
Normal file
Reference in New Issue
Block a user