Skip to content

Conversation

@stevekaplan123
Copy link
Contributor

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

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

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_token context processor with a default fallback.
  • Passes the value into the chatbot web component via max-input-chars on templates/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.

Comment on lines +132 to 138
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,
}
Copy link

Copilot AI Feb 10, 2026

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.

Suggested change
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,
}

Copilot uses AI. Check for mistakes.
@mergify
Copy link

mergify bot commented Feb 10, 2026

🧪 CI Insights

Here's what we observed from your CI run for eddd8d6.

🟢 All jobs passed!

But CI Insights is watching 👀

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