Skip to content

Commit

Permalink
refactor: Improve error messaging for missing message fields in memor…
Browse files Browse the repository at this point in the history
…y module (#4779)

* Improve error messaging for missing message fields in memory module

* fix: Simplify return statement in NotDiamondComponent's chat result method

* Update .gitignore to exclude all .db files
  • Loading branch information
ogabrielluiz authored Nov 23, 2024
1 parent 1120915 commit e61fb96
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,4 @@ src/frontend/temp
.history

.dspy_cache/
cache.db
*.db
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ def model_select(self) -> Message:
return self._call_get_chat_result(chosen_model, input_value, system_message)

def _call_get_chat_result(self, chosen_model, input_value, system_message):
result = get_chat_result(
return get_chat_result(
runnable=chosen_model,
input_value=input_value,
system_message=system_message,
)
return result

def _format_input(
self,
Expand Down
16 changes: 14 additions & 2 deletions src/backend/base/langflow/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from langflow.schema.message import Message
from langflow.services.database.models.message.model import MessageRead, MessageTable
from langflow.services.deps import session_scope
from langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_USER


def get_messages(
Expand Down Expand Up @@ -162,8 +163,19 @@ def store_message(
logger.warning("No message provided.")
return []

if not message.session_id or not message.sender or not message.sender_name:
msg = "All of session_id, sender, and sender_name must be provided."
required_fields = ["session_id", "sender", "sender_name"]
missing_fields = [field for field in required_fields if not getattr(message, field)]
if missing_fields:
missing_descriptions = {
"session_id": "session_id (unique conversation identifier)",
"sender": f"sender (e.g., '{MESSAGE_SENDER_USER}' or '{MESSAGE_SENDER_AI}')",
"sender_name": "sender_name (display name, e.g., 'User' or 'Assistant')",
}
missing = ", ".join(missing_descriptions[field] for field in missing_fields)
msg = (
f"It looks like we're missing some important information: {missing}. "
"Please ensure that your message includes all the required fields."
)
raise ValueError(msg)
if hasattr(message, "id") and message.id:
return update_messages([message])
Expand Down

0 comments on commit e61fb96

Please sign in to comment.