-
-
Notifications
You must be signed in to change notification settings - Fork 311
chore: add remote config for max input chars #3083
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
base: wip-chatbot
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds a Remote Config-controlled setting to dynamically control the AI chatbot’s maximum input length (defaulting to 500 when unset), and wires it through Django template context into the <lc-chatbot> element.
Changes:
- Introduces a new Remote Config key
feature.chatbot.max_input_chars. - Reads the key in the
chatbot_user_tokencontext processor with a default fallback. - Passes the value into the chatbot web component via
max-input-charsontemplates/base.html.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
templates/base.html |
Adds max-input-chars attribute to the <lc-chatbot> element. |
sefaria/system/context_processors.py |
Fetches max input chars from remoteConfigCache and exposes it to templates. |
remote_config/keys.py |
Adds CHATBOT_MAX_INPUT_CHARS constant for the new Remote Config key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| max_input_chars = remoteConfigCache.get(CHATBOT_MAX_INPUT_CHARS, default=500) | ||
| return { | ||
| "chatbot_user_token": token, | ||
| "chatbot_enabled": True, | ||
| "chatbot_api_base_url": settings.CHATBOT_API_BASE_URL, | ||
| "chatbot_max_input_chars": max_input_chars, | ||
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remoteConfigCache.get() can return non-int values (e.g., if the admin creates this key with value_type=string, which is the model default). Since max-input-chars is presumably consumed as a number by the chatbot widget, this can lead to broken/bypassed limits or runtime errors. Consider coercing to int with a safe fallback to 500, and clamp to a reasonable min/max (e.g., >=1 and an upper bound) to avoid misconfiguration causing excessive client payloads/costs.
| max_input_chars = remoteConfigCache.get(CHATBOT_MAX_INPUT_CHARS, default=500) | |
| return { | |
| "chatbot_user_token": token, | |
| "chatbot_enabled": True, | |
| "chatbot_api_base_url": settings.CHATBOT_API_BASE_URL, | |
| "chatbot_max_input_chars": max_input_chars, | |
| } | |
| # Safely coerce remote config value to int with sane defaults and bounds | |
| raw_max_input_chars = remoteConfigCache.get(CHATBOT_MAX_INPUT_CHARS, default=500) | |
| default_max_input_chars = 500 | |
| min_max_input_chars = 1 | |
| max_max_input_chars = 20000 | |
| try: | |
| max_input_chars = int(raw_max_input_chars) | |
| except (TypeError, ValueError): | |
| max_input_chars = default_max_input_chars | |
| else: | |
| if max_input_chars < min_max_input_chars: | |
| max_input_chars = min_max_input_chars | |
| elif max_input_chars > max_max_input_chars: | |
| max_input_chars = max_max_input_chars | |
| return: | |
| { | |
| "chatbot_user_token": token, | |
| "chatbot_enabled": True, | |
| "chatbot_api_base_url": settings.CHATBOT_API_BASE_URL, | |
| "chatbot_max_input_chars": max_input_chars, | |
| } |
🧪 CI InsightsHere's what we observed from your CI run for eddd8d6. 🟢 All jobs passed!But CI Insights is watching 👀 |
Description
This PR allows admins to change the number of maximum input characters in the AI chatbot so that we can easily change this on-the-go in the future. It defaults to 500 characters if the key hasn't been added to RemoteConfig in Django Admin