moodle-block_openai_chat icon indicating copy to clipboard operation
moodle-block_openai_chat copied to clipboard

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

Open DavidPruem opened this issue 1 year ago • 3 comments
trafficstars

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.

DavidPruem avatar Mar 25 '24 17:03 DavidPruem

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

michael-milette avatar Mar 25 '24 19:03 michael-milette

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.

Limekiller avatar Mar 28 '24 15:03 Limekiller

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

DavidPruem avatar Apr 02 '24 10:04 DavidPruem

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

Limekiller avatar Jun 04 '24 22:06 Limekiller