Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/backend/base/langflow/base/io/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def build_config(self):
},
}

# 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",
Expand Down
9 changes: 7 additions & 2 deletions src/backend/base/langflow/components/inputs/ChatInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,7 +66,12 @@ def message_response(self) -> Message:
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,
Expand Down
9 changes: 7 additions & 2 deletions src/backend/base/langflow/components/outputs/ChatOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,7 +57,12 @@ def message_response(self) -> Message:
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,
Expand Down
Loading