From 4aa242f9b1b6f437e29b7ba2189aa5ac829ec735 Mon Sep 17 00:00:00 2001 From: Ibis Prevedello Date: Tue, 7 Mar 2023 23:36:58 -0300 Subject: [PATCH] refac: remove comments --- .../backend/langflow_backend/api/endpoints.py | 21 ------------ .../langflow_backend/api/list_endpoints.py | 34 ------------------- .../backend/langflow_backend/api/signature.py | 24 ------------- .../langflow_backend/custom/customs.py | 2 ++ .../backend/langflow_backend/utils/payload.py | 21 +++--------- 5 files changed, 6 insertions(+), 96 deletions(-) diff --git a/langflow/backend/langflow_backend/api/endpoints.py b/langflow/backend/langflow_backend/api/endpoints.py index 807298a9e..1ca745b20 100644 --- a/langflow/backend/langflow_backend/api/endpoints.py +++ b/langflow/backend/langflow_backend/api/endpoints.py @@ -42,27 +42,6 @@ def get_all(): for prompt in list_endpoints.list_prompts() }, "llms": {llm: signature.get_llm(llm) for llm in list_endpoints.list_llms()}, - # "utilities": { - # "template": { - # # utility: templates.utility(utility) for utility in list.list_utilities() - # } - # }, - # "memories": { - # memory: signature.get_memory(memory) - # for memory in list_endpoints.list_memories() - # }, - # "document_loaders": { - # "template": { - # # memory: templates.document_loader(memory) - # # for memory in list.list_document_loaders() - # } - # }, - # "vectorstores": {"template": {}}, - # "docstores": {"template": {}}, - # "tools": { - # tool: {"template": signature.tool(tool), **values} - # for tool, values in tools.items() - # }, "tools": { tool: signature.get_tool(tool) for tool in list_endpoints.list_tools() }, diff --git a/langflow/backend/langflow_backend/api/list_endpoints.py b/langflow/backend/langflow_backend/api/list_endpoints.py index f01c5b35f..0f637345b 100644 --- a/langflow/backend/langflow_backend/api/list_endpoints.py +++ b/langflow/backend/langflow_backend/api/list_endpoints.py @@ -25,11 +25,6 @@ def read_items(): "agents", "prompts", "llms", - # "utilities", - # "memories", - # "document_loaders", - # "vectorstores", - # "docstores", "tools", ] @@ -83,30 +78,6 @@ def list_memories(): return [memory.__name__ for memory in memories.type_to_cls_dict.values()] -# @router.get("/utilities") -# def list_utilities(): -# """List all utility types""" -# return list(utilities.__all__) - - -# @router.get("/document_loaders") -# def list_document_loaders(): -# """List all document loader types""" -# return list(document_loaders.__all__) - - -# @router.get("/vectorstores") -# def list_vectorstores(): -# """List all vector store types""" -# return list(vectorstores.__all__) - - -# @router.get("/docstores") -# def list_docstores(): -# """List all document store types""" -# return list(docstore.__all__) - - @router.get("/tools") def list_tools(): """List all load tools""" @@ -119,8 +90,3 @@ def list_tools(): tools.append(tool_params["name"]) return tools - - # return [ - # util.get_tool_params(util.get_tools_dict(tool))["name"] - # for tool in get_all_tool_names() - # ] diff --git a/langflow/backend/langflow_backend/api/signature.py b/langflow/backend/langflow_backend/api/signature.py index 68c133cf7..7aa0d3b83 100644 --- a/langflow/backend/langflow_backend/api/signature.py +++ b/langflow/backend/langflow_backend/api/signature.py @@ -62,18 +62,6 @@ def get_llm(name: str): raise HTTPException(status_code=404, detail="LLM not found") from exc -# @router.get("/utility") -# def utility(name: str): -# # Raise error if name is not in utilities -# if name not in utilities.__all__: -# raise Exception(f"Prompt {name} not found.") -# _class = getattr(utilities, name) -# return { -# name: {name: value for (name, value) in value.__repr_args__() if name != "name"} -# for name, value in _class.__fields__.items() -# } - - @router.get("/memory") def get_memory(name: str): """Get the signature of a memory.""" @@ -83,18 +71,6 @@ def get_memory(name: str): raise HTTPException(status_code=404, detail="Memory not found") from exc -# @router.get("/document_loader") -# def document_loader(name: str): -# # Raise error if name is not in document_loader -# if name not in document_loaders.__all__: -# raise Exception(f"Prompt {name} not found.") -# _class = getattr(document_loaders, name) -# return { -# name: {name: value for (name, value) in value.__repr_args__() if name != "name"} -# for name, value in _class.__fields__.items() -# } - - @router.get("/tool") def get_tool(name: str): """Get the signature of a tool.""" diff --git a/langflow/backend/langflow_backend/custom/customs.py b/langflow/backend/langflow_backend/custom/customs.py index 0cf129b52..bd5c9aa59 100644 --- a/langflow/backend/langflow_backend/custom/customs.py +++ b/langflow/backend/langflow_backend/custom/customs.py @@ -2,6 +2,8 @@ from langchain.agents.mrkl import prompt def get_custom_prompts(): + """Get custom prompts.""" + return { "ZeroShotPrompt": { "template": { diff --git a/langflow/backend/langflow_backend/utils/payload.py b/langflow/backend/langflow_backend/utils/payload.py index 75ffbdd7d..e4aa5cc93 100644 --- a/langflow/backend/langflow_backend/utils/payload.py +++ b/langflow/backend/langflow_backend/utils/payload.py @@ -52,21 +52,15 @@ def build_json(root, nodes, edges): for key, value in final_dict.items(): if key == "_type": continue - # elif key == "prompt": - # pass module_type = value["type"] - # if module_type == "Tool": - # pass - # if module_type in ["str", "bool", "int", "float", "Any"] or value["value"]: - # value = value["value"] + if "value" in value and value["value"] is not None: value = value["value"] elif "dict" in module_type: value = {} else: - # if value['list']: - # print(key) + children = [] for c in local_nodes: module_types = [c["data"]["type"]] @@ -74,19 +68,12 @@ def build_json(root, nodes, edges): module_types += c["data"]["node"]["base_classes"] if module_type in module_types: children.append(c) - # children = [ - # c - # for c in local_nodes - # if module_type - # in [c["data"]["type"]] + c["data"]["node"]["base_classes"] - # ] - # else: - # children = next((c for c in local_nodes if type in [c['data']['type']] + c['data']['node']['base_classes']), None) + if value["required"] and not children: raise ValueError(f"No child with type {module_type} found") values = [ build_json(child, nodes, edges) for child in children - ] # if children else None + ] value = list(values) if value["list"] else next(iter(values), None) final_dict[key] = value return final_dict