refactor: Update langflow custom imports and base classes

This commit updates the langflow custom imports and base classes in the code. It adds the "Component" import and base class to the langflow custom __init__.py file. It also updates the langflow template __init__.py file to include the "Input", "Output", "FrontendNode", and "Template" imports and base classes. Additionally, it modifies the langflow base ChatComponent class to inherit from the Component class. These changes improve the organization and functionality of the langflow custom and template modules.

Note: The commit message has been generated based on the provided code changes and recent commits.
This commit is contained in:
ogabrielluiz 2024-06-02 20:35:59 -03:00
commit 7fb5644a87
18 changed files with 6760 additions and 6719 deletions

View file

@ -1,8 +1,7 @@
from typing import Optional, Union
from langflow.base.io.chat import ChatComponent
from langflow.field_typing import Text
from langflow.schema import Record
from langflow.template import Input, Output
class ChatInput(ChatComponent):
@ -10,28 +9,32 @@ class ChatInput(ChatComponent):
description = "Get chat inputs from the Playground."
icon = "ChatInput"
def build_config(self):
build_config = super().build_config()
build_config["input_value"] = {
"input_types": [],
"display_name": "Message",
"multiline": True,
}
inputs = [
Input(name="input_value", type=str, display_name="Message", multiline=True, input_types=[]),
Input(name="sender", type=str, display_name="Sender Type", options=["Machine", "User"]),
Input(name="sender_name", type=str, display_name="Sender Name"),
Input(name="session_id", type=str, display_name="Session ID"),
]
outputs = [
Output(name="Message", method="text_response"),
Output(name="Record", method="record_response"),
]
return build_config
def text_response(self) -> Text:
result = self.message
if self.session_id and isinstance(result, (Record, str)):
self.store_message(result, self.session_id, self.sender, self.sender_name)
return result
def build(
self,
sender: Optional[str] = "User",
sender_name: Optional[str] = "User",
input_value: Optional[str] = None,
session_id: Optional[str] = None,
return_record: Optional[bool] = False,
) -> Union[Text, Record]:
return super().build_no_record(
sender=sender,
sender_name=sender_name,
input_value=input_value,
session_id=session_id,
return_record=return_record,
def record_response(self) -> Record:
record = Record(
data={
"message": self.message,
"sender": self.sender,
"sender_name": self.sender_name,
"session_id": self.session_id,
}
)
if self.session_id and isinstance(record, (Record, str)):
self.store_message(record, self.session_id, self.sender, self.sender_name)
return record