yGuy / chatgpt-mattermost-bot

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

Mattermost-bot #56

Closed Crimzin69 closed 6 months ago

Crimzin69 commented 11 months ago

Dear yGuy,

Thank you for the great api.

I have recently in stalled the lattest Mattermost on docker with Portainer. And thus also you container ghcr.io/yguy/chatgpt-mattermost-bot:latest:

When I try chat with the bot I get the following reply:

chatgpt BOT Sorry, but I encountered an internal error when trying to process your message

My versions:

Stack setup for ghcr.io/yguy/chatgpt-mattermost-bot:latest:

version: '3.7'

services: chatbot: image: ghcr.io/yguy/chatgpt-mattermost-bot:latest build: . restart: unless-stopped environment: MATTERMOST_URL: https://removed for privacy.co.za MATTERMOST_TOKEN: removed for privacy OPENAI_API_KEY: sk-removed for privacy

I am not sure how I can set the model to gpt4 but befor I digress see the log response below.

Log : On first run it has the following log:

2023-10-01T07:51:05.523Z INFO name=bot-ws msg=websocket connecting to wss://removed-for-privacy/api/v4/websocket pid=1 hostname=1af6ed135303 diff=0 2023-10-01T07:51:05.792Z LOG name=bot msg=Connected to Mattermost. pid=1 hostname=1af6ed135303 diff=0

Then as soon as you try to talk to it you get:

2023-10-01T07:56:49.002Z ERROR name=bot msg=Request failed with status code 429 pid=1 hostname=1af6ed135303 diff=343210 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.3.0","Authorization":"Bearer Removed-For-Privacy","Content-Length":1452},"method":"post","data":"{\"model\":\"gpt-3.5-turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"Your name is @chatgpt and you are a helpful assistant. Whenever users asks you for help you will provide them with succinct answers formatted using Markdown. You know the user's name as it is provided within the meta data of the messages.\"},{\"role\":\"user\",\"name\":\"Crim\",\"content\":\"hi @chatgpt can you help me\"}],\"max_tokens\":2000,\"temperature\":1,\"functions\":[{\"name\":\"image-plugin\",\"description\":\"Generates an image based on a given image description.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"imageDescription\":{\"type\":\"string\",\"description\":\"The description of the image provided by the user\"}},\"required\":[\"imageDescription\"]}},{\"name\":\"exit-plugin\",\"description\":\"Says goodbye to the user and wish him a good day.\",\"parameters\":{\"type\":\"object\",\"properties\":{},\"required\":[]}},{\"name\":\"message-collect-plugin\",\"description\":\"Collects messages in the thread for a specific user or time\",\"parameters\":{\"type\":\"object\",\"properties\":{\"lookBackTime\":{\"type\":\"number\",\"description\":\"The time in milliseconds to look back in time and collect messages which were posted within this timespan. Omit this parameter if the collected messages are independent from the time they were sent.\"},\"messageCount\":{\"type\":\"number\",\"description\":\"The number of messages which should be collected. Omit this parameter if you want to collect all messages.\"}},\"required\":[]}}],\"function_call\":\"auto\"}","url":"https://api.openai.com/v1/chat/completions"},"status":429}

Thank you and I hope you can give me some insight.

Kind Regards

Crimzin69 commented 11 months ago

If I update the stack as follows:

version: '3.7'

services: chatbot: image: ghcr.io/yguy/chatgpt-mattermost-bot:master build: . restart: unless-stopped environment: MATTERMOST_URL: https://Removed-for-Privacy.co.za MATTERMOST_TOKEN: Removed-for-Privacy OPENAI_API_KEY: sk-Removed-for-Privacy OPENAI_MODEL_NAME: GPT-4 NODE_ENV: production DEBUG_LEVEL: INFO # TRACE MATTERMOST_BOTNAME: "@chatgpt"

I get the following in the log:

":"ERROR","time":"2023-10-01T08:25:50.513Z","name":"bot","msg":"Request failed with status code 404","pid":1,"hostname":"266c1ddd5a87","diff":45282,"err":{"name":"Error","stack":"Error: Request failed with status code 404\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.3.0","Authorization":"Bearer sk-Removed-for-Privacy","Content-Length":1429},"method":"post","data":"{\"model\":\"GPT-4\",\"messages\":[{\"role\":\"system\",\"content\":\"Your name is @chatgpt and you are a helpful assistant. Whenever users asks you for help you will provide them with succinct answers formatted using Markdown. You know the user's name as it is provided within the meta data of the messages.\"},{\"role\":\"user\",\"name\":\"gewadmin\",\"content\":\"Hi @chatgpt \"}],\"max_tokens\":2000,\"temperature\":1,\"functions\":[{\"name\":\"image-plugin\",\"description\":\"Generates an image based on a given image description.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"imageDescription\":{\"type\":\"string\",\"description\":\"The description of the image provided by the user\"}},\"required\":[\"imageDescription\"]}},{\"name\":\"exit-plugin\",\"description\":\"Says goodbye to the user and wish him a good day.\",\"parameters\":{\"type\":\"object\",\"properties\":{},\"required\":[]}},{\"name\":\"message-collect-plugin\",\"description\":\"Collects messages in the thread for a specific user or time\",\"parameters\":{\"type\":\"object\",\"properties\":{\"lookBackTime\":{\"type\":\"number\",\"description\":\"The time in milliseconds to look back in time and collect messages which were posted within this timespan. Omit this parameter if the collected messages are independent from the time they were sent.\"},\"messageCount\":{\"type\":\"number\",\"description\":\"The number of messages which should be collected. Omit this parameter if you want to collect all messages.\"}},\"required\":[]}}],\"function_call\":\"auto\"}","url":"https://api.openai.com/v1/chat/completions"},"status":404}}

yGuy commented 11 months ago

We could implement exponential back-off for those over-using their API keys...

https://help.openai.com/en/articles/5955604-how-can-i-solve-429-too-many-requests-errors

See #57

miukumac commented 8 months ago

Unfortunately I seem to be running into this issue even when I haven't used the service at all and the API keys are, literally, on a fresh paid account.

Also waiting and trying during different times and/or from different IPs or ISPs does not seem to have any effect. Any query of any kind results in a 429.

yGuy commented 8 months ago

That's also an issue with the service. All the bot does is send the request. If the server answers with a 429 I don't see how this could be the fault of the bot.

Are you absolutely sure you are using the new keys?

miukumac commented 8 months ago

Thank you yGuy, we managed to fix the issue and it was related to the account. Sorry for the false alarm :-)

horvath-szilard commented 2 months ago

Thank you yGuy, we managed to fix the issue and it was related to the account. Sorry for the false alarm :-)

@miukumac would you please explain what was the solution?

miukumac commented 2 months ago

Thank you yGuy, we managed to fix the issue and it was related to the account. Sorry for the false alarm :-)

@miukumac would you please explain what was the solution?

We tried with an account that had ChatGPT+ but did not have ChatGPT API subscription, they're separate.