Refactor ChatInput and ChatOutput classes to remove 'as_record' parameter
This commit is contained in:
parent
160aa47e26
commit
3f9790a420
2 changed files with 17 additions and 33 deletions
|
|
@ -25,10 +25,6 @@ class ChatInput(CustomComponent):
|
||||||
"display_name": "Session ID",
|
"display_name": "Session ID",
|
||||||
"info": "Session ID of the chat history.",
|
"info": "Session ID of the chat history.",
|
||||||
},
|
},
|
||||||
"as_record": {
|
|
||||||
"display_name": "As Record",
|
|
||||||
"info": "If true, the message will be returned as a Record.",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
|
|
@ -36,18 +32,15 @@ class ChatInput(CustomComponent):
|
||||||
sender: Optional[str] = "User",
|
sender: Optional[str] = "User",
|
||||||
sender_name: Optional[str] = "User",
|
sender_name: Optional[str] = "User",
|
||||||
message: Optional[str] = None,
|
message: Optional[str] = None,
|
||||||
as_record: Optional[bool] = False,
|
|
||||||
session_id: Optional[str] = None,
|
session_id: Optional[str] = None,
|
||||||
) -> Union[Text, Record]:
|
) -> Record:
|
||||||
self.status = message
|
|
||||||
if as_record:
|
|
||||||
if isinstance(message, Record):
|
if isinstance(message, Record):
|
||||||
# Update the data of the record
|
# Update the data of the record
|
||||||
message.data["sender"] = sender
|
message.data["sender"] = sender
|
||||||
message.data["sender_name"] = sender_name
|
message.data["sender_name"] = sender_name
|
||||||
message.data["session_id"] = session_id
|
message.data["session_id"] = session_id
|
||||||
return message
|
else:
|
||||||
return Record(
|
message = Record(
|
||||||
text=message,
|
text=message,
|
||||||
data={
|
data={
|
||||||
"sender": sender,
|
"sender": sender,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from typing import Optional, Union
|
from typing import Optional
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.field_typing import Text
|
|
||||||
from langflow.schema import Record
|
from langflow.schema import Record
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,10 +27,6 @@ class ChatOutput(CustomComponent):
|
||||||
"info": "Session ID of the chat history.",
|
"info": "Session ID of the chat history.",
|
||||||
"input_types": ["Text"],
|
"input_types": ["Text"],
|
||||||
},
|
},
|
||||||
"as_record": {
|
|
||||||
"display_name": "As Record",
|
|
||||||
"info": "If true, the message will be returned as a Record.",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
|
|
@ -40,18 +35,14 @@ class ChatOutput(CustomComponent):
|
||||||
sender_name: Optional[str] = "AI",
|
sender_name: Optional[str] = "AI",
|
||||||
session_id: Optional[str] = None,
|
session_id: Optional[str] = None,
|
||||||
message: Optional[str] = None,
|
message: Optional[str] = None,
|
||||||
as_record: Optional[bool] = False,
|
) -> Record:
|
||||||
) -> Union[Text, Record]:
|
|
||||||
self.status = message
|
|
||||||
if as_record:
|
|
||||||
if isinstance(message, Record):
|
if isinstance(message, Record):
|
||||||
# Update the data of the record
|
# Update the data of the record
|
||||||
message.data["sender"] = sender
|
message.data["sender"] = sender
|
||||||
message.data["sender_name"] = sender_name
|
message.data["sender_name"] = sender_name
|
||||||
message.data["session_id"] = session_id
|
message.data["session_id"] = session_id
|
||||||
|
else:
|
||||||
return message
|
message = Record(
|
||||||
return Record(
|
|
||||||
text=message,
|
text=message,
|
||||||
data={
|
data={
|
||||||
"sender": sender,
|
"sender": sender,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue