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.64k stars 1.01k forks source link

matrix-bot-chatgpt #2556

Open ReggieMarr opened 1 year ago

ReggieMarr commented 1 year ago

Describe the bug A clear and concise description of what the bug is. When attempting to install the matrix-bot-chatgpt I am unable to talk to it. journalctl looks like This:

Mar 09 06:04:03 vps-b8ce3055 systemd[1]: Started Matrix chatgpt bot.
Mar 09 06:04:04 vps-b8ce3055 matrix-bot-chatgpt[4094466]: yarn run v1.22.19
Mar 09 06:04:04 vps-b8ce3055 matrix-bot-chatgpt[4094466]: $ node --enable-source-maps dist/index.js
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Thu, 09 Mar 2023 06:04:05 GMT [INFO] [index] Starting bot using ChatGPT model: text-chat-davinci-002-20221122
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Thu, 09 Mar 2023 06:04:05 GMT [INFO] [index] Using promptPrefix: <|im_sep|>Instructions:
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: You are ChatGPT, a large language model trained by OpenAI.
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Current date: March 9, 2023<|im_sep|>
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Thu, 09 Mar 2023 06:04:05 GMT [ERROR] [MatrixHttpClient] (REQ-3) { errcode: 'M_NOT_FOUND', error: 'data not found' }
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Thu, 09 Mar 2023 06:04:05 GMT [ERROR] [MatrixHttpClient] (REQ-5) {
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:   '@marvin:bridge.monster': {
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:     '0yWYBY6E': {
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:       error: 'user_id or device_id mismatch: users:  - @marvin:bridge.monster, devices:  - 0yWYBY6E'
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:     }
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:   }
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: }
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: node:internal/process/promises:289
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:             triggerUncaughtException(err, true /* fromPromise */);
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:             ^
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<IncomingMessage>".] {
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]:   code: 'ERR_UNHANDLED_REJECTION'
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: }
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: Node.js v19.6.0
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: error Command failed with exit code 1.
Mar 09 06:04:05 vps-b8ce3055 matrix-bot-chatgpt[4094466]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Mar 09 06:04:06 vps-b8ce3055 systemd[1]: matrix-bot-chatgpt.service: Main process exited, code=exited, status=1/FAILURE
Mar 09 06:04:06 vps-b8ce3055 systemd[1]: matrix-bot-chatgpt.service: Failed with result 'exit-code'.
Mar 09 06:04:36 vps-b8ce3055 systemd[1]: matrix-bot-chatgpt.service: Scheduled restart job, restart counter is at 209.

Moments later it looks like this:

