From 73b23a2501909330a28dec8cbb563a6eb41ffe12 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 21 Feb 2024 21:38:55 -0300 Subject: [PATCH 01/12] Add provider option for API key --- .../langflow/components/llms/ChatLiteLLM.py | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/components/llms/ChatLiteLLM.py b/src/backend/langflow/components/llms/ChatLiteLLM.py index f2b7f7dc3..30cb1407b 100644 --- a/src/backend/langflow/components/llms/ChatLiteLLM.py +++ b/src/backend/langflow/components/llms/ChatLiteLLM.py @@ -1,4 +1,3 @@ -import os from typing import Any, Callable, Dict, Optional, Union from langchain_community.chat_models.litellm import ChatLiteLLM, ChatLiteLLMException @@ -27,6 +26,18 @@ class ChatLiteLLMComponent(CustomComponent): "required": False, "password": True, }, + "provider": { + "display_name": "Provider", + "info": "The provider of the API key.", + "options": [ + "OpenAI", + "Azure", + "Anthropic", + "Replicate", + "Cohere", + "OpenRouter", + ], + }, "streaming": { "display_name": "Streaming", "field_type": "bool", @@ -96,7 +107,8 @@ class ChatLiteLLMComponent(CustomComponent): def build( self, model: str, - api_key: str, + provider: str, + api_key: Optional[str] = None, streaming: bool = True, temperature: Optional[float] = 0.7, model_kwargs: Optional[Dict[str, Any]] = {}, @@ -114,13 +126,19 @@ class ChatLiteLLMComponent(CustomComponent): litellm.set_verbose = verbose except ImportError: raise ChatLiteLLMException( - "Could not import litellm python package. " "Please install it with `pip install litellm`" + "Could not import litellm python package. " + "Please install it with `pip install litellm`" ) - if api_key: - if "perplexity" in model: - os.environ["PERPLEXITYAI_API_KEY"] = api_key - elif "replicate" in model: - os.environ["REPLICATE_API_KEY"] = api_key + provider_map = { + "OpenAI": "openai_api_key", + "Azure": "azure_api_key", + "Anthropic": "anthropic_api_key", + "Replicate": "replicate_api_key", + "Cohere": "cohere_api_key", + "OpenRouter": "openrouter_api_key", + } + # Set the API key based on the provider + kwarg = {provider_map[provider]: api_key} LLM = ChatLiteLLM( model=model, @@ -133,5 +151,6 @@ class ChatLiteLLMComponent(CustomComponent): n=n, max_tokens=max_tokens, max_retries=max_retries, + **kwarg, ) return LLM From 1e3cdd3f327a351fc568e4817436a2ba2852f86a Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 22 Feb 2024 12:53:15 +0100 Subject: [PATCH 02/12] Made categories --- src/frontend/src/components/IOview/index.tsx | 10 ++++++++++ src/frontend/src/utils/styleUtils.ts | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index ef9d4018d..443197fa6 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -126,6 +126,16 @@ export default function IOView({ children, open, setOpen }): JSX.Element { )} +
+ {categories[selectedCategory].name === "Inputs" && + <> + Text Inputs + } + {categories[selectedCategory].name === "Outputs" && + <> + Prompt Outputs + } +
{UpdateAccordion() .filter( (input) => diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index 7a42368bd..16565e53c 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -11,7 +11,7 @@ import { ChevronDown, ChevronLeft, ChevronRight, - Sliders, + ChevronRightSquare, ChevronUp, ChevronsLeft, ChevronsRight, @@ -40,6 +40,7 @@ import { Fingerprint, FlaskConical, FolderPlus, + FormInput, Forward, Gift, GitBranchPlus, @@ -88,6 +89,7 @@ import { Share, Share2, Shield, + Sliders, Sparkles, Square, Store, @@ -385,6 +387,8 @@ export const nodeIconsLucide: iconsType = { Square, Minimize2, Maximize2, + FormInput, + ChevronRightSquare, SaveAll, Forward, Share2, From a94b5b9657cbbf85ff458702cd43135fecdcbd81 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 22 Feb 2024 12:57:07 +0100 Subject: [PATCH 03/12] Fixed chat button --- src/frontend/src/components/IOview/index.tsx | 92 +++++++++++--------- src/frontend/src/constants/constants.ts | 2 +- src/frontend/src/utils/styleUtils.ts | 2 + 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index 443197fa6..3ee2dec6e 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -60,11 +60,17 @@ export default function IOView({ children, open, setOpen }): JSX.Element { } function UpdateAccordion() { - return (categories[selectedCategory]?.name ?? "Inputs") === "Inputs" ? inputs : outputs; + return (categories[selectedCategory]?.name ?? "Inputs") === "Inputs" + ? inputs + : outputs; } return ( - + {children} {/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */} @@ -85,56 +91,58 @@ export default function IOView({ children, open, setOpen }): JSX.Element { handleSelectChange() ? "w-2/6" : "w-full" )} > -
- {categories.map((category, index) => { - return ( - //hide chat button if chat is alredy on the view - - ); - })} +
+
+ {categories.map((category, index) => { + return ( + //hide chat button if chat is alredy on the view + + ); + })} +
{(outputs.map((output) => output.type).includes("ChatOutput") || inputs.map((output) => output.type).includes("chatInput")) && selectedView.type !== "ChatOutput" && ( - + )}
-
- {categories[selectedCategory].name === "Inputs" && - <> - Text Inputs - } - {categories[selectedCategory].name === "Outputs" && - <> - Prompt Outputs - } +
+ {categories[selectedCategory].name === "Inputs" && ( + <> + + Text Inputs + + )} + {categories[selectedCategory].name === "Outputs" && ( + <> + + Prompt Outputs + + )}
{UpdateAccordion() .filter( diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index b9422efab..c1eaa999d 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -681,4 +681,4 @@ export const LANGFLOW_SUPPORTED_TYPES = new Set([ export const priorityFields = new Set(["code", "template"]); export const INPUT_TYPES = new Set(["ChatInput", "TextInput"]); -export const OUTPUT_TYPES = new Set(["ChatOutput"]); +export const OUTPUT_TYPES = new Set(["ChatOutput", "PromptTemplate"]); diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index 16565e53c..3df9442e2 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -65,6 +65,7 @@ import { Menu, MessageCircle, MessageSquare, + MessageSquareMore, MessagesSquare, Minimize2, Minus, @@ -390,6 +391,7 @@ export const nodeIconsLucide: iconsType = { FormInput, ChevronRightSquare, SaveAll, + MessageSquareMore, Forward, Share2, Share, From cce060968f38cc65599f73b2b31337e81eb0019f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 22 Feb 2024 13:03:11 +0100 Subject: [PATCH 04/12] Fixed input and output view --- src/frontend/src/components/IOInputField/index.tsx | 7 ++++++- src/frontend/src/components/IOOutputView/index.tsx | 7 ++++++- src/frontend/src/components/IOview/index.tsx | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/components/IOInputField/index.tsx b/src/frontend/src/components/IOInputField/index.tsx index fa7492e53..c499bd551 100644 --- a/src/frontend/src/components/IOInputField/index.tsx +++ b/src/frontend/src/components/IOInputField/index.tsx @@ -62,5 +62,10 @@ export default function IOInputField({ ); } } - return
{handleInputType()}
; + return ( +
+ {inputType} + {handleInputType()} +
+ ); } diff --git a/src/frontend/src/components/IOOutputView/index.tsx b/src/frontend/src/components/IOOutputView/index.tsx index aed4317b8..fdae4b6b3 100644 --- a/src/frontend/src/components/IOOutputView/index.tsx +++ b/src/frontend/src/components/IOOutputView/index.tsx @@ -43,5 +43,10 @@ export default function IOOutputView({ ); } } - return
{handleOutputType()}
; + return ( +
+ {outputType} + {handleOutputType()} +
+ ); } diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index 3ee2dec6e..6513680ac 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -182,6 +182,7 @@ export default function IOView({ children, open, setOpen }): JSX.Element { keyValue={input.id} >
+
{node && (categories[selectedCategory].name === "Inputs" ? ( ))} +
+
From b0a2d625afab5758eec01b85e8948d74b24c0515 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 22 Feb 2024 13:08:28 +0100 Subject: [PATCH 05/12] Made chat button --- src/frontend/src/components/IOview/index.tsx | 33 +++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index 6513680ac..6b6bae2e3 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -183,27 +183,32 @@ export default function IOView({ children, open, setOpen }): JSX.Element { >
- {node && - (categories[selectedCategory].name === "Inputs" ? ( - - ) : ( - - ))} + {node && + (categories[selectedCategory].name === "Inputs" ? ( + + ) : ( + + ))}
-
); })} - {handleSelectChange() && handleSelectChange()} + {handleSelectChange() ? ( + handleSelectChange() + ) : ( +
+ +
+ )}
From 138aa1c5fea102a7fa70bdca4e9a46af63ea0a90 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 22 Feb 2024 13:08:52 +0100 Subject: [PATCH 06/12] Removed prompt template from outputs --- src/frontend/src/constants/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index c1eaa999d..b9422efab 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -681,4 +681,4 @@ export const LANGFLOW_SUPPORTED_TYPES = new Set([ export const priorityFields = new Set(["code", "template"]); export const INPUT_TYPES = new Set(["ChatInput", "TextInput"]); -export const OUTPUT_TYPES = new Set(["ChatOutput", "PromptTemplate"]); +export const OUTPUT_TYPES = new Set(["ChatOutput"]); From 71c5d836477c278dffd4f043c2b4d10f9c26310c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 10:40:39 -0300 Subject: [PATCH 07/12] Fix exception handling in build_vertex function --- src/backend/langflow/api/v1/chat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index ada9a4fa7..81d132aa4 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -10,6 +10,9 @@ from fastapi import ( WebSocketException, status, ) +from loguru import logger +from sqlmodel import Session + from langflow.api.utils import build_and_cache_graph, format_elapsed_time from langflow.api.v1.schemas import ( ResultData, @@ -24,8 +27,6 @@ from langflow.services.auth.utils import ( from langflow.services.chat.service import ChatService from langflow.services.deps import get_chat_service, get_session from langflow.services.monitor.utils import log_vertex_build -from loguru import logger -from sqlmodel import Session router = APIRouter(tags=["Chat"]) @@ -172,7 +173,7 @@ async def build_vertex( raise ValueError(f"No result found for vertex {vertex_id}") chat_service.set_cache(flow_id, graph) except Exception as exc: - params = repr(exc) + params = str(exc) valid = False result_dict = ResultData(results={}) artifacts = {} From c70a227ee4417deabd5799888e6be64d7d1f447b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 10:40:46 -0300 Subject: [PATCH 08/12] Refactor ConversationChainComponent build method --- .../components/chains/ConversationChain.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/components/chains/ConversationChain.py b/src/backend/langflow/components/chains/ConversationChain.py index f3a302fe8..43f71e67b 100644 --- a/src/backend/langflow/components/chains/ConversationChain.py +++ b/src/backend/langflow/components/chains/ConversationChain.py @@ -23,19 +23,25 @@ class ConversationChainComponent(CustomComponent): def build( self, + inputs: str, llm: BaseLanguageModel, memory: Optional[BaseMemory] = None, - inputs: dict = {}, ) -> Union[Chain, Callable, Text]: if memory is None: chain = ConversationChain(llm=llm) - chain = ConversationChain(llm=llm, memory=memory) + else: + chain = ConversationChain(llm=llm, memory=memory) result = chain.invoke(inputs) # result is an AIMessage which is a subclass of BaseMessage # We need to check if it is a string or a BaseMessage if hasattr(result, "content") and isinstance(result.content, str): - return result.content + self.status = "is message" + result = result.content elif isinstance(result, str): - return result - - return str(result) + self.status = "is_string" + result = result + else: + # is dict + result = result.get("response") + self.status = result + return result From 4d0753703127e8986bd93663b6260c1cd70f8b59 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 11:56:02 -0300 Subject: [PATCH 09/12] Fix conditional rendering in IOView component --- src/frontend/src/components/IOview/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index 6b6bae2e3..a85a98ac7 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -131,13 +131,13 @@ export default function IOView({ children, open, setOpen }): JSX.Element { )}
- {categories[selectedCategory].name === "Inputs" && ( + {categories[selectedCategory]?.name === "Inputs" && ( <> Text Inputs )} - {categories[selectedCategory].name === "Outputs" && ( + {categories[selectedCategory]?.name === "Outputs" && ( <> Prompt Outputs @@ -184,7 +184,7 @@ export default function IOView({ children, open, setOpen }): JSX.Element {
{node && - (categories[selectedCategory].name === "Inputs" ? ( + (categories[selectedCategory]?.name === "Inputs" ? ( - +
)}
From cb4fe92e9b06fdcb7de159be6e10ed4d63ab02c8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 11:57:03 -0300 Subject: [PATCH 10/12] Add attribute validation functions and mapping --- .../langflow/interface/custom/attributes.py | 31 ++++++++++++++++++ .../custom/custom_component/component.py | 32 ++----------------- .../langflow/interface/custom/utils.py | 15 +++------ 3 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 src/backend/langflow/interface/custom/attributes.py diff --git a/src/backend/langflow/interface/custom/attributes.py b/src/backend/langflow/interface/custom/attributes.py new file mode 100644 index 000000000..7aa2bc184 --- /dev/null +++ b/src/backend/langflow/interface/custom/attributes.py @@ -0,0 +1,31 @@ +def validate_icon(value: str, *args, **kwargs): + # we are going to use the emoji library to validate the emoji + # emojis can be defined using the :emoji_name: syntax + if not value.startswith(":") or not value.endswith(":"): + warnings.warn("Invalid emoji. Please use the :emoji_name: syntax.") + return value + emoji_value = emoji.emojize(value, variant="emoji_type") + if value == emoji_value: + warnings.warn(f"Invalid emoji. {value} is not a valid emoji.") + return value + return emoji_value + + +def getattr_return_str(value): + + return str(value) if value else "" + + +def getattr_return_bool(value): + if isinstance(value, bool): + return value + + +ATTR_FUNC_MAPPING = { + "display_name": getattr_return_str, + "description": getattr_return_str, + "beta": getattr_return_str, + "documentation": getattr_return_str, + "icon": validate_icon, + "pinned": getattr_return_bool, +} diff --git a/src/backend/langflow/interface/custom/custom_component/component.py b/src/backend/langflow/interface/custom/custom_component/component.py index 4188c2f3b..c35899610 100644 --- a/src/backend/langflow/interface/custom/custom_component/component.py +++ b/src/backend/langflow/interface/custom/custom_component/component.py @@ -2,9 +2,10 @@ import operator import warnings from typing import Any, ClassVar, Optional -import emoji from cachetools import TTLCache, cachedmethod from fastapi import HTTPException + +from langflow.interface.custom.attributes import ATTR_FUNC_MAPPING from langflow.interface.custom.code_parser import CodeParser from langflow.interface.custom.eval import eval_custom_component_code from langflow.utils import validate @@ -65,14 +66,6 @@ class Component: return validate.create_function(self.code, self._function_entrypoint_name) - def getattr_return_str(self, value): - - return str(value) if value else "" - - def getattr_return_bool(self, value): - if isinstance(value, bool): - return value - def build_template_config(self) -> dict: if not self.code: return {} @@ -80,15 +73,8 @@ class Component: cc_class = eval_custom_component_code(self.code) component_instance = cc_class() template_config = {} - attributes_func_mapping = { - "display_name": self.getattr_return_str, - "description": self.getattr_return_str, - "beta": self.getattr_return_str, - "documentation": self.getattr_return_str, - "icon": self.validate_icon, - } - for attribute, func in attributes_func_mapping.items(): + for attribute, func in ATTR_FUNC_MAPPING.items(): if hasattr(component_instance, attribute): value = getattr(component_instance, attribute) if value is not None: @@ -96,17 +82,5 @@ class Component: return template_config - def validate_icon(self, value: str, *args, **kwargs): - # we are going to use the emoji library to validate the emoji - # emojis can be defined using the :emoji_name: syntax - if not value.startswith(":") or not value.endswith(":"): - warnings.warn("Invalid emoji. Please use the :emoji_name: syntax.") - return value - emoji_value = emoji.emojize(value, variant="emoji_type") - if value == emoji_value: - warnings.warn(f"Invalid emoji. {value} is not a valid emoji.") - return value - return emoji_value - def build(self, *args: Any, **kwargs: Any) -> Any: raise NotImplementedError diff --git a/src/backend/langflow/interface/custom/utils.py b/src/backend/langflow/interface/custom/utils.py index cc0f2bd70..f0ef4444f 100644 --- a/src/backend/langflow/interface/custom/utils.py +++ b/src/backend/langflow/interface/custom/utils.py @@ -7,7 +7,10 @@ from typing import Any, Dict, List, Optional, Union from uuid import UUID from fastapi import HTTPException +from loguru import logger + from langflow.field_typing.range_spec import RangeSpec +from langflow.interface.custom.attributes import ATTR_FUNC_MAPPING from langflow.interface.custom.code_parser.utils import extract_inner_type from langflow.interface.custom.custom_component import CustomComponent from langflow.interface.custom.directory_reader.utils import ( @@ -22,7 +25,6 @@ from langflow.template.frontend_node.custom_components import ( ) from langflow.utils import validate from langflow.utils.util import get_base_classes -from loguru import logger def add_output_types( @@ -263,16 +265,9 @@ def run_build_config( def sanitize_template_config(template_config): """Sanitize the template config""" - attributes = { - "display_name", - "description", - "beta", - "documentation", - "output_types", - "icon", - } + for key in template_config.copy(): - if key not in attributes: + if key not in ATTR_FUNC_MAPPING.keys(): template_config.pop(key, None) return template_config From 16018c1d6f6df04f17dd18dc17a101b26796a516 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 11:57:15 -0300 Subject: [PATCH 11/12] Add pinned state to CustomComponent and FrontendNode --- .../custom/custom_component/custom_component.py | 3 +++ .../langflow/template/frontend_node/base.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/interface/custom/custom_component/custom_component.py b/src/backend/langflow/interface/custom/custom_component/custom_component.py index 8a5d72073..687c25439 100644 --- a/src/backend/langflow/interface/custom/custom_component/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component/custom_component.py @@ -6,6 +6,7 @@ from uuid import UUID import yaml from cachetools import TTLCache, cachedmethod from fastapi import HTTPException + from langflow.interface.custom.code_parser.utils import ( extract_inner_type_from_generic_alias, extract_union_types_from_generic_alias, @@ -35,6 +36,8 @@ class CustomComponent(Component): """The field configuration of the component. Defaults to an empty dictionary.""" field_order: Optional[List[str]] = None """The field order of the component. Defaults to an empty list.""" + pinned: Optional[bool] = False + """The default pinned state of the component. Defaults to False.""" code_class_base_inheritance: ClassVar[str] = "CustomComponent" function_entrypoint_name: ClassVar[str] = "build" function: Optional[Callable] = None diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index d9f594d34..aadb6c6ea 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -2,6 +2,8 @@ import re from collections import defaultdict from typing import ClassVar, Dict, List, Optional, Union +from pydantic import BaseModel, Field, field_serializer, model_serializer + from langflow.template.field.base import TemplateField from langflow.template.frontend_node.constants import ( CLASSES_TO_REMOVE, @@ -10,7 +12,6 @@ from langflow.template.frontend_node.constants import ( from langflow.template.frontend_node.formatter import field_formatters from langflow.template.template.base import Template from langflow.utils import constants -from pydantic import BaseModel, Field, field_serializer, model_serializer class FieldFormatters(BaseModel): @@ -44,17 +45,31 @@ class FieldFormatters(BaseModel): class FrontendNode(BaseModel): _format_template: bool = True template: Template + """Template for the frontend node.""" description: Optional[str] = None + """Description of the frontend node.""" icon: Optional[str] = None + """Icon of the frontend node.""" is_composition: Optional[bool] = None + """Whether the frontend node is used for composition.""" base_classes: List[str] + """List of base classes for the frontend node.""" name: str = "" + """Name of the frontend node.""" display_name: Optional[str] = "" + """Display name of the frontend node.""" documentation: str = "" + """Documentation of the frontend node.""" custom_fields: Optional[Dict] = defaultdict(list) + """Custom fields of the frontend node.""" output_types: List[str] = [] + """List of output types for the frontend node.""" full_path: Optional[str] = None + """Full path of the frontend node.""" field_formatters: FieldFormatters = Field(default_factory=FieldFormatters) + """Field formatters for the frontend node.""" + pinned: bool = False + """Whether the frontend node is pinned.""" beta: bool = False error: Optional[str] = None From ef357198b9334303a0b04d1c28bbb508b5d40951 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 12:36:49 -0300 Subject: [PATCH 12/12] Refactor import statements and update field info in MemoryFrontendNode class --- .../langflow/template/frontend_node/memories.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/memories.py b/src/backend/langflow/template/frontend_node/memories.py index fc9df6291..1b2b5c9dc 100644 --- a/src/backend/langflow/template/frontend_node/memories.py +++ b/src/backend/langflow/template/frontend_node/memories.py @@ -4,7 +4,9 @@ from langchain_community.chat_message_histories.mongodb import ( DEFAULT_COLLECTION_NAME, DEFAULT_DBNAME, ) -from langchain_community.chat_message_histories.postgres import DEFAULT_CONNECTION_STRING +from langchain_community.chat_message_histories.postgres import ( + DEFAULT_CONNECTION_STRING, +) from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode @@ -13,7 +15,9 @@ from langflow.template.template.base import Template class MemoryFrontendNode(FrontendNode): - #! Needs testing + + pinned: bool = True + def add_extra_fields(self) -> None: # chat history should have another way to add common field? # prevent adding incorect field in ChatMessageHistory @@ -77,7 +81,9 @@ class MemoryFrontendNode(FrontendNode): field.show = True field.advanced = False field.value = "" - field.info = INPUT_KEY_INFO if field.name == "input_key" else OUTPUT_KEY_INFO + field.info = ( + INPUT_KEY_INFO if field.name == "input_key" else OUTPUT_KEY_INFO + ) if field.name == "memory_key": field.value = "chat_history"