OpenAI API key generated but AI is not working

OpenAI API key generated but AI is not working

by Doulos Xavier -
Number of replies: 13

I am using Moodle 4.5.3 (Build: 20250317)

I generated the OpenAI API key using my personal account on OpenAI 

I am getting an error, any idea how to fix, any pointers appreciated. 

image%20%281%29.png

image.png

Average of ratings: Useful (1)
In reply to Doulos Xavier

Re: OpenAI API key generated but AI is not working

by Ken Task -
Picture of Particularly helpful Moodlers

See the links @
https://moodle.org/mod/forum/view.php?f=15
This is the installing and upgrading help forum.

Proper forum for your issue:
https://moodle.org/mod/forum/view.php?id=8826

SOP

Turn on debugging and report what you see.  

Check server error logs and report what you see.   

Check tracker 

https://tracker.moodle.org/browse/MDL-82977?jql=text%20~%20%224.5%20OpenAi%22

In reply to Ken Task

Re: OpenAI API key generated but AI is not working

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
This might give additional information
https://github.com/marcusgreen/moodle-tool_aitest
Average of ratings: Useful (1)
In reply to Marcus Green

Re: OpenAI API key generated but AI is not working

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Moderator note: No need to re-post Binoy, as I'm just moving this discussion to the AI and Moodle forum...

In reply to Marcus Green

Re: OpenAI API key generated but AI is not working

by Doulos Xavier -
Hi Marcus,

Just wondering where do I place the code

Your Github page mentions this

"Place the code in the folder /admin/tool/aitest Run the upgrade/install With admin rights view the /admin/tool/aitest page"

However my folder structure is this I am using cPanel, appreciate your response.
public_html/moodle42/ai/tests
In reply to Doulos Xavier

Re: OpenAI API key generated but AI is not working

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I know nothing of cpanel. The code should be put in the filder /admin/too/aitest. The folder admin/tool will already exist, so you need to put the code into a new folder there. If you have command line access with git you can change to the admin/tool folder
which from the command prompt at the root is

cd admin/tool

Then run this command with git

git clone https://github.com/marcusgreen/moodle-tool_aitest aitest

It is purely a diagnostic tool to throw out more information on the source of the problem. Once you have finished delete it.
Some reasons I can think of for the ai subsystem it not working is an incorrect key, something I managed to do the last time I did an install, a missing organisation key thing, or the wrong sort of openai account.
In reply to Marcus Green

Re: OpenAI API key generated but AI is not working

by Doulos Xavier -
Hi Marcus, thanks for your guidance,

I used the git clone command to pull the code into /admin/tool/aitest just wondering how do I test, in the README.md you have mentioned

"Run the upgrade/install With admin rights view the /admin/tool/aitest page"

Went to the browser and typed this http://192.168.18.151/moodle/admin/tool/aitest/ 

Getting this error

"Exception - Call to undefined function xdebug_break()

More information about this error"

But there is nothing showing in the link that takes to the main Moodle site. 

In reply to Doulos Xavier

Re: OpenAI API key generated but AI is not working

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

My apologies Binoy, I had left a thing in for debugging. If you either repeat the whole process, or go into the aitest folder and run
 
git pull
It will tell you it is has upgraded a plugin and then you can re-visit the folder and it should run.

This is an example of the output I just got, which is still a bit unclear, but is a reasonable pointer.


In reply to Marcus Green

Re: OpenAI API key generated but AI is not working

by Doulos Xavier -

Hi Marcus, i tried this. But still getting "Exception - Call to undefined function xdebug_break()" appreciate your help

mp@migrate:/var/www/html/moodle/admin/tool/aitest$ sudo git pull
[sudo] password for mp:
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 11 (delta 5), reused 10 (delta 4), pack-reused 0 (from 0)
Unpacking objects: 100% (11/11), 1.72 KiB | 63.00 KiB/s, done.
From https://github.com/marcusgreen/moodle-tool_aitest
 + 5cccf79...3d7e55a main       -> origin/main  (forced update)
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

In reply to Doulos Xavier

Re: OpenAI API key generated but AI is not working

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I suggest deleting the folder and re-doing the git clone 


In reply to Doulos Xavier

OpenAI API key generated but AI is not working

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I kept failing to get my OpenAI key to work too. I eventually just gave up and created two OpenAI servers using two Raspberry Pi 5's. One is using the 26TOPS Pi HAT and the other is just running in CPU mode with a M.2 SSD drive. I have no idea if either one could work well enough to support a classroom, but for me as a single person plugin developer, they work fine. I have also generated my own, raspiai tool, based on the openai one provided in the Moodle code, which lets me quickly change the AI model in use.

I have seen YouTube videos demonstrating similar OpenAI installs on much more capable servers that get output much, much quicker. The major advantage is that your interaction with your own server running OpwnAI is that it is private.
In reply to AL Rachels

OpenAI API key generated but AI is not working

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Al I would be very happy to have a Zoom or similar session with you to see if I can talk you through to a solution. Obvs I would tax you with asking if you would play with my AIText questions once your system was working smile....

I was working with a fresh install of Moodle 5.0 and the AI Subsystem last night and it didn't work at first but after about 20 minutes of fiddling it came to life, you can see an example of the first thing I did here.

https://fosstodon.org/@marcusgreen/114338482478970243

Binoy did you ever get yours working?

In reply to Marcus Green

OpenAI API key generated but AI is not working

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I would be happy to Zoom with you but until next Tuesday I am kind of swamped with what I need to do here. Actually, I am very interested in your AIText question to see if I can use it as a guide in adding AI capabilities to my Diary plugin.

Currently I am in the process of creating a "clean" Moodle 5 development site to replace my butchered one. At the moment I am trying to get my raspi AI provider set up and working. Things appear to be working a little differently when setting up a new Moodle 5 compared to the one I was using during the past few months of Moodle development.