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

💬 feat: Temporary Chats #5493

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ohneda
Copy link
Contributor

@ohneda ohneda commented Jan 27, 2025

Summary

This PR introduces a "Temporary Chat" feature with the following characteristics:

  • Temporary Chats do not appear in the chat history in the side bar.
  • Temporary Chats are excluded from search results.
  • Temporary Chats cannot be bookmarked.
  • Temporary Chats are stored in the database for 30 days and then automatically deleted.

This feature basically follows ChatGPT's TemporaryChat specification.

SCR-20250127-bnsa

Implementation Details

  • Added an expiredAt property to both the Conversation and Message models.

  • Created a expireAfterSeconds index to leverage MongoDB's TTL (Time-To-Live) feature, which automatically deletes records after the specified time.

    • If expiredAt is null or not defined, the chat is considered non-temporary.
    • MongoDB's TTL feature is supported in MongoDB 2.x and later.
    • Reference: MongoDB TTL Documentation
  • Note: Currently, both Conversation and Message are set to expire 30 days after creation. This means that some Message records may temporarily become "orphaned" if their parent Conversation is deleted first. While setting the same expiredAt value for both models would ensure simultaneous deletion, this implementation prioritizes simplicity.

  • Added a temporaryChat property to the librechat.yaml configuration file under the interface section.

    • If set to false, the Temporary Chat toggle will not be displayed in the UI.
    • Default value is true.
  • The transactions model does not include the expiredAt property due to its specific role and behavior.

    • Since the transactions model is not deleted when its parent Conversation is removed (based on the current implementation), this decision is expected to have no adverse effects. However, if any issues arise, I will revisit and adjust the implementation to ensure data consistency.

Alternative Implementation Approaches

Other solutions, such as using Agenda.js or node-cron, were considered for more granular control over deletion logic. However, the current implementation using MongoDB's TTL feature was chosen for its simplicity.

Feedback and suggestions are welcome!

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

The following scenarios were manually verified:

  1. When Temporary Chat is enabled, the expiredAt property is correctly set for both Conversation and Message.
  2. When Temporary Chat is disabled, the expiredAt property is not set.
  3. Conversation and Message records with expiredAt are deleted after 30 days.
  4. The Bookmark button is hidden when Temporary Chat is enabled.
  5. The Bookmark button is displayed when Temporary Chat is disabled.
  6. Temporary Chats are excluded from search results.
  7. When librechat.yaml's interface.temporaryChat is set to false, the Temporary Chat toggle is not displayed in the UI.
  8. The Temporary Chat can only be set at the start of a chat and cannot be changed once the chat has begun.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes
  • A pull request for updating the documentation has been submitted.

ohneda added 11 commits January 26, 2025 09:27
Added `expiredAt` property to both Conversation and Message schemas.
Configured `expireAfterSeconds` index in MongoDB to automatically delete documents after a specified period.
…ort temporary chats

Added `isTemporary` property to TPayload and TSubmission for API calls for temporary chat.
Additionally, added `expiredAt` property to `tConversationSchema` to determine if a chat is temporary.
Add Recoil state for tracking temporary conversations, update event handlers to respect temporary chat status
- Added a Temporary Chat switch button at the end of dropdown lists in each model.
- Updated the form background color to black when Temporary Chat is enabled.
- Modified Navigation to exclude Temporary Chats from the chat list.
Updated the getConvosQueried query to ensure that Temporary Chats are not included in the search results.
Updated the UI to ensure that the bookmark button is not displayed when a chat is as Temporary Chat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant