yGuy / chatgpt-mattermost-bot

A very simple implementation of a service for a mattermost bot that uses ChatGPT in the backend.
MIT License
148 stars 49 forks source link

Request failed with status code 429 #20

Closed vmakarenko closed 1 year ago

vmakarenko commented 1 year ago

Cannot get response from the ChatGPT even with the paid Plus ChatGPT account:

{
  "level": "ERROR",
  "time": "2023-04-18T09:46:19.306Z",
  "name": "bot",
  "msg": "Request failed with status code 429",
  "pid": 1,
  "hostname": "2b5d342ab71e",
  "diff": 253,
  "err": {
    "name": "Error",
    "stack": "Error: Request failed with status code 429\n    at createError (/app/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/app/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:322:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1358:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)",
    "config": {
      "transitional": {
        "silentJSONParsing": true,
        "forcedJSONParsing": true,
        "clarifyTimeoutError": false
      },
      "transformRequest": [
        null
      ],
      "transformResponse": [
        null
      ],
      "timeout": 0,
      "xsrfCookieName": "XSRF-TOKEN",
      "xsrfHeaderName": "X-XSRF-TOKEN",
      "maxContentLength": -1,
      "maxBodyLength": -1,
      "headers": {
        "Accept": "application/json, text/plain, */*",
        "Content-Type": "application/json",
        "User-Agent": "OpenAI/NodeJS/3.2.1",
        "Authorization": "Bearer **MY_TOKEN_API_KEY**",
        "Content-Length": 247
      },
      "method": "post",
      "data": "{\"messages\":[{\"role\":\"system\",\"content\":\"You are a helpful assistant named @chatgpt who provides succinct answers in Markdown format.\"},{\"role\":\"user\",\"content\":\"@chatgpt  now with OPENAI_MAX_TOKENS=100\"}],\"model\":\"gpt-3.5-turbo\",\"max_tokens\":100}",
      "url": "https://api.openai.com/v1/chat/completions"
    },
    "status": 429
  }
}
stuartConnolly commented 1 year ago

This was happening to me last night and the issue was an expired free account. As soon as I upgraded to a paid account it start working. Don't think it's an issue with the bot.

yGuy commented 1 year ago

Try creating a new token api key with the new API account. Otherwise, please check if the API works for you without the bot. If it doesn't work, either, then it's obviously not a problem with the bot.

vmakarenko commented 1 year ago

This is definitely not a problem of the bot - I tried to access API as you suggested. Same result. I'll try with payed version. Thank you!

zell-mbc commented 1 year ago

There seem to be other reasons for this error as well? My chatBot was happily answering questions for a couple of months and then out of the blue stopped with the exact same error as above. My API token is still valid though, I am using this very token in a Desktop applet, and that hasn't stopped working.

please check if the API works for you without the bot Do you mean using this token in another app (which I do), or is there a way to test through Mattermost without the bot?

I have now created a new token, updated the docker-compose file and restarted, but unfortunately the error remains. I can see the new token is used in the JSON error: "…Authorization":"Bearer my new token","Content-Length":226}…" When looking at the token on OpenaAIs website I can see it's been used, but still I get the error?

image

Neither the token created in March nor the one created today will work for me? Do I maybe need the payed version for Mattermost?

yGuy commented 1 year ago

Do I maybe need the payed version for Mattermost?

Mattermost ist not involved here, at all. So the answer to that question is a clear: "no".

By "checking the API" I mean the OpenAI API calls. Basically just call the following code in isolation: https://github.com/yGuy/chatgpt-mattermost-bot/blob/06f41d0216e56301131d092cac78a6357f627182/src/openai-thread-completion.js#L12

It's the only place where the error occurs and is completely isolate from mattermost, and if you look at the code it's also completely isolated from the bot, so it's just the Open AI API that can reasonably fail, here.

zell-mbc commented 1 year ago

Sorry, yes, meant to write payed for OpenAI instead of Mattermost . Please excuse my ignorance but I am not sure how to run this script in isolation. I tried via node but that errors out because of missing dependencies, obviously. I guess I need to somehow run the createChatCompletion function in it's natural environment :-) so all the supporting libraries are found, but I don't know.

yGuy commented 1 year ago

Definitely consider paying those few cents per month to OpenAI. It's well worth it (some would call it cheap to pay about 1$ per month for your whole team) and ensures proper operation.

zell-mbc commented 1 year ago

Would going for a $ account be a test or do you know that's the issue?

Reason for asking is because this is for a non profit org, and I am putting my time in for free as well. Getting them to sign up and leave their financial data with OpenAI will need convincing and is probably not worth the effort. The alternative is that I pay out of my own pocket which I am not sure is a good idea either.

yGuy commented 1 year ago

Would going for a $ account be a test or do you know that's the issue?

Don't know. Just try. I have a paid account and I have never seen this issue. The same holds true for others, it seems.

You are working for free but cannot afford to pay (much less than) 1 US Dollars for testing? Really?

zell-mbc commented 1 year ago

Nah, of course $1 won't break the bank. It's more the uncontrollable nature of others surfing on my account :-) I guess I'll change to a paid for account and see if this changes anything. I'll report back…

zell-mbc commented 1 year ago

That was it, changed my account to a paid account and voila, ChatGPT is talking to me again. Still strange that my KDE ChatGPT applet kept on working and the ChatBot with the same token stopped, but I got a working solution again.

Thanks for helping along…