Skip to content

Commit

Permalink
Merge pull request #136 from Pearson-Advance/vue/PADV-1684.re-opened
Browse files Browse the repository at this point in the history
PADV 1684 - Add feature flag for LLM summarize for frontend
  • Loading branch information
Serafin-dev authored Oct 15, 2024
2 parents 6debc75 + ba1191f commit cdba011
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit cdba011

Please sign in to comment.