spantaleev / matrix-docker-ansible-deploy

🐳 Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
GNU Affero General Public License v3.0
4.93k stars 1.05k forks source link

matrix-bot-chatgpt - M_UNKNOWN_TOKEN: Invalid access token passed. #2495

Closed schopenhauer closed 1 year ago

schopenhauer commented 1 year ago

I am getting the following error message when trying to deploy the matrix-bot-chatgpt, but the bot user and API key configured in vars.yml seem to be in good order. Any ideas?

Feb 16 20:34:11 matrix-bot-chatgpt[304157]: yarn run v1.22.19
Feb 16 20:34:11 matrix-bot-chatgpt[304157]: $ node --enable-source-maps dist/index.js
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: Thu, 16 Feb 2023 19:34:13 GMT [ERROR] [MatrixHttpClient] (REQ-1) {
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   errcode: 'M_UNKNOWN_TOKEN',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   error: 'Invalid access token passed.',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   soft_logout: false
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: }
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: /usr/src/app/node_modules/matrix-bot-sdk/src/http.ts:110
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:         throw new MatrixError(errBody, response.statusCode);
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:               ^
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: MatrixError: M_UNKNOWN_TOKEN: Invalid access token passed.
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at doHttpRequest (/usr/src/app/node_modules/matrix-bot-sdk/src/http.ts:110:15)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at MatrixClient.descriptor.value (/usr/src/app/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at MatrixClient.getWhoAmI (/usr/src/app/node_modules/matrix-bot-sdk/src/MatrixClient.ts:624:24)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at MatrixClient.getUserId (/usr/src/app/node_modules/matrix-bot-sdk/src/MatrixClient.ts:614:9)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at MatrixClient.descriptor.value (/usr/src/app/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at async CommandHandler.prepareProfile (file:///usr/src/app/dist/handlers.js:14:23)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at async CommandHandler.start (file:///usr/src/app/dist/handlers.js:10:9)
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     at async main (file:///usr/src/app/dist/index.js:73:5) {
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   body: {
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     errcode: 'M_UNKNOWN_TOKEN',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     error: 'Invalid access token passed.',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:     soft_logout: false
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   },
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   statusCode: 401,
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   errcode: 'M_UNKNOWN_TOKEN',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   error: 'Invalid access token passed.',
Feb 16 20:34:13 matrix-bot-chatgpt[304157]:   retryAfterMs: undefined
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: }
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: Node.js v19.6.0
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: error Command failed with exit code 1.
Feb 16 20:34:13 matrix-bot-chatgpt[304157]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Feb 16 20:34:13 systemd[1]: matrix-bot-chatgpt.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 20:34:13 systemd[1]: matrix-bot-chatgpt.service: Failed with result 'exit-code'.
gitayam commented 1 year ago

what method did you use to generate the token, was having issue when i graphically set with element vs the api route

schopenhauer commented 1 year ago

I followed the instructions to create new API key as described in the comments:

# Obtain a new API key from https://platform.openai.com/account/api-keys

ralfi commented 1 year ago

Do this ...

  1. Login with your Matrix Account for the Bot in your favourite Browser, if needed complete your encryption settings

  2. Copy the Access Token in Settings -> Help and Info -> Acess Token

  3. IMPORTANT: DO NOT LOGOUT -> LET THE BROWSER WINDOW OPEN!

  4. Import this Token in your vars.yml

  5. Execute the Ansible Skript with setup-all Option, after this execute with the start Option if nothing in setup-all fails

  6. For simple Debugging create a new Room and invite your bot

  7. If it works then 👋 Hello, I'm ChatGPT bot! Matrix E2EE: true appears

  8. Try !chatgpt Your_Question

  9. If it works close the Browser Window opened in 1.

Hope that helps ...

If this works steps 1-4 it could be necessary to do again if you receive a new Chatgpt Docker Image (IMHO).

schopenhauer commented 1 year ago

Ok, finally got it to work and give me the Hello message. Now, there seems to be another issue:

eb 17 11:39:45 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:45 GMT [INFO] [index] Starting bot using ChatGPT model: text-chat-davinci-002-20221122
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:45 GMT [INFO] [index] Using promptPrefix: <|im_sep|>Instructions:
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: You are ChatGPT, a large language model trained by OpenAI.
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: Current date: February 17, 2023<|im_sep|>
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:45 GMT [ERROR] [MatrixHttpClient] (REQ-5) { errcode: 'M_NOT_FOUND', error: 'Event not found.' }
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:45 GMT [INFO] [MatrixClientLite] End-to-end encryption enabled
Feb 17 11:39:45 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:45 GMT [INFO] [index] Bot started!
Feb 17 11:39:46 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:39:46 GMT [ERROR] [MatrixHttpClient] (REQ-8) { errcode: 'M_NOT_FOUND', error: 'Event not found.' }
Feb 17 11:40:27 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:40:27 GMT [ERROR] [OpenAI-API Error: Error: Failed to send message. HTTP 404 - {
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:     "error": {
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:         "message": "That model does not exist",
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:         "type": "invalid_request_error",
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:         "param": null,
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:         "code": null
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:     }
Feb 17 11:40:27 matrix-bot-chatgpt[409349]: }
Feb 17 11:40:27 matrix-bot-chatgpt[409349]: ]
Feb 17 11:40:27 matrix-bot-chatgpt[409349]: TypeError: Cannot read properties of undefined (reading 'response')
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:     at CommandHandler.onMessage (file:///usr/src/app/dist/handlers.js:128:86)
Feb 17 11:40:27 matrix-bot-chatgpt[409349]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Feb 17 11:40:27 matrix-bot-chatgpt[409349]: Fri, 17 Feb 2023 10:40:27 GMT [ERROR] [MatrixHttpClient] (REQ-23) { errcode: 'M_NOT_FOUND', error: 'Event not found.' }
ralfi commented 1 year ago

image

This works for me. Seems to me you do not have the last line.

ralfi commented 1 year ago

Quick an Dirty way is to change the file in your matrix Directory /chatgpt/config/env and restart the service file with systemctl. But dont forget to change the vars.yml.

schopenhauer commented 1 year ago

Ok, this works well - thank you :+1:

array-in-a-matrix commented 1 year ago

Can you close the issue please, since the problem is now fixed.