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

Asad/aside with react #416

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 21 additions & 2 deletions src/ol_openedx_chat/block.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import pkg_resources
from django.template import Context, Template
from web_fragments.fragment import Fragment
from xblock.core import XBlockAside
from xblock.core import XBlockAside, XBlock
from webob.response import Response

from xmodule.video_block.transcripts_utils import get_transcript_from_contentstore
import openai

openai.api_key = "<API_KEY"

BLOCK_PROBLEM_CATEGORY = "problem"
MULTIPLE_CHOICE_TYPE = "multiplechoiceresponse"
Expand Down Expand Up @@ -42,9 +48,19 @@ def student_view_aside(self, block, context=None): # noqa: ARG002
Renders the aside contents for the student view
""" # noqa: D401
fragment = Fragment("")
fragment.add_content(render_template("static/html/student_view.html"))
fragment.add_content(render_template("static/html/student_view.html", {"block_key": self.scope_ids.usage_id.usage_key.block_id}))
fragment.add_javascript(get_resource_bytes("static/js/ai_chat.js"))
fragment.initialize_js('initReactXBlock8StudentView')
return fragment

@XBlock.handler
def mock_handler(self, request=None, suffix=None):
print("\n\n\n")
print(request.POST)
print(suffix)
print("\n\n\n")
return Response(json_body={"message": "Hello, This your MIT Teaching Assistant. (A Server message)"})

@XBlockAside.aside_for("author_view")
def author_view_aside(self, block, context=None): # noqa: ARG002
"""
Expand All @@ -64,6 +80,9 @@ def should_apply_to_block(cls, block):
instances, the problem type of the given block needs to be retrieved in
different ways.
""" # noqa: D401
if getattr(block, "category", None) == 'video':
return True

if getattr(block, "category", None) != BLOCK_PROBLEM_CATEGORY:
return False
block_problem_types = None
Expand Down
Loading
Loading