|
@@ -4,8 +4,6 @@ from collections.abc import Generator
|
|
|
from datetime import UTC, datetime
|
|
|
from typing import Optional, Union, cast
|
|
|
|
|
|
-from sqlalchemy import and_
|
|
|
-
|
|
|
from core.app.app_config.entities import EasyUIBasedAppConfig, EasyUIBasedAppModelConfigFrom
|
|
|
from core.app.apps.base_app_generator import BaseAppGenerator
|
|
|
from core.app.apps.base_app_queue_manager import AppQueueManager, GenerateTaskStoppedError
|
|
@@ -30,7 +28,7 @@ from models import Account
|
|
|
from models.enums import CreatedByRole
|
|
|
from models.model import App, AppMode, AppModelConfig, Conversation, EndUser, Message, MessageFile
|
|
|
from services.errors.app_model_config import AppModelConfigBrokenError
|
|
|
-from services.errors.conversation import ConversationCompletedError, ConversationNotExistsError
|
|
|
+from services.errors.conversation import ConversationNotExistsError
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
@@ -81,31 +79,6 @@ class MessageBasedAppGenerator(BaseAppGenerator):
|
|
|
logger.exception(f"Failed to handle response, conversation_id: {conversation.id}")
|
|
|
raise e
|
|
|
|
|
|
- def _get_conversation_by_user(
|
|
|
- self, app_model: App, conversation_id: str, user: Union[Account, EndUser]
|
|
|
- ) -> Conversation:
|
|
|
- conversation_filter = [
|
|
|
- Conversation.id == conversation_id,
|
|
|
- Conversation.app_id == app_model.id,
|
|
|
- Conversation.status == "normal",
|
|
|
- Conversation.is_deleted.is_(False),
|
|
|
- ]
|
|
|
-
|
|
|
- if isinstance(user, Account):
|
|
|
- conversation_filter.append(Conversation.from_account_id == user.id)
|
|
|
- else:
|
|
|
- conversation_filter.append(Conversation.from_end_user_id == user.id if user else None)
|
|
|
-
|
|
|
- conversation = db.session.query(Conversation).filter(and_(*conversation_filter)).first()
|
|
|
-
|
|
|
- if not conversation:
|
|
|
- raise ConversationNotExistsError()
|
|
|
-
|
|
|
- if conversation.status != "normal":
|
|
|
- raise ConversationCompletedError()
|
|
|
-
|
|
|
- return conversation
|
|
|
-
|
|
|
def _get_app_model_config(self, app_model: App, conversation: Optional[Conversation] = None) -> AppModelConfig:
|
|
|
if conversation:
|
|
|
app_model_config = (
|