Install Edly AI_Coach_XBlock fail

I am not sure if this is the right place to ask for help. I tried to install AI_Coach_XBlock from https://github.com/edly-io/ai-coach-xblock and after setting advance module list, I do not see the “AI Coach” after pressing “Advanced component” of course unit. Here are my steps:

  1. pip install ai-coach-xblock
  2. Update Settings of LMS and CMS - Add the OPEN AI secret key in the lms and cms configuration files:
    2.1) \env\apps\openedx\config\cms.env.yml
    2.2) \env\apps\openedx\config\lms.env.yml

Add the following:
OPENAI_SECRET_KEY:‘my_openai_secret_key’
3) tutor local launch
4) Update course advanced settings by adding ai_coach
5) At course unit, click “Advanced component”, but AI Coach is not found.

I check the error log using the command suggested by @Mahendra.

tutor local logs --follow cms --tail=100 -f

And the attach is my log file.
cms log - 15 Oct 24.txt (36.6 KB)

There is error about item not found. I am not sure what is it about. And
I am quite new about plugin, is there anything I did incorrectly, please let me know. Thank you very much.

Hi @N_V,

  1. Could you please share the Tutor version you are currently using?
  2. Additionally, are you running Tutor in dev mode or local mode?

If you’re using tutor local, please follow these steps:

  • Add ai-coach-xblock to OPENEDX_EXTRA_PIP_REQUIREMENTS and run tutor config save.
  • Rebuild the openedx image using tutor images build openedx.

Also, make sure to add your OPENAI_SECRET_KEY in the following files:

  • env/apps/openedx/settings/lms/production.py
  • env/apps/openedx/settings/lms/development.py

Apply the same changes to the CMS settings as well.

If you’re using a plugin to update the settings, that will ensure the changes persist. Otherwise, these changes might be overwritten when running tutor config save.

Thanks for your advice.

My Tutor version is 18.1.3.
My OpenEdX version is Redwood.2

I follow your advice and it works. Thanks a lot.

@hinakhadim I tried to follow your solution but it still does not work… Please help.

Here is how I setup tutor

python -m pip install --upgrade tutor[full]
tutor local launch
tutor --version
tutor, version 19.0.0
python --version
Python 3.9.18

I tried to add the following line to the config

nano "$(tutor config printroot)/config.yml"
OPENEDX_EXTRA_PIP_REQUIREMENTS: ['ai-coach-xblock']
tutor config save
tutor images build openedx

I verified the installation

tutor local run cms bash
~/edx-platform$ pip show ai-coach-xblock
Name: ai-coach-xblock
Version: 1.0.7

I did get a warning during the build about a missing dependency “importlib_resources” but I don’t think this is related to the issue…

I tried to set the openai key


nano "$(tutor config printroot)/env/apps/openedx/settings/lms/production.py"
nano "$(tutor config printroot)/env/apps/openedx/settings/lms/development.py"
nano "$(tutor config printroot)/env/apps/openedx/settings/cms/production.py"
nano "$(tutor config printroot)/env/apps/openedx/settings/cms/development.py"

OPENAI_SECRET_KEY = "key"

I then tried to add “ai_coach” under a course advanced settings like this:


Advanced module list
[
    "edx_sga",
    "lti",
    "scorm",
    "library_content",
    "annotatable",
    "poll",
    "survey",
    "ai_coach"
]

and still when I go to unit->components->advanced I don’t see the ai_coach

So I also tried
tutor local restart

And I cleared the cache in the browser and in the build, yet still I don’t see the component.

I will really appreciate your help. Thanks.

In the logs I found this:

tutor local logs lms

lms-1  | Traceback (most recent call last):
[...]
lms-1  |   File "/openedx/venv/lib/python3.11/site-packages/ai_coach/__init__.py", line 1, in <module>
lms-1  |     from .ai_coach import AICoachXBlock
lms-1  |   File "/openedx/venv/lib/python3.11/site-packages/ai_coach/ai_coach.py", line 8, in <module>
lms-1  |     import importlib_resources
lms-1  | ModuleNotFoundError: No module named 'importlib_resources'

so here is what I did:

nano "$(tutor config printroot)/config.yml"
OPENEDX_EXTRA_PIP_REQUIREMENTS:
- importlib_resources
- ai-coach-xblock

tutor config save
tutor images build openedx

I verified the installation with

 tutor local run cms bash
~/edx-platform$ pip show importlib_resources
Name: importlib_resources
Version: 6.5.2

I checked both cms and lms logs and now I don’t see any errors

tutor local logs lms
tutor local logs cms

But still there is no option for ai_coach…
So I tried tutor local restart.

I also realized each time I was building I was overriding the openai key so I added it to the main config file

nano "$(tutor config printroot)/config.yml"
OPENAI_SECRET_KEY: key

but I noticed after the build it doesn’t add the key to the cms and lms config files so I manually added the key to each one again and then I did tutor local restart…

I am looking at the course through the studio UI with the user created with this command:
tutor local do createuser --superuser --staff super super@example.com -p super

I am fairly new to openedx and I am not familiar with plugins, I am still looking for a method to resolve this issue,
Thank you.

Hi @Terak,
Thanks for sharing detailed logs for the error. I verified that this is not working due to importlib_resources. The Fix PR has been created and will be merged after review.

Hi @hinakhadim

I’m also having issues with the openedx-cmi5-xblock. I assume it has the same issue in sumac since it also has that import.

Hi @hinakhadim was this fix tested in sumac? I tried to install the xblock in my local environment and followed the steps in the repo and still can’t see the component appear.

Hi @Andres_Espinel, thank you for pointing out the issue. This has now been fixed in the latest version of ai-coach-xblock and it should now be working in sumac.

Hi @nmacedocunha, thank you for pointing out this issue to us. This issue has now been resolved in the latest version of openedx-cmi5-xblock and it should now be working in Sumac.

Thanks for the reply! I installed the 1.0.8 version of the xblock and I could add it normally to the site. However when a learner tries to click in the “Ask from coach” button, we get a message saying: Unable to connect to AI-coach. Please contact your administrator. I checked my logs and I got an error: 2025-02-20 19:20:34,184 ERROR 30 [ai_coach.ai_coach] [user 4] [ip] ai_coach.py:187 - ‘dict’ object has no attribute ‘chat’.

I ran into the same issue when installing the XBlock (v1.0.8 ) on Sumac. Initially, I saw the same error in my logs:

'dict' object has no attribute 'chat'

After debugging, I found that the cause was a problem initializing the OpenAI client, which was failing with this error:

Client.__init__() got an unexpected keyword argument 'proxies'

The issue seems to be related to httpx version 0.28, which removed the proxies argument, breaking compatibility Error with OpenAI 1.56.0 - Client.__init__() got an unexpected keyword argument 'proxies' - #2 by arata - API - OpenAI Developer Community

I downgraded httpx to 0.27.2, and after that, the XBlock started working correctly. It’s not an ideal solution, but it’s a temporary fix that allows me to use the XBlock for now

I’ve opened an issue in the repository to report this problem: OpenAI Client Initialization Fails Due to httpx 0.28 · Issue #19 · edly-io/ai-coach-xblock · GitHub

Hi @magajh , thank you for pointing out this issue. This issue has now been resolved and the new changes have been merged into the main branch.

1 Like