Skip to content

Commit

Permalink
feat: add asset ID for the video transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Mar 3, 2025
1 parent 338c22d commit 8953e5e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/ol_openedx_chat/block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pkg_resources
from django.conf import settings
from django.template import Context, Template
Expand All @@ -12,6 +14,8 @@

from .compat import get_ol_openedx_chat_enabled_flag

log = logging.getLogger(__name__)


def get_resource_bytes(path):
"""
Expand Down Expand Up @@ -54,6 +58,7 @@ def student_view_aside(self, block, context=None):
"""
Renders the aside contents for the student view
""" # noqa: D401
from xmodule.video_block.transcripts_utils import Transcript

# This is a workaround for those blocks which do not have has_author_view=True
# because when a block does not define has_author_view=True in it, the only view
Expand All @@ -78,10 +83,29 @@ def student_view_aside(self, block, context=None):
)
fragment.add_css(get_resource_bytes("static/css/ai_chat.css"))
fragment.add_javascript(get_resource_bytes("static/js/ai_chat.js"))

transcript_asset_id = None
if getattr(block, "category", None) == "video":
try:
transcripts_info = block.get_transcripts_info()
if transcripts_info.get("transcripts") and transcripts_info[
"transcripts"
].get("en"):
transcript_asset_id = Transcript.asset_location(
block.location, transcripts_info["transcripts"]["en"]
)

except Exception:
log.exception(
"Error while fetching transcripts for block %s",
block.location,
)

extra_context = {
"ask_tim_drawer_title": f"about {block.display_name}",
"block_id": self.scope_ids.usage_id.usage_key.block_id,
"block_usage_key": self.scope_ids.usage_id.usage_key,
"transcript_asset_id": transcript_asset_id,
"user_id": self.runtime.user_id,
"learn_ai_api_url": settings.LEARN_AI_API_URL,
"learning_mfe_base_url": settings.LEARNING_MICROFRONTEND_URL,
Expand Down
4 changes: 3 additions & 1 deletion src/ol_openedx_chat/static/js/ai_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
$(`#chat-button-${init_args.block_id}`).on("click", {
askTimTitle: init_args.ask_tim_drawer_title,
blockUsageKey: init_args.block_usage_key,
blockID: init_args.block_id
blockID: init_args.block_id,
transcriptAssetID: init_args.transcript_asset_id
}, function (event) {

window.parent.postMessage(
Expand All @@ -25,6 +26,7 @@
initialMessages: INITIAL_MESSAGES,
blockID: event.data.blockID,
blockUsageKey: event.data.blockUsageKey,
transcriptAssetID: event.data.transcriptAssetID,
},
},
init_args.learning_mfe_base_url, // Ensure correct parent origin
Expand Down

0 comments on commit 8953e5e

Please sign in to comment.