|
|
|
@ -26,10 +26,13 @@ from core.model_runtime.errors.invoke import InvokeAuthorizationError
|
|
|
|
from core.ops.ops_trace_manager import TraceQueueManager
|
|
|
|
from core.ops.ops_trace_manager import TraceQueueManager
|
|
|
|
from core.prompt.utils.get_thread_messages_length import get_thread_messages_length
|
|
|
|
from core.prompt.utils.get_thread_messages_length import get_thread_messages_length
|
|
|
|
from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository
|
|
|
|
from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository
|
|
|
|
|
|
|
|
from core.repositories.sqlalchemy_workflow_execution_repository import SQLAlchemyWorkflowExecutionRepository
|
|
|
|
|
|
|
|
from core.workflow.repository.workflow_execution_repository import WorkflowExecutionRepository
|
|
|
|
from core.workflow.repository.workflow_node_execution_repository import WorkflowNodeExecutionRepository
|
|
|
|
from core.workflow.repository.workflow_node_execution_repository import WorkflowNodeExecutionRepository
|
|
|
|
from extensions.ext_database import db
|
|
|
|
from extensions.ext_database import db
|
|
|
|
from factories import file_factory
|
|
|
|
from factories import file_factory
|
|
|
|
from models import Account, App, Conversation, EndUser, Message, Workflow, WorkflowNodeExecutionTriggeredFrom
|
|
|
|
from models import Account, App, Conversation, EndUser, Message, Workflow, WorkflowNodeExecutionTriggeredFrom
|
|
|
|
|
|
|
|
from models.enums import WorkflowRunTriggeredFrom
|
|
|
|
from services.conversation_service import ConversationService
|
|
|
|
from services.conversation_service import ConversationService
|
|
|
|
from services.errors.message import MessageNotExistsError
|
|
|
|
from services.errors.message import MessageNotExistsError
|
|
|
|
|
|
|
|
|
|
|
|
@ -159,8 +162,22 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
# Create repositories
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create session factory
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
|
|
|
|
# Create workflow execution(aka workflow run) repository
|
|
|
|
|
|
|
|
if invoke_from == InvokeFrom.DEBUGGER:
|
|
|
|
|
|
|
|
workflow_triggered_from = WorkflowRunTriggeredFrom.DEBUGGING
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
workflow_triggered_from = WorkflowRunTriggeredFrom.APP_RUN
|
|
|
|
|
|
|
|
workflow_execution_repository = SQLAlchemyWorkflowExecutionRepository(
|
|
|
|
|
|
|
|
session_factory=session_factory,
|
|
|
|
|
|
|
|
user=user,
|
|
|
|
|
|
|
|
app_id=application_generate_entity.app_config.app_id,
|
|
|
|
|
|
|
|
triggered_from=workflow_triggered_from,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
session_factory=session_factory,
|
|
|
|
session_factory=session_factory,
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
@ -173,6 +190,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
invoke_from=invoke_from,
|
|
|
|
invoke_from=invoke_from,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
|
|
|
|
workflow_execution_repository=workflow_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
conversation=conversation,
|
|
|
|
conversation=conversation,
|
|
|
|
stream=streaming,
|
|
|
|
stream=streaming,
|
|
|
|
@ -226,8 +244,18 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
# Create repositories
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create session factory
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
|
|
|
|
# Create workflow execution(aka workflow run) repository
|
|
|
|
|
|
|
|
workflow_execution_repository = SQLAlchemyWorkflowExecutionRepository(
|
|
|
|
|
|
|
|
session_factory=session_factory,
|
|
|
|
|
|
|
|
user=user,
|
|
|
|
|
|
|
|
app_id=application_generate_entity.app_config.app_id,
|
|
|
|
|
|
|
|
triggered_from=WorkflowRunTriggeredFrom.DEBUGGING,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
session_factory=session_factory,
|
|
|
|
session_factory=session_factory,
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
@ -240,6 +268,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
invoke_from=InvokeFrom.DEBUGGER,
|
|
|
|
invoke_from=InvokeFrom.DEBUGGER,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
|
|
|
|
workflow_execution_repository=workflow_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
conversation=None,
|
|
|
|
conversation=None,
|
|
|
|
stream=streaming,
|
|
|
|
stream=streaming,
|
|
|
|
@ -291,8 +320,18 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers.set({})
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
contexts.plugin_tool_providers_lock.set(threading.Lock())
|
|
|
|
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
# Create repositories
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create session factory
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
session_factory = sessionmaker(bind=db.engine, expire_on_commit=False)
|
|
|
|
|
|
|
|
# Create workflow execution(aka workflow run) repository
|
|
|
|
|
|
|
|
workflow_execution_repository = SQLAlchemyWorkflowExecutionRepository(
|
|
|
|
|
|
|
|
session_factory=session_factory,
|
|
|
|
|
|
|
|
user=user,
|
|
|
|
|
|
|
|
app_id=application_generate_entity.app_config.app_id,
|
|
|
|
|
|
|
|
triggered_from=WorkflowRunTriggeredFrom.DEBUGGING,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create workflow node execution repository
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
|
|
|
|
session_factory=session_factory,
|
|
|
|
session_factory=session_factory,
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
@ -305,6 +344,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
invoke_from=InvokeFrom.DEBUGGER,
|
|
|
|
invoke_from=InvokeFrom.DEBUGGER,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
application_generate_entity=application_generate_entity,
|
|
|
|
|
|
|
|
workflow_execution_repository=workflow_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
conversation=None,
|
|
|
|
conversation=None,
|
|
|
|
stream=streaming,
|
|
|
|
stream=streaming,
|
|
|
|
@ -317,6 +357,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
user: Union[Account, EndUser],
|
|
|
|
user: Union[Account, EndUser],
|
|
|
|
invoke_from: InvokeFrom,
|
|
|
|
invoke_from: InvokeFrom,
|
|
|
|
application_generate_entity: AdvancedChatAppGenerateEntity,
|
|
|
|
application_generate_entity: AdvancedChatAppGenerateEntity,
|
|
|
|
|
|
|
|
workflow_execution_repository: WorkflowExecutionRepository,
|
|
|
|
workflow_node_execution_repository: WorkflowNodeExecutionRepository,
|
|
|
|
workflow_node_execution_repository: WorkflowNodeExecutionRepository,
|
|
|
|
conversation: Optional[Conversation] = None,
|
|
|
|
conversation: Optional[Conversation] = None,
|
|
|
|
stream: bool = True,
|
|
|
|
stream: bool = True,
|
|
|
|
@ -381,6 +422,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
conversation=conversation,
|
|
|
|
conversation=conversation,
|
|
|
|
message=message,
|
|
|
|
message=message,
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
|
|
|
|
workflow_execution_repository=workflow_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
stream=stream,
|
|
|
|
stream=stream,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -453,6 +495,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
conversation: Conversation,
|
|
|
|
conversation: Conversation,
|
|
|
|
message: Message,
|
|
|
|
message: Message,
|
|
|
|
user: Union[Account, EndUser],
|
|
|
|
user: Union[Account, EndUser],
|
|
|
|
|
|
|
|
workflow_execution_repository: WorkflowExecutionRepository,
|
|
|
|
workflow_node_execution_repository: WorkflowNodeExecutionRepository,
|
|
|
|
workflow_node_execution_repository: WorkflowNodeExecutionRepository,
|
|
|
|
stream: bool = False,
|
|
|
|
stream: bool = False,
|
|
|
|
) -> Union[ChatbotAppBlockingResponse, Generator[ChatbotAppStreamResponse, None, None]]:
|
|
|
|
) -> Union[ChatbotAppBlockingResponse, Generator[ChatbotAppStreamResponse, None, None]]:
|
|
|
|
@ -476,9 +519,10 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|
|
|
conversation=conversation,
|
|
|
|
conversation=conversation,
|
|
|
|
message=message,
|
|
|
|
message=message,
|
|
|
|
user=user,
|
|
|
|
user=user,
|
|
|
|
stream=stream,
|
|
|
|
|
|
|
|
dialogue_count=self._dialogue_count,
|
|
|
|
dialogue_count=self._dialogue_count,
|
|
|
|
|
|
|
|
workflow_execution_repository=workflow_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
workflow_node_execution_repository=workflow_node_execution_repository,
|
|
|
|
|
|
|
|
stream=stream,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|