fix: update chat components to make them backwards compatible (#2725)

* feat: Add conditional check for storing message in ChatOutput

* refactor: Update store_message method in ChatComponent for backward compatibility

* refactor: update input name to not collide with method name
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-16 11:19:53 -03:00 committed by GitHub
commit 7d3fac6f10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 4 deletions

View file

@ -49,6 +49,19 @@ class ChatComponent(Component):
},
}
# Keep this method for backward compatibility
def store_message(
self,
message: Message,
) -> list[Message]:
messages = store_message(
message,
flow_id=self.graph.flow_id,
)
self.status = messages
return messages
def build_with_data(
self,
sender: Optional[str] = "User",

View file

@ -20,7 +20,7 @@ class ChatInput(ChatComponent):
info="Message to be passed as input.",
),
BoolInput(
name="store_message",
name="should_store_message",
display_name="Store Messages",
info="Store the message in the history.",
value=True,
@ -66,7 +66,12 @@ class ChatInput(ChatComponent):
files=self.files,
)
if self.session_id and isinstance(message, Message) and isinstance(message.text, str):
if (
self.session_id
and isinstance(message, Message)
and isinstance(message.text, str)
and self.should_store_message
):
store_message(
message,
flow_id=self.graph.flow_id,

View file

@ -18,7 +18,7 @@ class ChatOutput(ChatComponent):
info="Message to be passed as output.",
),
BoolInput(
name="store_message",
name="should_store_message",
display_name="Store Messages",
info="Store the message in the history.",
value=True,
@ -57,7 +57,12 @@ class ChatOutput(ChatComponent):
sender_name=self.sender_name,
session_id=self.session_id,
)
if self.session_id and isinstance(message, Message) and isinstance(message.text, str):
if (
self.session_id
and isinstance(message, Message)
and isinstance(message.text, str)
and self.should_store_message
):
store_message(
message,
flow_id=self.graph.flow_id,