Limekiller / moodle-block_openai_chat

An AI chat block for Moodle, powered by GPT
https://moodle.org/plugins/block_openai_chat
GNU General Public License v3.0
29 stars 18 forks source link

Update API key conditional to check the local instance before displaying error message #49

Closed DavidPruem closed 4 months ago

DavidPruem commented 6 months ago

Hi,

I'm currently using moodle 4.1.9 (LTS Version), with the openai chat block. I have to enter an api key and select an default assistant in the main block settings. I entered a API-Key without any credits and chose one dummy assistant as default. My intention is that, teachers who want to use this block have to enter their own api key and then can select their own prepared assistants. As far as i understand the description on the plugin webpage on moodle.org this should work.

The feedback i get from my teachers is, that they can't select their own assistants but are stuck with my non functional dummy assistant, even after they entered their own api key.

michael-milette commented 6 months ago

I tested it with Moodle 4.1.5+ and the latest Moodle 4.3.3+ release today.

If you have even just a single character in the global API key field of the plugin's settings and have enabled the Instance-level settings in the plugin's settings, you should be able to specify a local API key in the block's settings within the course. If that key is valid and has credits available, it works.

However, if you don't have anything in the plugin's global API Key field, it doesn't matter what you do in the local instance settings, it will not work. I would have expected it to work with just a local instance key. I consider this a bug.

image

If you don't see a field called OpenAI API Key in the local instance under Advanced, you likely did not enable the instance-level settings in the blocks global settings, you will not have the option of specifying the API key in the local settings for the block.

image

Last but not least, always make sure that the specified API key at the local level, exists, is correct, and has credits attached to it. Otherwise, it will be as useful as the dummy API key that you specified locally.

image

Hope you find this information helpful. If not, please include a screenshot of the prompt and error message that you are getting when you try to chat with GPT.

Best regards,

Michael Milette

Limekiller commented 6 months ago

Thanks for this issue Michael and David--this is an artifact from before local block settings were implemented. A conditional was added to check if the global API key had been added, because the block wouldn't work in any context without it and a clear message was needed to communicate that to admins. I'll update this to also check if there's a key at the block level as well.

DavidPruem commented 6 months ago

Thank you very much for your fast response.

It is indeed helpful, that I don't need a real API-Key in the global settings.

Unfortunately I still can't select an assistant in the instance settings, the drop down is empty. The used API-Key is not my own so I can't absolutely verify that it is correct, but I trust that the teacher who entered the key is reliable and trustworthy in this regard.

Best regards,

David Prüm

Limekiller commented 4 months ago

This has been fixed in https://github.com/Limekiller/moodle-block_openai_chat/commit/006c61e01fdd6a467a37a6ad5d8f4dcf53e77c4d