refactor: Update ChatInput and ChatOutput to handle Message input

Update the ChatInput and ChatOutput components in ChatInput.py and ChatOutput.py to handle Message input. If the input value is an instance of the Message class, extract the text attribute and use it as the input value. This change ensures compatibility with the langflow schema and improves the flexibility of the components.
This commit is contained in:
ogabrielluiz 2024-06-13 00:16:44 -03:00
commit f823d5ccf7
3 changed files with 10 additions and 10 deletions

View file

@ -49,7 +49,7 @@ class ChatInput(ChatComponent):
sender_name=self.sender_name,
session_id=self.session_id,
)
if self.session_id and isinstance(message, (Message, str)):
if self.session_id and isinstance(message, (Message, str)) and isinstance(message.text, str):
self.store_message(message)
self.status = message
return message

View file

@ -39,12 +39,15 @@ class ChatOutput(ChatComponent):
]
def message_response(self) -> Message:
message = Message(
text=self.input_value,
sender=self.sender,
sender_name=self.sender_name,
session_id=self.session_id,
)
if isinstance(self.input_value, Message):
message = self.input_value
else:
message = Message(
text=self.input_value,
sender=self.sender,
sender_name=self.sender_name,
session_id=self.session_id,
)
if self.session_id and isinstance(message, Message) and isinstance(message.text, str):
self.store_message(message)
self.status = message

View file

@ -23,9 +23,6 @@ def build_logs_from_artifacts(artifacts: dict) -> dict:
message = artifacts[key]["raw"]
_type = artifacts[key]["type"]
if not isinstance(message, dict):
message = {"message": message}
if "stream_url" in message and "type" in message:
stream_url = StreamURL(location=message["stream_url"])
log = Log(message=stream_url, type=_type)