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

PADV 1684 - Add feature flag for LLM summarize for frontend #136

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lms/djangoapps/edxnotes/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from django.conf import settings
from xblock.exceptions import NoSuchServiceError
from openedx.core.djangoapps.plugins.plugins_hooks import run_extension_point

from common.djangoapps.edxmako.shortcuts import render_to_string
from common.djangoapps.student.auth import is_ccx_course
Expand Down Expand Up @@ -50,6 +51,8 @@ def get_html(self, *args, **kwargs):
except NoSuchServiceError:
user = None

is_llm_summarize_enabled = run_extension_point('PEARSON_CORE_ENABLE_LLM_SUMMARIZE', course_id=str(course.id))

if is_studio or not is_feature_enabled(course, user):
return original_get_html(self, *args, **kwargs)
else:
Expand All @@ -69,6 +72,10 @@ def get_html(self, *args, **kwargs):
"endpoint": get_public_endpoint(),
"debug": settings.DEBUG,
"eventStringLimit": settings.TRACK_MAX_EVENT / 6,
"llmSummarize": {
"isEnabled": is_llm_summarize_enabled,
"courseId": str(course.id),
},
},
})

Expand Down
9 changes: 5 additions & 4 deletions lms/static/js/edxnotes/plugins/llm_summarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@
let annotator = this.annotator;
document.head.appendChild(style);
this.modifyDom(this.annotator);

annotator.editor.options.llmSummarize = annotator.options.llmSummarize
const summarizeButton = document.getElementById('summarizeButton');

summarizeButton.addEventListener('click', function(ev) {
annotator.editor.element[0].setAttribute('is_summarizing', true);
annotator.editor.options.isSummarizing = true;
});
annotator.subscribe('annotationEditorShown', this.handleSummarize);
annotator.subscribe('annotationEditorHidden', this.cleanupSummarize);
},
handleSummarize: function (editor, annotation) {
if (editor.element[0].getAttribute('is_summarizing') !== 'true') return;
if (!editor.options || !editor.options.isSummarizing) return;

function toggleLoader() {
const saveButton = document.querySelector('.annotator-controls .annotator-save');
Expand All @@ -115,6 +115,7 @@
},
body: JSON.stringify({
text_to_summarize: annotation.quote,
course_id: editor.options && editor.options.llmSummarize && editor.options.llmSummarize.courseId,
}),
});

Expand All @@ -140,7 +141,7 @@

textAreaWrapper.children[0].value = '';
textAreaWrapper.children[1].value = '';
editor.element[0].setAttribute('is_summarizing', 'false');
editor.options.isSummarizing = false;
loaderWrapper.classList.add('d-none');
},
modifyDom: function(annotator) {
Expand Down
9 changes: 8 additions & 1 deletion lms/static/js/edxnotes/views/notes_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
destroy: '/annotations/:id/',
search: '/search/'
}
}
},
llmSummarize: {
isEnabled: params && params.llmSummarize && params.llmSummarize.isEnabled,
courseId: params && params.llmSummarize && params.llmSummarize.courseId,
},
};
};

Expand Down Expand Up @@ -85,6 +89,9 @@
logger = NotesLogger.getLogger(element.id, params.debug),
annotator;

if (options && options.llmSummarize && options.llmSummarize.isEnabled) {
plugins.push('LlmSummarize');
}
annotator = $el.annotator(options).data('annotator');
setupPlugins(annotator, plugins, options);
NotesCollector.storeNotesRequestData(
Expand Down
Loading