🔨 refactor(LLMChain.py): remove unused import statement for Text from langflow.field_typing

🔨 refactor(utils.py): rename variable 'return_type' to 'return_types' for clarity
🔨 refactor(types.py): add Optional and Union imports, add type hints for user_id parameter in build_field_config and build_langchain_template_custom_component functions
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-06 22:58:32 -03:00
commit 47e5d49c8f
3 changed files with 10 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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: