Skip to content

Feature/sc 41194/ research this and cost it configure and#3139

Draft
stevekaplan123 wants to merge 18 commits intomasterfrom
feature/sc-41194/-research-this-and-cost-it-configure-and
Draft

Feature/sc 41194/ research this and cost it configure and#3139
stevekaplan123 wants to merge 18 commits intomasterfrom
feature/sc-41194/-research-this-and-cost-it-configure-and

Conversation

@stevekaplan123
Copy link
Contributor

Description

A brief description of the PR

Code Changes

The following changes were made to the files below

Notes

Any additional notes go here

@mergify
Copy link

mergify bot commented Mar 9, 2026

🧪 CI Insights

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

🟢 All jobs passed!

But CI Insights is watching 👀

…41194/-research-this-and-cost-it-configure-and
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 extends the ReaderApp chatbot integration by adding new configuration props (max prompts, welcome messages, interface language) and introducing a dedicated Django chatbot app to store editable welcome/restart text via the admin.

Changes:

  • Add a new Django chatbot app with ChatbotWelcomeMessage model, admin UI, migrations, and tests.
  • Extend base_props and ReaderApp.jsx to pass max-prompts, welcome-messages, and interface-lang into the <lc-chatbot> custom element.
  • Add a new remote-config key for feature.chatbot.max_prompts and enable the chatbot app in Django settings.

Reviewed changes

Copilot reviewed 12 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
static/js/ReaderApp.jsx Passes additional chatbot attributes to the <lc-chatbot> element; relaxes display gating logic.
sefaria/settings.py Adds the new chatbot Django app to INSTALLED_APPS.
remote_config/keys.py Adds CHATBOT_MAX_PROMPTS remote-config key constant.
reader/views.py Adds chatbot props (chatbot_max_prompts, chatbot_welcome_messages) to base_props.
reader/migrations/0002_add_chatbot_welcome_message.py Introduces a temporary reader-owned welcome message model (later reverted).
reader/migrations/0003_revert_chatbot_welcome_message.py Deletes the temporary reader-owned welcome message model.
chatbot/models.py Implements ChatbotWelcomeMessage and cached get_chatbot_welcome_messages().
chatbot/admin.py Registers ChatbotWelcomeMessage with preview fields in Django admin.
chatbot/apps.py Adds ChatbotConfig for the new app.
chatbot/migrations/0001_initial.py Creates the ChatbotWelcomeMessage table and inserts a default record.
chatbot/migrations/0002_add_new_session_message.py Adds new_session_* fields to the welcome message model.
chatbot/tests/test_chatbot_welcome_message.py Adds tests for default and DB-backed welcome message behavior.

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

Comment on lines 355 to 362
chatbot_data = {
"chatbot_user_token": None,
"chatbot_enabled": False,
"chatbot_api_base_url": CHATBOT_API_BASE_URL,
'chatbot_max_input_chars': remoteConfigCache.get(CHATBOT_MAX_INPUT_CHARS, default=500),
'chatbot_max_prompts': remoteConfigCache.get(CHATBOT_MAX_PROMPTS, default=100),
'chatbot_welcome_messages': json.dumps(get_chatbot_welcome_messages()),
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

get_chatbot_welcome_messages() is called unconditionally when building base_props, which means every request pays at least a cache lookup (and a DB query on cache miss) even when the chatbot is disabled for the user. Consider only fetching/serializing welcome messages when _is_user_in_experiment(request) is true (or when chatbot_enabled will be true), since the <lc-chatbot> element is only rendered in that case anyway.

Copilot uses AI. Check for mistakes.
Comment on lines 146 to 155
INSTALLED_APPS = (
'adminsortable',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'reader',
'chatbot',
'django.contrib.staticfiles',
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

INSTALLED_APPS currently adds the chatbot app as 'chatbot', but this repo already uses explicit AppConfig paths for some apps (e.g. remote_config.apps.RemoteConfigConfig, django_topics.apps.DjangoTopicsAppConfig). To keep behavior consistent on Django 1.11 and ensure any future ChatbotConfig.ready()/metadata is applied, add it as 'chatbot.apps.ChatbotConfig' (or add default_app_config in chatbot/__init__.py).

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +6
class ChatbotConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "chatbot"
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

default_auto_field = "django.db.models.BigAutoField" is a Django 3.2+ setting and is unused on Django 1.11 (the version pinned in requirements.txt). Keeping it here can be misleading, especially since the migrations use AutoField; consider removing it (or documenting why it’s present) to avoid confusion.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +39
def create_default_welcome(apps, schema_editor):
ChatbotWelcomeMessage = apps.get_model("reader", "ChatbotWelcomeMessage")
ChatbotWelcomeMessage.objects.get_or_create(
key="default",
defaults={"welcome": "", "restart": ""},
)


class Migration(migrations.Migration):

dependencies = [
('reader', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='ChatbotWelcomeMessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('key', models.CharField(default='default', help_text="Identifier for this message set (e.g. 'default')", max_length=50, unique=True)),
('welcome', models.TextField(default='', help_text='Message shown when chat is empty (i.e. first-time)')),
('restart', models.TextField(default='', help_text='Message shown on restart button')),
('updated_at', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name': 'Chatbot welcome message',
'verbose_name_plural': 'Chatbot welcome messages',
'ordering': ['key'],
},
),
migrations.RunPython(create_default_welcome, migrations.RunPython.noop),
]
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

These two new reader migrations create ChatbotWelcomeMessage and then immediately delete it. Since the canonical model now lives in the new chatbot app, it would be cleaner to drop both reader migrations entirely (before merge) rather than shipping a create+drop sequence that adds noise to the migration history and performs unnecessary DDL on deploys.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +16
class Migration(migrations.Migration):

dependencies = [
('reader', '0002_add_chatbot_welcome_message'),
]

operations = [
migrations.DeleteModel(name='ChatbotWelcomeMessage'),
]
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

If reader/migrations/0002_add_chatbot_welcome_message.py is removed as suggested, this revert migration should also be removed. If there is a real need to keep a revert migration, consider renaming it to reflect the actual state transition (and add a data migration if existing installations have welcome message data that needs to be moved into the chatbot app).

Copilot uses AI. Check for mistakes.
Comment on lines 153 to 155
'reader',
'chatbot',
'django.contrib.staticfiles',
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The PR title/description are still the template/placeholder text and don’t describe the intent of these chatbot changes (new app, welcome messages, remote config for max prompts). Please update the PR description to match the actual behavior change so reviewers can validate the requirements and rollout expectations.

Copilot uses AI. Check for mistakes.
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.

2 participants