add "" to input mixin
This commit is contained in:
parent
8a98f4c53d
commit
2b1786f791
3 changed files with 4 additions and 85 deletions
|
|
@ -1,82 +0,0 @@
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from langflow.base.memory.memory import BaseMemoryComponent
|
|
||||||
from langflow.field_typing import Text
|
|
||||||
from langflow.helpers.data import messages_to_text
|
|
||||||
from langflow.memory import get_messages
|
|
||||||
from langflow.schema.message import Message
|
|
||||||
|
|
||||||
|
|
||||||
class MemoryComponent(BaseMemoryComponent):
|
|
||||||
display_name = "Chat Memory"
|
|
||||||
description = "Retrieves stored chat messages given a specific Session ID."
|
|
||||||
beta: bool = True
|
|
||||||
icon = "history"
|
|
||||||
|
|
||||||
def build_config(self):
|
|
||||||
return {
|
|
||||||
"sender": {
|
|
||||||
"options": ["Machine", "User", "Machine and User"],
|
|
||||||
"display_name": "Sender Type",
|
|
||||||
},
|
|
||||||
"sender_name": {"display_name": "Sender Name", "advanced": True},
|
|
||||||
"n_messages": {
|
|
||||||
"display_name": "Number of Messages",
|
|
||||||
"info": "Number of messages to retrieve.",
|
|
||||||
},
|
|
||||||
"session_id": {
|
|
||||||
"display_name": "Session ID",
|
|
||||||
"info": "Session ID of the chat history.",
|
|
||||||
"input_types": ["Text"],
|
|
||||||
},
|
|
||||||
"order": {
|
|
||||||
"options": ["Ascending", "Descending"],
|
|
||||||
"display_name": "Order",
|
|
||||||
"info": "Order of the messages.",
|
|
||||||
"advanced": True,
|
|
||||||
},
|
|
||||||
"data_template": {
|
|
||||||
"display_name": "Data Template",
|
|
||||||
"multiline": True,
|
|
||||||
"info": "Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.",
|
|
||||||
"advanced": True,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_messages(self, **kwargs) -> list[Message]:
|
|
||||||
# Validate kwargs by checking if it contains the correct keys
|
|
||||||
if "sender" not in kwargs:
|
|
||||||
kwargs["sender"] = None
|
|
||||||
if "sender_name" not in kwargs:
|
|
||||||
kwargs["sender_name"] = None
|
|
||||||
if "session_id" not in kwargs:
|
|
||||||
kwargs["session_id"] = None
|
|
||||||
if "limit" not in kwargs:
|
|
||||||
kwargs["limit"] = 5
|
|
||||||
if "order" not in kwargs:
|
|
||||||
kwargs["order"] = "Descending"
|
|
||||||
|
|
||||||
kwargs["order"] = "DESC" if kwargs["order"] == "Descending" else "ASC"
|
|
||||||
if kwargs["sender"] == "Machine and User":
|
|
||||||
kwargs["sender"] = None
|
|
||||||
return get_messages(**kwargs)
|
|
||||||
|
|
||||||
def build(
|
|
||||||
self,
|
|
||||||
sender: Optional[str] = "Machine and User",
|
|
||||||
sender_name: Optional[str] = None,
|
|
||||||
session_id: Optional[str] = None,
|
|
||||||
n_messages: int = 5,
|
|
||||||
order: Optional[str] = "Descending",
|
|
||||||
data_template: Optional[str] = "{sender_name}: {text}",
|
|
||||||
) -> Text:
|
|
||||||
messages = self.get_messages(
|
|
||||||
sender=sender,
|
|
||||||
sender_name=sender_name,
|
|
||||||
session_id=session_id,
|
|
||||||
limit=n_messages,
|
|
||||||
order=order,
|
|
||||||
)
|
|
||||||
messages_str = messages_to_text(template=data_template or "", messages=messages)
|
|
||||||
self.status = messages_str
|
|
||||||
return messages_str
|
|
||||||
|
|
@ -36,8 +36,8 @@ class BaseInputMixin(BaseModel):
|
||||||
show: bool = True
|
show: bool = True
|
||||||
"""Should the field be shown. Defaults to True."""
|
"""Should the field be shown. Defaults to True."""
|
||||||
|
|
||||||
value: Any = None
|
value: Any = ""
|
||||||
"""The value of the field. Default is None."""
|
"""The value of the field. Default is an empty string."""
|
||||||
|
|
||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
"""Name of the field. Default is an empty string."""
|
"""Name of the field. Default is an empty string."""
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin): # noqa:
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
|
||||||
load_from_db: StrictBoolean = False
|
load_from_db: StrictBoolean = False
|
||||||
"""Defines if the field will allow the user to open a text editor. Default is False."""
|
"""Defines if the field will allow the user to open a text editor. Default is False."""
|
||||||
value: Optional[str] = ""
|
|
||||||
|
|
||||||
|
|
||||||
class MultilineInput(BaseInputMixin):
|
class MultilineInput(BaseInputMixin):
|
||||||
|
|
@ -54,10 +53,12 @@ class BoolInput(BaseInputMixin, ListableInputMixin):
|
||||||
|
|
||||||
class NestedDictInput(BaseInputMixin, ListableInputMixin):
|
class NestedDictInput(BaseInputMixin, ListableInputMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.NESTED_DICT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.NESTED_DICT
|
||||||
|
value: Optional[dict] = {}
|
||||||
|
|
||||||
|
|
||||||
class DictInput(BaseInputMixin, ListableInputMixin):
|
class DictInput(BaseInputMixin, ListableInputMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.DICT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.DICT
|
||||||
|
value: Optional[dict] = {}
|
||||||
|
|
||||||
|
|
||||||
class DropdownInput(BaseInputMixin, DropDownMixin):
|
class DropdownInput(BaseInputMixin, DropDownMixin):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue