From c1fd55bb049ef12108bee711c747d5381e17c05c Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 28 Jul 2024 13:00:58 +0100 Subject: [PATCH] fix/refac: actions --- backend/main.py | 67 +++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/backend/main.py b/backend/main.py index 27b962b93..d1d96b001 100644 --- a/backend/main.py +++ b/backend/main.py @@ -991,32 +991,15 @@ async def get_all_models(): model["name"] = custom_model.name model["info"] = custom_model.model_dump() - action_ids = [] + global_action_ids + action_ids = [] if "info" in model and "meta" in model["info"]: action_ids.extend(model["info"]["meta"].get("actionIds", [])) - action_ids = list(set(action_ids)) - action_ids = [ - action_id - for action_id in action_ids - if action_id in enabled_action_ids - ] - - model["actions"] = [] - for action_id in action_ids: - action = Functions.get_function_by_id(action_id) - model["actions"].append( - { - "id": action_id, - "name": action.name, - "description": action.meta.description, - "icon_url": action.meta.manifest.get("icon_url", None), - } - ) + model["action_ids"] = action_ids else: owned_by = "openai" pipe = None - actions = [] + action_ids = [] for model in models: if ( @@ -1027,26 +1010,8 @@ async def get_all_models(): if "pipe" in model: pipe = model["pipe"] - action_ids = [] + global_action_ids if "info" in model and "meta" in model["info"]: action_ids.extend(model["info"]["meta"].get("actionIds", [])) - action_ids = list(set(action_ids)) - action_ids = [ - action_id - for action_id in action_ids - if action_id in enabled_action_ids - ] - - actions = [ - { - "id": action_id, - "name": Functions.get_function_by_id(action_id).name, - "description": Functions.get_function_by_id( - action_id - ).meta.description, - } - for action_id in action_ids - ] break models.append( @@ -1059,7 +1024,31 @@ async def get_all_models(): "info": custom_model.model_dump(), "preset": True, **({"pipe": pipe} if pipe is not None else {}), - "actions": actions, + "action_ids": action_ids, + } + ) + + for model in models: + action_ids = [] + if "action_ids" in model: + action_ids = model["action_ids"] + del model["action_ids"] + + action_ids = action_ids + global_action_ids + action_ids = list(set(action_ids)) + action_ids = [ + action_id for action_id in action_ids if action_id in enabled_action_ids + ] + + model["actions"] = [] + for action_id in action_ids: + action = Functions.get_function_by_id(action_id) + model["actions"].append( + { + "id": action_id, + "name": action.name, + "description": action.meta.description, + "icon_url": action.meta.manifest.get("icon_url", None), } )