From 957da16d6ef5f4b2eb0de1711910c3b013cc1047 Mon Sep 17 00:00:00 2001 From: merrygoround-of-life Date: Wed, 11 Oct 2023 12:59:27 +0900 Subject: [PATCH 01/14] Fix: missing numexpr when using poetry to run --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 192528702..0bbd31714 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,7 @@ langfuse = "^1.0.13" pillow = "^10.0.0" metal-sdk = "^2.2.0" markupsafe = "^2.1.3" +numexpr = "^2.8.6" [tool.poetry.group.dev.dependencies] From 7c9f649f01f3fff41c6bd0b5d13107445e212087 Mon Sep 17 00:00:00 2001 From: Guangya Liu Date: Wed, 11 Oct 2023 14:21:41 -0400 Subject: [PATCH 02/14] added trace name --- src/backend/langflow/processing/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/processing/base.py b/src/backend/langflow/processing/base.py index e5816306c..20e2a9d83 100644 --- a/src/backend/langflow/processing/base.py +++ b/src/backend/langflow/processing/base.py @@ -34,7 +34,7 @@ def get_langfuse_callback(trace_id): if langfuse := LangfuseInstance.get(): logger.debug("Langfuse credentials found") try: - trace = langfuse.trace(CreateTrace(id=trace_id)) + trace = langfuse.trace(CreateTrace(name="langflow-"+trace_id, id=trace_id)) return trace.getNewHandler() except Exception as exc: logger.error(f"Error initializing langfuse callback: {exc}") From b2205bba8aa64b61dd150849ddc9782d231bd50f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 11 Oct 2023 17:33:32 -0300 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20add=20out?= =?UTF-8?q?put=20types=20to=20the=20frontend=20node=20to=20improve=20data?= =?UTF-8?q?=20integrity=20and=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ feat(types.py): add support for adding output types to the frontend node to ensure valid return types and improve error handling --- src/backend/langflow/interface/types.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index 6708c11c9..5f29dbf2e 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -288,6 +288,24 @@ def add_base_classes(frontend_node, return_types: List[str]): frontend_node.get("base_classes").append(base_class) +def add_output_types(frontend_node, return_types: List[str]): + """Add output types to the frontend node""" + for return_type in return_types: + if return_type not in CUSTOM_COMPONENT_SUPPORTED_TYPES or return_type is None: + raise HTTPException( + status_code=400, + detail={ + "error": ( + "Invalid return type should be one of: " + f"{list(CUSTOM_COMPONENT_SUPPORTED_TYPES.keys())}" + ), + "traceback": traceback.format_exc(), + }, + ) + + frontend_node.get("output_types").append(return_type) + + def build_langchain_template_custom_component(custom_component: CustomComponent): """Build a custom component template for the langchain""" try: @@ -314,6 +332,9 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) add_base_classes( frontend_node, custom_component.get_function_entrypoint_return_type ) + add_output_types( + frontend_node, custom_component.get_function_entrypoint_return_type + ) logger.debug("Added base classes") return frontend_node except Exception as exc: From df66ae848e8a9c625090811f73d85d2e60b47e59 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 11 Oct 2023 18:31:05 -0300 Subject: [PATCH 04/14] =?UTF-8?q?=F0=9F=94=80=20chore(field=5Ftyping):=20a?= =?UTF-8?q?dd=20support=20for=20additional=20types=20in=20field=5Ftyping/?= =?UTF-8?q?=5F=5Finit=5F=5F.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔀 chore(field_typing): add support for Data type in field_typing/base.py 🔀 chore(field_typing): add constants.py file to define supported types in field_typing 🔀 chore(interface/custom): remove duplicate imports and use field_typing types 🔀 chore(utils): fix syntax error in get_base_classes function --- src/backend/langflow/field_typing/__init__.py | 9 ++- src/backend/langflow/field_typing/base.py | 3 +- .../langflow/field_typing/constants.py | 43 +++++++++++++ .../langflow/interface/custom/constants.py | 62 ++----------------- src/backend/langflow/utils/util.py | 4 +- 5 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 src/backend/langflow/field_typing/constants.py diff --git a/src/backend/langflow/field_typing/__init__.py b/src/backend/langflow/field_typing/__init__.py index 927716b11..14cbba2d0 100644 --- a/src/backend/langflow/field_typing/__init__.py +++ b/src/backend/langflow/field_typing/__init__.py @@ -1,3 +1,8 @@ -from .base import NestedDict +from .base import NestedDict, Data +from .constants import * -__all__ = ["NestedDict"] +__all__ = ( + ["NestedDict", "Data"] + + list(LANGCHAIN_BASE_TYPES.keys()) + + list(CUSTOM_COMPONENT_SUPPORTED_TYPES.keys()) +) diff --git a/src/backend/langflow/field_typing/base.py b/src/backend/langflow/field_typing/base.py index ed3219888..48b737a63 100644 --- a/src/backend/langflow/field_typing/base.py +++ b/src/backend/langflow/field_typing/base.py @@ -1,4 +1,5 @@ -from typing import Union, Dict +from typing import Union, Dict, Any # Type alias for more complex dicts NestedDict = Dict[str, Union[str, Dict]] +Data = Any diff --git a/src/backend/langflow/field_typing/constants.py b/src/backend/langflow/field_typing/constants.py new file mode 100644 index 000000000..4a8072b15 --- /dev/null +++ b/src/backend/langflow/field_typing/constants.py @@ -0,0 +1,43 @@ +from langchain.agents.agent import AgentExecutor +from langchain.chains.base import Chain +from langchain.document_loaders.base import BaseLoader +from langchain.llms.base import BaseLLM +from langchain.memory.chat_memory import BaseChatMemory +from langchain.prompts import PromptTemplate +from langchain.schema import BaseOutputParser, BaseRetriever, Document +from langchain.schema.embeddings import Embeddings +from langchain.schema.memory import BaseMemory +from langchain.text_splitter import TextSplitter +from langchain.tools import Tool +from langchain.vectorstores.base import VectorStore +from langflow.field_typing import Data, NestedDict + + +LANGCHAIN_BASE_TYPES = { + "Chain": Chain, + "AgentExecutor": AgentExecutor, + "Tool": Tool, + "BaseLLM": BaseLLM, + "PromptTemplate": PromptTemplate, + "BaseLoader": BaseLoader, + "Document": Document, + "TextSplitter": TextSplitter, + "VectorStore": VectorStore, + "Embeddings": Embeddings, + "BaseRetriever": BaseRetriever, + "BaseOutputParser": BaseOutputParser, + "BaseMemory": BaseMemory, + "BaseChatMemory": BaseChatMemory, +} +# Langchain base types plus Python base types +CUSTOM_COMPONENT_SUPPORTED_TYPES = { + **LANGCHAIN_BASE_TYPES, + "str": str, + "int": int, + "float": float, + "bool": bool, + "list": list, + "dict": dict, + "NestedDict": NestedDict, + "Data": Data, +} diff --git a/src/backend/langflow/interface/custom/constants.py b/src/backend/langflow/interface/custom/constants.py index 58ecef637..a3eb64336 100644 --- a/src/backend/langflow/interface/custom/constants.py +++ b/src/backend/langflow/interface/custom/constants.py @@ -1,65 +1,15 @@ -from langchain.prompts import PromptTemplate -from langchain.chains.base import Chain -from langchain.document_loaders.base import BaseLoader -from langchain.schema.embeddings import Embeddings -from langchain.llms.base import BaseLLM -from langchain.schema import BaseRetriever, Document -from langchain.text_splitter import TextSplitter -from langchain.tools import Tool -from langchain.vectorstores.base import VectorStore -from langchain.schema import BaseOutputParser -from langchain.schema.memory import BaseMemory -from langchain.memory.chat_memory import BaseChatMemory -from langchain.agents.agent import AgentExecutor - -LANGCHAIN_BASE_TYPES = { - "Chain": Chain, - "AgentExecutor": AgentExecutor, - "Tool": Tool, - "BaseLLM": BaseLLM, - "PromptTemplate": PromptTemplate, - "BaseLoader": BaseLoader, - "Document": Document, - "TextSplitter": TextSplitter, - "VectorStore": VectorStore, - "Embeddings": Embeddings, - "BaseRetriever": BaseRetriever, - "BaseOutputParser": BaseOutputParser, - "BaseMemory": BaseMemory, - "BaseChatMemory": BaseChatMemory, -} - -# Langchain base types plus Python base types -CUSTOM_COMPONENT_SUPPORTED_TYPES = { - **LANGCHAIN_BASE_TYPES, - "str": str, - "int": int, - "float": float, - "bool": bool, - "list": list, - "dict": dict, -} - - DEFAULT_CUSTOM_COMPONENT_CODE = """from langflow import CustomComponent -from langchain.llms.base import BaseLLM -from langchain.chains import LLMChain -from langchain.prompts import PromptTemplate -from langchain.schema import Document +from langflow.field_typing import * -import requests - -class YourComponent(CustomComponent): +class Component(CustomComponent): display_name: str = "Custom Component" description: str = "Create any custom component you want!" def build_config(self): - return { "url": { "multiline": True, "required": True } } + return { "param": { "display_name": "Parameter" } } + + def build(self, param: Data) -> Data: + return params - def build(self, url: str, llm: BaseLLM, prompt: PromptTemplate) -> Document: - response = requests.get(url) - chain = LLMChain(llm=llm, prompt=prompt) - result = chain.run(response.text[:300]) - return Document(page_content=str(result)) """ diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index b563c5973..c23c559e4 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -191,7 +191,9 @@ def get_base_classes(cls): """Get the base classes of a class. These are used to determine the output of the nodes. """ - if bases := cls.__bases__: + + if hasattr(cls, "__bases__") and cls.__bases__: + bases = cls.__bases__ result = [] for base in bases: if any(type in base.__module__ for type in ["pydantic", "abc"]): From 440298861c000e323894fafeb58b15a41da3cfaa Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 11 Oct 2023 18:32:19 -0300 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=94=84=20refactor(types.py):=20upda?= =?UTF-8?q?te=20import=20statement=20for=20CUSTOM=5FCOMPONENT=5FSUPPORTED?= =?UTF-8?q?=5FTYPES=20to=20match=20new=20location=20in=20field=5Ftyping=20?= =?UTF-8?q?module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index 5f29dbf2e..0046c84fb 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -4,7 +4,7 @@ from typing import Any, List from langflow.api.utils import get_new_key from langflow.interface.agents.base import agent_creator from langflow.interface.chains.base import chain_creator -from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES +from langflow.field_typing.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES from langflow.interface.custom.utils import extract_inner_type from langflow.interface.document_loaders.base import documentloader_creator from langflow.interface.embeddings.base import embedding_creator From 846a15f9fd5b3fc9f157568ff49d31d3be057a84 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 11 Oct 2023 18:32:56 -0300 Subject: [PATCH 06/14] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20convert=20?= =?UTF-8?q?"int"=20and=20"float"=20type=20values=20to=20their=20respective?= =?UTF-8?q?=20types=20for=20better=20data=20consistency=20and=20type=20saf?= =?UTF-8?q?ety?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 8ae0bb5f8..ad6fc952f 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -216,6 +216,10 @@ class Vertex: } elif isinstance(_value, dict): params[key] = _value + elif value.get("type") == "int": + params[key] = int(value.get("value")) + elif value.get("type") == "float": + params[key] = float(value.get("value")) else: params[key] = value.get("value") From 8f20105b4b58b5fd3e36b54508a2db696edeba17 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 11 Oct 2023 18:33:13 -0300 Subject: [PATCH 07/14] =?UTF-8?q?=F0=9F=94=A7=20fix(custom=5Fcomponent.py)?= =?UTF-8?q?:=20fix=20import=20statement=20for=20CUSTOM=5FCOMPONENT=5FSUPPO?= =?UTF-8?q?RTED=5FTYPES=20=F0=9F=94=A7=20fix(custom=5Fcomponent.py):=20fix?= =?UTF-8?q?=20argument=20type=20in=20return=20statement=20of=20CustomCompo?= =?UTF-8?q?nent.get=5Fargs()=20=F0=9F=94=A7=20fix(custom=5Fcomponents.py):?= =?UTF-8?q?=20make=20description=20attribute=20optional=20in=20CustomCompo?= =?UTF-8?q?nentFrontendNode=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/custom/custom_component.py | 3 ++- .../langflow/template/frontend_node/custom_components.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index ccc0b08b2..42b68ed40 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -1,7 +1,7 @@ from typing import Any, Callable, List, Optional, Union from uuid import UUID from fastapi import HTTPException -from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES +from langflow.field_typing.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES from langflow.interface.custom.component import Component from langflow.interface.custom.directory_reader import DirectoryReader from langflow.services.getters import get_db_service @@ -108,6 +108,7 @@ class CustomComponent(Component, extra=Extra.allow): ), }, ) + # TODO arg type should be Data if it is None return args @property diff --git a/src/backend/langflow/template/frontend_node/custom_components.py b/src/backend/langflow/template/frontend_node/custom_components.py index 4f36a1c9f..e239775bc 100644 --- a/src/backend/langflow/template/frontend_node/custom_components.py +++ b/src/backend/langflow/template/frontend_node/custom_components.py @@ -2,6 +2,7 @@ from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode from langflow.template.template.base import Template from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE +from typing import Optional class CustomComponentFrontendNode(FrontendNode): @@ -24,7 +25,7 @@ class CustomComponentFrontendNode(FrontendNode): ) ], ) - description: str = "Create any custom component you want!" + description: Optional[str] = None base_classes: list[str] = [] def to_dict(self): From 6abd5d5343cdb07be072dcd298c341ee769ef132 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 12 Oct 2023 16:29:30 -0300 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20handle=20c?= =?UTF-8?q?ases=20where=20value=20is=20not=20a=20valid=20int=20or=20float?= =?UTF-8?q?=20to=20prevent=20ValueError=20and=20assign=20the=20original=20?= =?UTF-8?q?value=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index ad6fc952f..de64b3598 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -216,10 +216,16 @@ class Vertex: } elif isinstance(_value, dict): params[key] = _value - elif value.get("type") == "int": - params[key] = int(value.get("value")) - elif value.get("type") == "float": - params[key] = float(value.get("value")) + elif value.get("type") == "int" and value.get("value") is not None: + try: + params[key] = int(value.get("value")) + except ValueError: + params[key] = value.get("value") + elif value.get("type") == "float" and value.get("value") is not None: + try: + params[key] = float(value.get("value")) + except ValueError: + params[key] = value.get("value") else: params[key] = value.get("value") From 964b4ec7f285b1445583b2871e01053e9e037873 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 12 Oct 2023 16:29:48 -0300 Subject: [PATCH 09/14] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20improve=20?= =?UTF-8?q?code=20readability=20by=20formatting=20the=20CreateTrace=20func?= =?UTF-8?q?tion=20call=20in=20multiple=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/processing/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/processing/base.py b/src/backend/langflow/processing/base.py index 20e2a9d83..6c56a59dd 100644 --- a/src/backend/langflow/processing/base.py +++ b/src/backend/langflow/processing/base.py @@ -34,7 +34,9 @@ def get_langfuse_callback(trace_id): if langfuse := LangfuseInstance.get(): logger.debug("Langfuse credentials found") try: - trace = langfuse.trace(CreateTrace(name="langflow-"+trace_id, id=trace_id)) + trace = langfuse.trace( + CreateTrace(name="langflow-" + trace_id, id=trace_id) + ) return trace.getNewHandler() except Exception as exc: logger.error(f"Error initializing langfuse callback: {exc}") From dad8480ce36e4c2c066d6d8d17e10e486591570a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 12 Oct 2023 19:22:41 -0300 Subject: [PATCH 10/14] =?UTF-8?q?=F0=9F=94=A8=20refactor(HuggingFaceEndpoi?= =?UTF-8?q?nts.py):=20update=20import=20statement=20for=20HuggingFaceEndpo?= =?UTF-8?q?int=20class=20to=20match=20new=20file=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔧 chore(HuggingFaceEndpoints.py): remove unused import statement for langchain.llms.base module 🔧 chore(HuggingFaceEndpoints.py): remove unused "type" field from task parameter in build method signature 🔧 chore(HuggingFaceEndpoints.py): add default value for task parameter in build method signature 🔧 chore(HuggingFaceEndpoints.py): add default values for huggingfacehub_api_token and model_kwargs parameters in build method signature 🐛 fix(HuggingFaceEndpoints.py): add model_kwargs parameter to HuggingFaceEndpoint constructor to fix missing argument error --- .../langflow/components/llms/HuggingFaceEndpoints.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/components/llms/HuggingFaceEndpoints.py b/src/backend/langflow/components/llms/HuggingFaceEndpoints.py index ea2b4f20b..0d28d5b9b 100644 --- a/src/backend/langflow/components/llms/HuggingFaceEndpoints.py +++ b/src/backend/langflow/components/llms/HuggingFaceEndpoints.py @@ -1,6 +1,6 @@ from typing import Optional from langflow import CustomComponent -from langchain.llms import HuggingFaceEndpoint +from langchain.llms.huggingface_endpoint import HuggingFaceEndpoint from langchain.llms.base import BaseLLM @@ -13,7 +13,6 @@ class HuggingFaceEndpointsComponent(CustomComponent): "endpoint_url": {"display_name": "Endpoint URL", "password": True}, "task": { "display_name": "Task", - "type": "select", "options": ["text2text-generation", "text-generation", "summarization"], }, "huggingfacehub_api_token": {"display_name": "API token", "password": True}, @@ -27,7 +26,7 @@ class HuggingFaceEndpointsComponent(CustomComponent): def build( self, endpoint_url: str, - task="text2text-generation", + task: str = "text2text-generation", huggingfacehub_api_token: Optional[str] = None, model_kwargs: Optional[dict] = None, ) -> BaseLLM: @@ -36,6 +35,7 @@ class HuggingFaceEndpointsComponent(CustomComponent): endpoint_url=endpoint_url, task=task, huggingfacehub_api_token=huggingfacehub_api_token, + model_kwargs=model_kwargs, ) except Exception as e: raise ValueError("Could not connect to HuggingFace Endpoints API.") from e From 4366b02c4f1a27f9befd0244161d938828ff6145 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 12 Oct 2023 19:23:13 -0300 Subject: [PATCH 11/14] =?UTF-8?q?=F0=9F=94=80=20chore(field=5Ftyping):=20r?= =?UTF-8?q?eorganize=20imports=20and=20update=20=5F=5Fall=5F=5F=20list=20f?= =?UTF-8?q?or=20better=20readability=20and=20maintainability=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(field=5Ftyping):=20remove=20unused=20base.?= =?UTF-8?q?py=20file=20as=20it=20is=20no=20longer=20needed=20=F0=9F=94=80?= =?UTF-8?q?=20chore(constants):=20update=20import=20statements=20and=20add?= =?UTF-8?q?=20type=20aliases=20for=20better=20readability=20and=20maintain?= =?UTF-8?q?ability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/field_typing/__init__.py | 59 ++++++++++++++++--- src/backend/langflow/field_typing/base.py | 5 -- .../langflow/field_typing/constants.py | 9 ++- 3 files changed, 60 insertions(+), 13 deletions(-) delete mode 100644 src/backend/langflow/field_typing/base.py diff --git a/src/backend/langflow/field_typing/__init__.py b/src/backend/langflow/field_typing/__init__.py index 14cbba2d0..9a2161d3f 100644 --- a/src/backend/langflow/field_typing/__init__.py +++ b/src/backend/langflow/field_typing/__init__.py @@ -1,8 +1,53 @@ -from .base import NestedDict, Data -from .constants import * - -__all__ = ( - ["NestedDict", "Data"] - + list(LANGCHAIN_BASE_TYPES.keys()) - + list(CUSTOM_COMPONENT_SUPPORTED_TYPES.keys()) +# LANGCHAIN_BASE_TYPES = { +# "Chain": Chain, +# "AgentExecutor": AgentExecutor, +# "Tool": Tool, +# "BaseLLM": BaseLLM, +# "PromptTemplate": PromptTemplate, +# "BaseLoader": BaseLoader, +# "Document": Document, +# "TextSplitter": TextSplitter, +# "VectorStore": VectorStore, +# "Embeddings": Embeddings, +# "BaseRetriever": BaseRetriever, +# "BaseOutputParser": BaseOutputParser, +# "BaseMemory": BaseMemory, +# "BaseChatMemory": BaseChatMemory, +# } +from .constants import ( + Tool, + PromptTemplate, + Chain, + BaseChatMemory, + BaseLLM, + BaseLoader, + BaseMemory, + BaseOutputParser, + BaseRetriever, + VectorStore, + Embeddings, + TextSplitter, + Document, + AgentExecutor, + NestedDict, + Data, ) + +__all__ = [ + "NestedDict", + "Data", + "Tool", + "PromptTemplate", + "Chain", + "BaseChatMemory", + "BaseLLM", + "BaseLoader", + "BaseMemory", + "BaseOutputParser", + "BaseRetriever", + "VectorStore", + "Embeddings", + "TextSplitter", + "Document", + "AgentExecutor", +] diff --git a/src/backend/langflow/field_typing/base.py b/src/backend/langflow/field_typing/base.py deleted file mode 100644 index 48b737a63..000000000 --- a/src/backend/langflow/field_typing/base.py +++ /dev/null @@ -1,5 +0,0 @@ -from typing import Union, Dict, Any - -# Type alias for more complex dicts -NestedDict = Dict[str, Union[str, Dict]] -Data = Any diff --git a/src/backend/langflow/field_typing/constants.py b/src/backend/langflow/field_typing/constants.py index 4a8072b15..3ce429548 100644 --- a/src/backend/langflow/field_typing/constants.py +++ b/src/backend/langflow/field_typing/constants.py @@ -10,7 +10,14 @@ from langchain.schema.memory import BaseMemory from langchain.text_splitter import TextSplitter from langchain.tools import Tool from langchain.vectorstores.base import VectorStore -from langflow.field_typing import Data, NestedDict +from typing import Union, Dict + +# Type alias for more complex dicts +NestedDict = Dict[str, Union[str, Dict]] + + +class Data: + pass LANGCHAIN_BASE_TYPES = { From 7bdf5641707f6af18d5b33970ac3e4760bfb2b18 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 12 Oct 2023 19:23:45 -0300 Subject: [PATCH 12/14] =?UTF-8?q?=F0=9F=94=A7=20chore(constants.py):=20cle?= =?UTF-8?q?an=20up=20import=20statements=20and=20remove=20unnecessary=20wh?= =?UTF-8?q?itespace=20to=20improve=20code=20readability=20=F0=9F=90=9B=20f?= =?UTF-8?q?ix(custom=5Fcomponent.py):=20set=20the=20type=20of=20argument?= =?UTF-8?q?=20to=20"Data"=20if=20it=20is=20not=20specified=20to=20ensure?= =?UTF-8?q?=20consistency=20and=20prevent=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/constants.py | 24 ++++++++++++++++--- .../interface/custom/custom_component.py | 4 +++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/interface/custom/constants.py b/src/backend/langflow/interface/custom/constants.py index a3eb64336..6df72500c 100644 --- a/src/backend/langflow/interface/custom/constants.py +++ b/src/backend/langflow/interface/custom/constants.py @@ -1,15 +1,33 @@ DEFAULT_CUSTOM_COMPONENT_CODE = """from langflow import CustomComponent -from langflow.field_typing import * +from langflow.field_typing import ( + Tool, + PromptTemplate, + Chain, + BaseChatMemory, + BaseLLM, + BaseLoader, + BaseMemory, + BaseOutputParser, + BaseRetriever, + VectorStore, + Embeddings, + TextSplitter, + Document, + AgentExecutor, + NestedDict, + Data, +) + class Component(CustomComponent): display_name: str = "Custom Component" description: str = "Create any custom component you want!" def build_config(self): - return { "param": { "display_name": "Parameter" } } + return {"param": {"display_name": "Parameter"}} def build(self, param: Data) -> Data: - return params + return param """ diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 42b68ed40..4b889e77b 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -108,7 +108,9 @@ class CustomComponent(Component, extra=Extra.allow): ), }, ) - # TODO arg type should be Data if it is None + elif not arg.get("type"): + # Set the type to Data + arg["type"] = "Data" return args @property From d9e69b1ba30116bb41dacbe9561eab9c6f976562 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 16 Oct 2023 09:59:43 -0300 Subject: [PATCH 13/14] =?UTF-8?q?=F0=9F=94=A7=20chore(.env.example):=20add?= =?UTF-8?q?=20LANGFLOW=5FAUTO=5FLOGIN=20variable=20to=20enable/disable=20a?= =?UTF-8?q?utomatic=20login=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.env.example b/.env.example index b3e592bdf..ccab7c28e 100644 --- a/.env.example +++ b/.env.example @@ -56,6 +56,14 @@ LANGFLOW_REMOVE_API_KEYS= # LANGFLOW_REDIS_CACHE_EXPIRE (default: 3600) LANGFLOW_CACHE_TYPE= +# Auto login +# If set to true then a superuser will be logged in automatically +# and the login page will be skipped, keeping the +# default experience of Langflow +# Values: true, false +# Example: LANGFLOW_AUTO_LOGIN=true +LANGFLOW_AUTO_LOGIN= + # Superuser username # Example: LANGFLOW_SUPERUSER=admin LANGFLOW_SUPERUSER= From 466c158f1576881deb4726877b3a1901d7a90307 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 16 Oct 2023 13:53:36 -0300 Subject: [PATCH 14/14] fix(tabsContext.tsx): remove unnecessary noticeData setting when downloading a file feat(tabsContext.tsx): change the order of arguments in addFlow function call to improve readability feat(exportModal/index.tsx): add alertContext and setNoticeData to display a warning when saving a file with API keys feat(exportModal/index.tsx): add a caution message to inform users about the consequences of saving with API keys --- src/frontend/src/contexts/tabsContext.tsx | 5 +---- src/frontend/src/modals/exportModal/index.tsx | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 79b39ad60..cba2376b5 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -260,9 +260,6 @@ export function TabsProvider({ children }: { children: ReactNode }) { // simulate a click on the link element to trigger the download link.click(); - setNoticeData({ - title: "Warning: Critical data, JSON file may include API keys.", - }); } function downloadFlows() { @@ -300,7 +297,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { let fileData = JSON.parse(text); if (fileData.flows) { fileData.flows.forEach((flow: FlowType) => { - id = addFlow(flow, newProject); + id = addFlow(newProject, flow); }); } // parse the text into a JSON object diff --git a/src/frontend/src/modals/exportModal/index.tsx b/src/frontend/src/modals/exportModal/index.tsx index 01b655b39..89bc292c9 100644 --- a/src/frontend/src/modals/exportModal/index.tsx +++ b/src/frontend/src/modals/exportModal/index.tsx @@ -4,6 +4,7 @@ import IconComponent from "../../components/genericIconComponent"; import { Button } from "../../components/ui/button"; import { Checkbox } from "../../components/ui/checkbox"; import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants"; +import { alertContext } from "../../contexts/alertContext"; import { TabsContext } from "../../contexts/tabsContext"; import { removeApiKeys } from "../../utils/reactflowUtils"; import BaseModal from "../baseModal"; @@ -11,7 +12,8 @@ import BaseModal from "../baseModal"; const ExportModal = forwardRef( (props: { children: ReactNode }, ref): JSX.Element => { const { flows, tabId, downloadFlow } = useContext(TabsContext); - const [checked, setChecked] = useState(false); + const { setNoticeData } = useContext(alertContext); + const [checked, setChecked] = useState(true); const flow = flows.find((f) => f.id === tabId); useEffect(() => { setName(flow!.name); @@ -44,6 +46,7 @@ const ExportModal = forwardRef(
{ setChecked(event); }} @@ -52,18 +55,26 @@ const ExportModal = forwardRef( Save with my API keys
+ + Caution: Uncheck this box only removes API keys from fields + specifically designated for API keys. +