From 47e5d49c8f5c33117e1750cfdc012fe8e9daecba Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 6 Nov 2023 22:58:32 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(LLMChain.py):=20remove?= =?UTF-8?q?=20unused=20import=20statement=20for=20Text=20from=20langflow.f?= =?UTF-8?q?ield=5Ftyping=20=F0=9F=94=A8=20refactor(utils.py):=20rename=20v?= =?UTF-8?q?ariable=20'return=5Ftype'=20to=20'return=5Ftypes'=20for=20clari?= =?UTF-8?q?ty=20=F0=9F=94=A8=20refactor(types.py):=20add=20Optional=20and?= =?UTF-8?q?=20Union=20imports,=20add=20type=20hints=20for=20user=5Fid=20pa?= =?UTF-8?q?rameter=20in=20build=5Ffield=5Fconfig=20and=20build=5Flangchain?= =?UTF-8?q?=5Ftemplate=5Fcustom=5Fcomponent=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/components/chains/LLMChain.py | 3 +-- src/backend/langflow/interface/custom/utils.py | 6 +++--- src/backend/langflow/interface/types.py | 9 ++++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/components/chains/LLMChain.py b/src/backend/langflow/components/chains/LLMChain.py index e7cd68acb..b14eef302 100644 --- a/src/backend/langflow/components/chains/LLMChain.py +++ b/src/backend/langflow/components/chains/LLMChain.py @@ -6,7 +6,6 @@ from langflow.field_typing import ( BaseLanguageModel, BaseMemory, Chain, - Text, ) @@ -27,5 +26,5 @@ class LLMChainComponent(CustomComponent): prompt: BasePromptTemplate, llm: BaseLanguageModel, memory: Optional[BaseMemory] = None, - ) -> Union[Chain, Callable, Text]: + ) -> Union[Chain, Callable]: return LLMChain(prompt=prompt, llm=llm, memory=memory) diff --git a/src/backend/langflow/interface/custom/utils.py b/src/backend/langflow/interface/custom/utils.py index 9560b0f01..700b98b53 100644 --- a/src/backend/langflow/interface/custom/utils.py +++ b/src/backend/langflow/interface/custom/utils.py @@ -16,6 +16,6 @@ def extract_union_types(return_type: str) -> list[str]: """ # If the return type is a Union, then we need to parse it return_type = return_type.replace("Union", "").replace("[", "").replace("]", "") - return_type = return_type.split(",") - return_type = [item.strip() for item in return_type] - return return_type + return_types = return_type.split(",") + return_types = [item.strip() for item in return_types] + return return_types diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index ec603818a..e48255de9 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -1,6 +1,7 @@ import ast import contextlib -from typing import Any, List +from typing import Any, List, Union, Optional +from uuid import UUID from langflow.api.utils import get_new_key from langflow.interface.agents.base import agent_creator from langflow.interface.chains.base import chain_creator @@ -208,7 +209,9 @@ def update_attributes(frontend_node, template_config): frontend_node[attribute] = template_config[attribute] -def build_field_config(custom_component: CustomComponent, user_id: str = None): +def build_field_config( + custom_component: CustomComponent, user_id: Optional[Union[str, UUID]] = None +): """Build the field configuration for a custom component""" try: @@ -307,7 +310,7 @@ def add_output_types(frontend_node, return_types: List[str]): def build_langchain_template_custom_component( - custom_component: CustomComponent, user_id: str = None + custom_component: CustomComponent, user_id: Optional[Union[str, UUID]] = None ): """Build a custom component template for the langchain""" try: