Skip to content

Commit

Permalink
refactor(generator): simplify file extraction logic
Browse files Browse the repository at this point in the history
- Standardize file extraction using `args.get("files") or []` pattern
- Improve readability and consistency across app generators
  • Loading branch information
laipz8200 committed Sep 29, 2024
1 parent e269550 commit f10ad34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions api/core/app/apps/agent_chat/app_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion api/core/app/apps/workflow/app_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f10ad34

Please sign in to comment.