From 834570df8b655a0ba240456a8305865c031cb16c Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Fri, 7 Jun 2024 14:40:03 -0300 Subject: [PATCH] refactor: Update output names in TextInput, TextOutput, RecordsOutput, ChatInput, and ChatOutput --- .../base/langflow/field_typing/constants.py | 2 +- .../base/langflow/graph/vertex/types.py | 6 +++--- .../base/langflow/template/field/base.py | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/backend/base/langflow/field_typing/constants.py b/src/backend/base/langflow/field_typing/constants.py index d73257c14..512e60529 100644 --- a/src/backend/base/langflow/field_typing/constants.py +++ b/src/backend/base/langflow/field_typing/constants.py @@ -6,7 +6,7 @@ from langchain.memory.chat_memory import BaseChatMemory from langchain_core.document_loaders import BaseLoader from langchain_core.documents import Document from langchain_core.embeddings import Embeddings -from langchain_core.language_models import BaseLLM, BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel, BaseLLM from langchain_core.memory import BaseMemory from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate, PromptTemplate diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index 20b6b393c..1aed9a8dc 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -156,7 +156,7 @@ class InterfaceVertex(ComponentVertex): if isinstance(message, str): message = unescape_string(message) stream_url = None - text_output = self.results["Message"] + text_output = self.results["message"] if isinstance(text_output, (AIMessage, AIMessageChunk)): artifacts = ChatOutputResponse.from_message( text_output, @@ -173,8 +173,8 @@ class InterfaceVertex(ComponentVertex): elif isinstance(message, (AsyncIterator, Iterator)): stream_url = self.build_stream_url() message = "" - self.results["Message"] = message - self.results["Record"].message = message + self.results["message"] = message + self.results["record"].message = message self._built_object = self.results elif not isinstance(text_output, str): message = str(text_output) diff --git a/src/backend/base/langflow/template/field/base.py b/src/backend/base/langflow/template/field/base.py index e3160b9a8..808a59dfc 100644 --- a/src/backend/base/langflow/template/field/base.py +++ b/src/backend/base/langflow/template/field/base.py @@ -84,7 +84,7 @@ class Input(BaseModel): def serialize_model(self, handler): result = handler(self) # If the field is str, we add the Text input type - if self.field_type in [str, Text]: + if self.field_type in ["str", "Text"]: if "input_types" not in result: result["input_types"] = ["Text"] if self.field_type == Text: @@ -110,7 +110,10 @@ class Input(BaseModel): # this should be done for all types # How to check if v is a type? if isinstance(v, (type, GenericAlias)): - return str(v) + if isinstance(v, type): + v = v.__name__ + else: + v = str(v) elif not isinstance(v, str): raise ValueError(f"type must be a string or a type, not {type(v)}") return v @@ -144,19 +147,19 @@ class Input(BaseModel): class Output(BaseModel): - types: Optional[list[str]] = Field(default=[], serialization_alias="types") + types: Optional[list[str]] = Field(default=[]) """List of output types for the field.""" - selected: Optional[str] = Field(default=None, serialization_alias="selected") + selected: Optional[str] = Field(default=None) """The selected output type for the field.""" + name: str = Field(default=None) + """The name of the field.""" + display_name: Optional[str] = Field(default=None) """The display name of the field.""" - name: str = Field(default=None, serialization_alias="name") - """The name of the field.""" - - method: Optional[str] = Field(default=None, serialization_alias="method") + method: Optional[str] = Field(default=None) """The method to use for the output.""" def to_dict(self):