From 250d3a1064bbc760d7a476d55905315ee7929e91 Mon Sep 17 00:00:00 2001 From: Ibis Prevedello Date: Fri, 24 Mar 2023 13:38:51 -0300 Subject: [PATCH] refac: fix bug reading docstring --- src/backend/langflow/interface/listing.py | 20 +++----------------- src/backend/langflow/utils/util.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/backend/langflow/interface/listing.py b/src/backend/langflow/interface/listing.py index d8e4b087dc53..21e763de42fd 100644 --- a/src/backend/langflow/interface/listing.py +++ b/src/backend/langflow/interface/listing.py @@ -24,12 +24,10 @@ def list_type(object_type: str): def list_agents(): """List all agent types""" - AGENT_BUG = ["ChatAgent"] return [ agent.__name__ for agent in agents.loading.AGENT_TO_CLASS.values() - if (agent.__name__ in settings.agents or settings.dev) - and agent.__name__ not in AGENT_BUG + if agent.__name__ in settings.agents or settings.dev ] @@ -46,17 +44,12 @@ def list_prompts(): def list_tools(): """List all load tools""" - TOOL_BUG = [] tools = [] for tool in get_all_tool_names(): tool_params = util.get_tool_params(util.get_tools_dict(tool)) - if ( - tool_params - and (tool_params["name"] in settings.tools or settings.dev) - and tool_params["name"] not in TOOL_BUG - ): + if tool_params and tool_params["name"] in settings.tools or settings.dev: tools.append(tool_params["name"]) return tools @@ -82,15 +75,8 @@ def list_chain_types(): def list_memories(): """List all memory types""" - MEMORY_BUG = [ - "ChatMessageHistory", - "ConversationSummaryBufferMemory", - "ConversationKGMemory", - "ConversationSummaryMemory", - ] return [ memory.__name__ for memory in memory_type_to_cls_dict.values() - if (memory.__name__ in settings.memories or settings.dev) - and memory.__name__ not in MEMORY_BUG + if memory.__name__ in settings.memories or settings.dev ] diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 45f992e0498c..4710114ed50e 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -71,6 +71,7 @@ def build_template_from_class(name: str, type_to_cls_dict: Dict): if v.__name__ == name: _class = v + # Get the docstring docs = get_class_doc(_class) variables = {"_type": _type} @@ -192,11 +193,7 @@ def get_class_doc(class_name): A dictionary containing the extracted information, with keys for 'Description', 'Parameters', 'Attributes', and 'Returns'. """ - # Get the class docstring - docstring = class_name.__doc__ - - # Parse the docstring to extract information - lines = docstring.split("\n") + # Template data = { "Description": "", "Parameters": {}, @@ -205,6 +202,15 @@ def get_class_doc(class_name): "Returns": {}, } + # Get the class docstring + docstring = class_name.__doc__ + + if not docstring: + return data + + # Parse the docstring to extract information + lines = docstring.split("\n") + current_section = "Description" for line in lines: