From f10ad3489347b914ce99e11a0e2e37d8c26a0d77 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Sun, 29 Sep 2024 12:36:38 +0800 Subject: [PATCH] refactor(generator): simplify file extraction logic - Standardize file extraction using `args.get("files") or []` pattern - Improve readability and consistency across app generators --- api/core/app/apps/agent_chat/app_generator.py | 9 +++++++-- api/core/app/apps/workflow/app_generator.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/core/app/apps/agent_chat/app_generator.py b/api/core/app/apps/agent_chat/app_generator.py index 034857266b8ad7..c452c3cb46f407 100644 --- a/api/core/app/apps/agent_chat/app_generator.py +++ b/api/core/app/apps/agent_chat/app_generator.py @@ -49,7 +49,12 @@ def generate( ) -> dict: ... def generate( - self, app_model: App, user: Union[Account, EndUser], args: Any, invoke_from: InvokeFrom, stream: bool = True + self, + app_model: App, + user: Union[Account, EndUser], + args: Any, + invoke_from: InvokeFrom, + stream: bool = True, ) -> Union[dict, Generator[dict, None, None]]: """ Generate App response. @@ -100,7 +105,7 @@ def generate( role = CreatedByRole.ACCOUNT if isinstance(user, Account) else CreatedByRole.END_USER # parse files - files = args["files"] if args.get("files") else [] + files = args.get("files") or [] file_extra_config = FileUploadConfigManager.convert(override_model_config_dict or app_model_config.to_dict()) if file_extra_config: file_objs = file_factory.build_from_mappings( diff --git a/api/core/app/apps/workflow/app_generator.py b/api/core/app/apps/workflow/app_generator.py index 68bd23af9fac97..47fc2c96eeca4f 100644 --- a/api/core/app/apps/workflow/app_generator.py +++ b/api/core/app/apps/workflow/app_generator.py @@ -68,7 +68,7 @@ def generate( call_depth: int = 0, workflow_thread_pool_id: Optional[str] = None, ): - files: Sequence[Mapping[str, Any]] = args.get("files", []) + files: Sequence[Mapping[str, Any]] = args.get("files") or [] role = CreatedByRole.ACCOUNT if isinstance(user, Account) else CreatedByRole.END_USER