Skip to content

Feature/sc 41194/ research this and cost it configure and3#73

Open
stevekaplan123 wants to merge 20 commits intomainfrom
feature/sc-41194/-research-this-and-cost-it-configure-and3
Open

Feature/sc 41194/ research this and cost it configure and3#73
stevekaplan123 wants to merge 20 commits intomainfrom
feature/sc-41194/-research-this-and-cost-it-configure-and3

Conversation

@stevekaplan123
Copy link
Contributor

@stevekaplan123 stevekaplan123 commented Mar 12, 2026

This PR adds conversation turn limits and adds a setting to prohibit excessive prompt sizes via MAX_INPUT_CHARS. Both maximum number of prompts and maximum number of characters per prompt can be set by admins in RemoteConfig. However, for security reasons, both of these values are now set in the chatbot's settings.py so that absolute maximums of 10,000 characters and 100 prompts prohibit users from abusing our system. Once the user hits the maximum, the server returns an error which is handled by the client to stop the user from continuing the conversation.

@stevekaplan123 stevekaplan123 requested a review from Copilot March 12, 2026 12:07
@coolify-sefaria-github
Copy link

coolify-sefaria-github bot commented Mar 12, 2026

The preview deployment for sefaria/ai-chatbot:server is ready. 🟢

Open app | Open Build Logs | Open Application Logs

Last updated at: 2026-03-19 07:12:46 CET

@stevekaplan123 stevekaplan123 review requested due to automatic review settings March 12, 2026 12:08
@stevekaplan123 stevekaplan123 changed the base branch from main to feature/sc-41912/welcome-experience-s March 12, 2026 12:08
@stevekaplan123 stevekaplan123 requested a review from Copilot March 12, 2026 12:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds conversation turn limits and localized welcome messages to the chatbot. It introduces server-side enforcement of maximum prompts per session and maximum input character length, with corresponding client-side handling to disable input when limits are reached. It also adds context-aware welcome messages (first visit, restart, new session) with English/Hebrew localization support.

Changes:

  • Server-side turn limit (MAX_PROMPTS) and input length (MAX_INPUT_CHARS) enforcement in the V2 streaming chat endpoint, with settings exposed via environment variables
  • Client-side turn counting, limit display, and input disabling when conversation limits are reached, including both prop-based and server-based limit configuration
  • Localized welcome messages with different text for first-time users, conversation restarts, and new sessions, supporting English and Hebrew

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
server/chatbot_server/settings.py Adds MAX_PROMPTS and MAX_INPUT_CHARS settings from environment variables
server/chat/V2/views.py Enforces turn limit (429) and input length (400) before processing chat requests; exposes maxPrompts in session info
server/chat/views.py Exposes maxPrompts in the history endpoint's session info
src/components/LCChatbot.svelte Adds client-side turn limit tracking, localized welcome messages, assistant bubble snippet, smaller default panel size
src/lib/storage.js Adds HAS_USED storage key for first-time user detection
src/CLAUDE.md Documents the new max-prompts widget attribute

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-41912/welcome-experience-s to main March 12, 2026 13:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@stevekaplan123 stevekaplan123 marked this pull request as ready for review March 15, 2026 13:41
Copy link
Contributor

@yodem yodem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: SC-41194 — Conversation Turn Limit (ai-chatbot side)

The turn limit implementation is solid overall — server-side enforcement with MAX_PROMPTS and MAX_INPUT_CHARS in settings, 429 response code, and client-side sync of limits. A few issues to address below.

});

// Sync turn limits from server on load
$effect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving syncSessionState() from the explicit openPanel() call into an $effect block means it will re-fire whenever any of sessionId, apiBaseUrl, or isOpen changes reactively. If sessionId is reassigned during chat flow (e.g., after handleNewChat), this could trigger an extra sync.

Not necessarily a bug, but worth verifying it doesn't cause duplicate API calls. The previous approach of calling sync explicitly on panel open was more predictable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, when the user reset the page, and the chat was already open, the session state wouldn't sync and turn_count would be 0 allowing for longer conversations. So this change is mostly a good thing. However, you're right that there is an unnecessary API call when someone restarts the chat. I will change the code accordingly to prevent that.

@stevekaplan123 stevekaplan123 requested a review from yodem March 19, 2026 07:13
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.

3 participants