Adding Chat GPT functionality to Storyline

Aug 09, 2023

Hi,

I am operating at the limit of my small knowledge about JavaScript here, but I hope someone can help.

I am trying to integrate a Q & A function to a course using Chat GPT. I have set up a test page with the relevant information secure key from Chat GPT (and yes, I am aware that having it client side is not best practice, but I want to get it to work in principle). I have a script that I have checked (using Chat GPT, ironically) and am told it looks fine. I have published it, and it doesn't work - I have been through it time and again, and I can't see anything wrong. I opened the console in the browser and saw an error message 'status 429' I looked this up, and it doesn't apply here - but there is a response from the API from open AI - telling me that it can't see the secure key, that I know is there. The JS is 'looking' in the right place, but this doesn't appear to be transmitted to Chat GPT.

Does anyone have any idea what I am doing wrong? I hope it may be obvious to someone more experienced with Java than me (not difficult), but any help is appreciated. I have attached the script if it helps.

7 Replies
Michael O'Sullivan

Thanks for the quick response - the AI mentioned this when I asked it to check the code

"You are logging the error in the catch block, which is good for debugging, but you might want to handle errors more gracefully, e.g., show a message to the user in the event of an API failure". I assumed it meant that any error would show some sort of message - which I don't get.

I published the SL page to the web, and when I opened the Console I saw this as a URL - I know the key is there and only set up today. Does this make any sense to you?

 

{
    "error": {
        "message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

Adam Scormit

Having your API code exposed is really not the best practice.  It's almost like sending your credit card and expiration date through email.  You can get the code to work, but as soon as it goes semi-live, you're transmitting the key on an  open network.  

What will happen is that your key will be revoked by OpenAI if the key becomes exposed, and it will eventually become exposed.

You really need an endpoint to work with and have the code on your endpoint work directly with OpenAI and your Storyline project.