Skip to content

Commit

Permalink
GPT and transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Nov 29, 2024
1 parent cb94286 commit 9190d9c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/ol_openedx_chat/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
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 @@ -43,7 +48,24 @@ def student_view_aside(self, block, context=None): # noqa: ARG002
Renders the aside contents for the student view
""" # noqa: D401
fragment = Fragment("")
breakpoint()
if getattr(block, "category", None) == "video":
content, filename, mimetype = get_transcript_from_contentstore(block, 'en', 'txt', block.get_transcripts_info())
prompt = (
"Summarize the following video transcript into a concise, informative summary:\n\n"
f"{content}"
)
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are an expert at summarizing content."},
{"role": "user", "content": prompt},
],
max_tokens=200,
temperature=0.5,
)
print("\n\n\n", response["choices"][0]["message"]["content"], "\n\n\n")
return fragment

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"))
Expand Down Expand Up @@ -77,6 +99,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
6 changes: 6 additions & 0 deletions src/ol_openedx_chat/static/html/student_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
</div>
</div>
</div>
<script
defer
id="ze-snippet"
type='application/javascript'
src="https://static.zdassets.com/ekr/snippet.js?key=8ef9ef96-3317-40a9-8ef6-de0737503caa"
></script>

0 comments on commit 9190d9c

Please sign in to comment.