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

feat: use AI Chat js bundle component #422

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
34 changes: 33 additions & 1 deletion src/ol_openedx_chat/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,40 @@ def student_view_aside(self, block, context=None):
if getattr(self.runtime, "is_author_mode", False):
return self.author_view_aside(block, context)

# if not self.enabled:
# return Fragment("")

if getattr(block, "category", None) == "video":
# content, filename, mimetype = get_transcript_from_contentstore(block, 'en', 'txt', block.get_transcripts_info())
pass

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_css(get_resource_bytes("static/css/ai_chat.css"))
fragment.add_javascript(get_resource_bytes("static/js/ai_chat.js"))
# We can either keep the JS file in the static folder or load it from the CDN here or in the template
# fragment.add_javascript(get_resource_bytes("static/js/aiChat.umd.js"))
fragment.add_javascript_url(
"https://unpkg.com/@mitodl/[email protected]/dist/bundles/aiChat.umd.js"
)
starters = (
[{"content": prompt} for prompt in self.chat_prompts.split(",")]
if self.chat_prompts
else []
)
fragment.initialize_js(
"AiChatAsideView",
json_args={
"starters": starters,
"block_usage_key": self.scope_ids.usage_id,
"user_id": self.runtime.user_id,
},
)
return fragment

@XBlockAside.aside_for(AUTHOR_VIEW)
Expand Down
14 changes: 14 additions & 0 deletions src/ol_openedx_chat/static/css/ai_chat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* General Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}



#app-root {
width: 450px;
height: 600px;
}
3 changes: 2 additions & 1 deletion src/ol_openedx_chat/static/html/student_view.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!--?<script src="https://unpkg.com/@mitodl/[email protected]/dist/bundles/aiChat.umd.js"></script>-->
<div>
<button type="button" onclick="alert('Hello World!')">Hello World!</button>
<div id="app-root">Hello</div>
</div>
Loading
Loading