systemd[1]: matrix-bot-chatgpt.service: Scheduled restart job, restart counter is at 238.                                                           
systemd[1]: Stopped Matrix chatgpt bot.                                                                                                             
systemd[1]: Starting Matrix chatgpt bot...                                                                                                          
systemd[1]: Started Matrix chatgpt bot.                                                                                                             
matrix-bot-chatgpt[4124907]: yarn run v1.22.19                                                                                                      
matrix-bot-chatgpt[4124907]: $ node --enable-source-maps dist/index.js                                                                              
matrix-bot-chatgpt[4124907]: Thu, 09 Mar 2023 06:22:06 GMT [ERROR] [MatrixHttpClient] (REQ-1) { errcode: 'M_UNKNOWN_TOKEN', error: 'Unknown token' }
matrix-bot-chatgpt[4124907]: /usr/src/app/node_modules/matrix-bot-sdk/src/http.ts:110                                                               
matrix-bot-chatgpt[4124907]:         throw new MatrixError(errBody, response.statusCode);                                                           
matrix-bot-chatgpt[4124907]:               ^                                                                                                        
matrix-bot-chatgpt[4124907]: MatrixError: M_UNKNOWN_TOKEN: Unknown token                                                                            
matrix-bot-chatgpt[4124907]:     at doHttpRequest (/usr/src/app/node_modules/matrix-bot-sdk/src/http.ts:110:15)                                     
matrix-bot-chatgpt[4124907]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)                                      
matrix-bot-chatgpt[4124907]:     at MatrixClient.descriptor.value (/usr/src/app/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)        
matrix-bot-chatgpt[4124907]:     at MatrixClient.getWhoAmI (/usr/src/app/node_modules/matrix-bot-sdk/src/MatrixClient.ts:624:24)                    
matrix-bot-chatgpt[4124907]:     at MatrixClient.getUserId (/usr/src/app/node_modules/matrix-bot-sdk/src/MatrixClient.ts:614:9)                     
matrix-bot-chatgpt[4124907]:     at MatrixClient.descriptor.value (/usr/src/app/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)        
matrix-bot-chatgpt[4124907]:     at async CommandHandler.prepareProfile (file:///usr/src/app/dist/handlers.js:14:23)                                
matrix-bot-chatgpt[4124907]:     at async CommandHandler.start (file:///usr/src/app/dist/handlers.js:10:9)                                          
matrix-bot-chatgpt[4124907]:     at async main (file:///usr/src/app/dist/index.js:77:5) {                                                           
matrix-bot-chatgpt[4124907]:   body: { errcode: 'M_UNKNOWN_TOKEN', error: 'Unknown token' },                                                        
matrix-bot-chatgpt[4124907]:   statusCode: 401,                                                                                                     
matrix-bot-chatgpt[4124907]:   errcode: 'M_UNKNOWN_TOKEN',                                                                                          
matrix-bot-chatgpt[4124907]:   error: 'Unknown token',                                                                                              
matrix-bot-chatgpt[4124907]:   retryAfterMs: undefined                                                                                              
matrix-bot-chatgpt[4124907]: }                                                                                                                      
matrix-bot-chatgpt[4124907]: Node.js v19.7.0                                                                                                        
matrix-bot-chatgpt[4124907]: error Command failed with exit code 1.                                                                                 
matrix-bot-chatgpt[4124907]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.                                   
systemd[1]: matrix-bot-chatgpt.service: Main process exited, code=exited, status=1/FAILURE                                                          
systemd[1]: matrix-bot-chatgpt.service: Failed with result 'exit-code'.                                                                             
systemd[1]: matrix-bot-chatgpt.service: Scheduled restart job, restart counter is at 239.   

To Reproduce My vars.yml file looks like this:

matrix_bot_chatgpt_enabled: true

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

# Customized for testing, also failed with default
matrix_bot_chatgpt_matrix_bot_username_localpart: 'marvin'

# Matrix access token (from bot user above)
# see: https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix
matrix_bot_chatgpt_matrix_access_token: 'TOKEN_CHECKED_WITH_ELEMENT'

Run ansible-playbook -i inventory/hosts setup.yml --tags=install-all,start

Expected behavior Expected chatgpt to respond to messages or be running. Neither is the Case. Matrix Server:

reggiemarr@vps-b8ce3055:~$ uname -a
Linux vps-b8ce3055 5.15.0-67-generic #74-Ubuntu SMP Wed Feb 22 14:14:39 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
reggiemarr@vps-b8ce3055:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy
watzfatz commented 1 year ago

edit: i did just solve it for me. i didnt read the "how to obtain an access token"-part properly and always logged out from the user invalidating the token by doing so. to solve this you need to (as described on ^ page): open a private window, open your element.domain page, log into the chatgpt user and obtain the access token, then just close the window WITHOUT LOGGIN OUT!

hope this helps and you did the same easy to avoid mistake

BettyNutz commented 1 year ago

edit: i did just solve it for me. i didnt read the "how to obtain an access token"-part properly and always logged out from the user invalidating the token by doing so. to solve this you need to (as described on ^ page): open a private window, open your element.domain page, log into the chatgpt user and obtain the access token, then just close the window WITHOUT LOGGIN OUT!

hope this helps and you did the same easy to avoid mistake

Did you try getting your token with this (Obtain an access token via curl bit):

https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/obtaining-access-tokens.md