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: AI Chat drawer #422

Merged
merged 16 commits into from
Feb 21, 2025
Merged

feat: AI Chat drawer #422

merged 16 commits into from
Feb 21, 2025

Conversation

asadali145
Copy link
Contributor

@asadali145 asadali145 commented Jan 8, 2025

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/6514

Description (What does it do?)

Adds chat AI button when it is enabled for a problem or a video block. Also, fixes an issue with the Aside field naming + adds a new field for the drawer title.

Screenshots (if appropriate):

Desktop Non-Staff User Desktop Staff User
desktop-normal desktop-staff
Tablet Non-Staff User Tablet Staff User
tablet-normal tablet-staff
Mobile Non-Staff User Mobile Staff User
mobile-normal mobile-staff

How can this be tested?

  • Generate package by checking out this branch and running pants package :: .
  • Enable xBlock configurations in CMS <STUDIO_URL>/admin/xblock_config/studioconfig/
  • Enable xBlock asides in LMS <LMS_URL>/admin/lms_xblock/xblockasidesconfig/
  • Install the ol-openedx-chat in LMS and CMS, Reload them
  • In frontend-app-learning:
    • Create env.config.jsx and add the below code:
import * as remoteAiChatDrawer from "./mitodl-smoot-design/dist/bundles/remoteAiChatDrawer.umd.js"

remoteAiChatDrawer.init({
  messageOrigin: "http://local.openedx.io:8000",
  transformBody: messages => ({ message: messages[messages.length - 1].content }),
})

const config = {
  ...process.env,
};

export default config;
  • Now run the below in the shell inside the learning MFE folder:
  • npm pack @mitodl/smoot-design@3.4.0
  • tar -xvzf mitodl-smoot-design-3.4.0.tgz
  • mv package mitodl-smoot-design
  • Now start learning MFE by npm run dev
  • Visit the CMS and enable the chat for a few problem and video blocks.
  • Visit LMS and you should see the button for AI Chat drawer and clicking on the button should open a drawer.
  • To communicate with the LEARN AI backend, you can add the API URL in LMS private.py: LEARN_AI_API_URL = "http://ai.open.odl.local:8002/http/recommendation_agent/"

@asadali145 asadali145 changed the title feat: AI Chat js bundle component feat: use AI Chat js bundle component Jan 8, 2025
@asadali145 asadali145 changed the base branch from asad/basic-lms-chat-v2 to main January 15, 2025 12:12
@asadali145 asadali145 force-pushed the asad/smoot-js-bundle branch 5 times, most recently from c14e729 to 6531a8a Compare January 17, 2025 12:45
@pdpinch
Copy link
Member

pdpinch commented Jan 17, 2025

will this close https://github.com/mitodl/hq/issues/6514

@asadali145
Copy link
Contributor Author

will this close mitodl/hq#6514

Yes, It will. I can add the issue in the PR description.

@asadali145 asadali145 force-pushed the asad/smoot-js-bundle branch from eda4f72 to f8383d8 Compare January 21, 2025 07:37
@asadali145 asadali145 force-pushed the asad/smoot-js-bundle branch 3 times, most recently from 78a02d6 to 3745128 Compare February 14, 2025 15:58
@asadali145 asadali145 force-pushed the asad/smoot-js-bundle branch 2 times, most recently from 2aec05b to 3b39b6f Compare February 19, 2025 13:22
@asadali145 asadali145 marked this pull request as ready for review February 20, 2025 14:51
conversationStarters: starters,
},
},
"http://apps.local.openedx.io:2000", // Ensure correct parent origin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an env var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, Let me fix this.

Copy link

@ChristopherChudzicki ChristopherChudzicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Tested a few problems using LEARN_AI_API_URL="http://ai.open.odl.local:8002/http/recommendation_agent/"

One non-blocking issue I did notice was the studio UI workflow seems a little odd. Maybe this is a quirk of xblock asides in studio:

Screenshot 2025-02-20 at 11 02 06 AM

Excited to see this on RC!

{% elif block_type == "video" %}
<p><b>Questions about this video?</b><br>AskTim</p>
{% endif %}
<img src="/static/images/icon.svg" alt="Chat Icon" class="chat-icon">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<img src="/static/images/icon.svg" alt="Chat Icon" class="chat-icon">
<img src="/static/images/icon.svg" alt="" class="chat-icon">

The icon is purely decorative. Better for screenreaders to ignore it. The button text is all that screenreaders need.

@asadali145
Copy link
Contributor Author

One non-blocking issue I did notice was the studio UI workflow seems a little odd. Maybe this is a quirk of xblock asides in studio:

I noticed this as well. I can work on this in a follow-up PR while we test it out on RC. I can create an issue for this tomorrow.

if getattr(block, "category", None) == "video":
try:
content, filename, mimetype = get_transcript_from_contentstore(
block, "en", "txt", block.get_transcripts_info()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Was there any specific reason for requesting the .txt transcripts? .srt in my opinion is more widely used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using the transcript for now. It's better to remove this as we will pass the block ID and the transcript will be fetched separately. I can remove this.

Comment on lines 68 to 73
ask_tim_drawer_title = String(
display_name=_("Open Learning Drawer Title"),
default="",
scope=Scope.content,
help=_("Drawer title displayed in the chat drawer"),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I have two suggestions here:

  1. We might want to use enforce_type to make sure it is always stored as string.
  2. I haven't run the block but I think we should set about {block.display_name} from below code as a default here. We would probably save some if conditions.
    • Also, Have we tested this if the title is too long? Would that break the design?
    • Should we not use settings scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have followed the existing field pattern that you added. We haven't used enforced_type + the settings scope. Looking at what it means makes me think that we should set the settings scope for all other fields as well.

Also, Have we tested this if the title is too long? Would that break the design?

This will be passed to the drawer from the smooth design. I can test it but it is not related to the current PR.

but I think we should set about {block.display_name} from below code as a default here

We don't have a block here it self, I am not sure of a way to set the default here. That is why I used the defaults when displaying in CMS/LMS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drawer title looks good I think. No ellipsis but its fine for now.
Screenshot 2025-02-21 at 3 54 11 PM

drawer_title = (
self.ask_tim_drawer_title
if self.ask_tim_drawer_title
else f"about {block.display_name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related comment above

except Exception: # noqa: BLE001
content = ""

extra_context["video_transcript"] = content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we are passing the whole transcript here. I might be wrong but my understanding was that we will pass an id. Sorry, if this sounds like an unreasonable question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as I mentioned above.

Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a code review from my side.
I didn't test it due to time constraints but I am ok since you and Chris have tested it. Good to go from my side. 👍

@asadali145 asadali145 changed the title feat: use AI Chat js bundle component feat: AI Chat drawer Feb 21, 2025
@asadali145 asadali145 merged commit 8e960bf into main Feb 21, 2025
8 checks passed
@asadali145 asadali145 deleted the asad/smoot-js-bundle branch February 21, 2025 13:45
This was referenced Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants