Skip to content

Commit

Permalink
Update .gitignore and refactor ChatInput and ChatOutput (#2140)
Browse files Browse the repository at this point in the history
This pull request includes two changes. First, the `.gitignore` file is
updated to include `*.db-shm` and `*.db-wal` files. Second, the
`ChatInput` and `ChatOutput` classes are refactored to include a new
`return_message` parameter. This parameter allows the caller to specify
whether they want the message to be returned as a `Message` object or
just the message text. These changes improve the functionality and
maintainability of the code.
  • Loading branch information
ogabrielluiz authored Jun 11, 2024
2 parents f7b1040 + d92cc3b commit 6716a90
Show file tree
Hide file tree
Showing 11 changed files with 886 additions and 251 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,5 @@ stuff/*
src/frontend/playwright-report/index.html
*.bak
prof/*
.langchain.db-shm
.langchain.db-wal
langflow.db-shm
langflow.db-wal
*.db-shm
*.db-wal
16 changes: 11 additions & 5 deletions src/backend/base/langflow/base/io/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def build_config(self):
"info": "If provided, the message will be stored in the memory.",
"advanced": True,
},
"return_record": {
"display_name": "Return Record",
"info": "Return the message as a record containing the sender, sender_name, and session_id.",
"return_message": {
"display_name": "Return Message",
"info": "Return the message as a Message containing the sender, sender_name, and session_id.",
"advanced": True,
},
"record_template": {
Expand Down Expand Up @@ -68,6 +68,7 @@ def build_with_record(
input_value: Optional[Union[str, Record, Message]] = None,
files: Optional[list[str]] = None,
session_id: Optional[str] = None,
return_message: Optional[bool] = False,
) -> Message:
message: Message | None = None

Expand All @@ -78,7 +79,12 @@ def build_with_record(
message = Message(
text=input_value, sender=sender, sender_name=sender_name, files=files, session_id=session_id
)
self.status = message
if not return_message:
message_text = message.text
else:
message_text = message

self.status = message_text
if session_id and isinstance(message, Message) and isinstance(message.text, str):
self.store_message(message)
return message
return message_text
2 changes: 2 additions & 0 deletions src/backend/base/langflow/components/inputs/ChatInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def build(
input_value: Optional[str] = None,
files: Optional[list[str]] = None,
session_id: Optional[str] = None,
return_message: Optional[bool] = False,
) -> Union[Message, Text]:
return super().build_with_record(
sender=sender,
sender_name=sender_name,
input_value=input_value,
files=files,
session_id=session_id,
return_message=return_message,
)
7 changes: 5 additions & 2 deletions src/backend/base/langflow/components/outputs/ChatOutput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from typing import Optional, Union

from langflow.base.io.chat import ChatComponent
from langflow.field_typing import Text
from langflow.schema.message import Message


Expand All @@ -16,11 +17,13 @@ def build(
input_value: Optional[str] = None,
session_id: Optional[str] = None,
files: Optional[list[str]] = None,
) -> Message:
return_message: Optional[bool] = False,
) -> Union[Message, Text]:
return super().build_with_record(
sender=sender,
sender_name=sender_name,
input_value=input_value,
session_id=session_id,
files=files,
return_message=return_message,
)
Loading

0 comments on commit 6716a90

Please sign in to comment.