hibobmaster / matrix_chatgpt_bot

A simple matrix bot that supports image generation and chatting using ChatGPT, Langchain
https://matrix.to/#/#public:matrix.qqs.tw
MIT License
75 stars 13 forks source link

node-chatgpt-api connecting issue #12

Closed jaodei closed 1 year ago

jaodei commented 1 year ago

Hi, I got error below while running on an amd64 based machine.

# got error: ✔ Container node-chatgpt-api Started0.4s image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was re[+] Running 3/3trix-bot-bingai1 ✔ Container node-chatgpt-api Started0.4s image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was re ✔ Container matrix-bot-bingai1 Started0.4s ! api The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 0.0s

But it appears the two containers are running though if I ask bing, it will have lots of errors with the most recent ones as below from docker logs command. _Traceback (most recent call last): File "/app/bing.py", line 28, in ask_bing resp = await self.session.post(url=self.bing_api_endpoint, json=self.data, timeout=120) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request conn = await self._connector.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect proto = await self._create_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 901, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection raise ClientConnectorError(req.connection_key, exc) from exc aiohttp.clientexceptions.ClientConnectorError: Cannot connect to host node-chatgpt-api:3000 ssl:default [Try again]

Is this due to the lack support of arm64? Cheers.

hibobmaster commented 1 year ago

With this pr https://github.com/waylaidwanderer/node-chatgpt-api/pull/312, you can use following image that supports arm64. change hibobmaster/node-chatgpt-api to ghcr.io/waylaidwanderer/node-chatgpt-api hibobmaster/node-chatgpt-api now supports arm64 too.

jaodei commented 1 year ago

Great. Thank you.

jaodei commented 1 year ago

I've encountered error of "Error, please retry" when I interacted with Bing Chat. It was OK. Then I tried to start from almost scratch. Then I got below error from docker logs node-chatgpt-api: @waylaidwanderer/chatgpt-api@1.37.0 start node bin/server.js Error: the settings.js file does not exist.

Is that because of the recent updates of both matrixchatgptbot and ghcr.io/waylaidwanderer/node-chatgpt-api?

For your info, I give the contents of key files below. Please could you give me some insights? Thank you. file compose.yaml _services: app: image: hibobmaster/matrixchatgptbot:latest container_name: matrix-bot-bingai1 restart: always volumes:

File config.json: I only run Bing Chat in this instance _{ "homeserver": "http://matrix-nginx-proxy:12080", "user_id": "@bingai:mydomain.com", "password": "999999999999999999999999999", "device_id": "bingai-docker", "bing_api_endpoint": "http://node-chatgpt-api:3000/conversation", "jailbreakEnabled": true, "markdownformatted": true }

File settings.js: _export default { cacheOptions: {}, storageFilePath: process.env.STORAGE_FILE_PATH || './cache.json', bingAiClient: { // Necessary for some people in different countries, e.g. China (https://cn.bing.com) host: '', userToken: 'mytoken-here', debug: true, }, // Options for the API server apiOptions: { port: process.env.API_PORT || 3000, host: process.env.APIHOST || 'localhost', debug: true, clientToUse: 'bing', perMessageClientOptionsWhitelist: { validClientsToUse: ['bing'], }, }, // Options for the CLI app cliOptions: { // (Optional) Possible options: chatgpt, bing. // clientToUse: 'bing', }, }

hibobmaster commented 1 year ago

Your config.json has one error:

- "bing_api_endpoint": "http://node-chatgpt-api:3000/conversation",
+ "bing_api_endpoint": "http://api:3000/conversation",

compose.yaml

services:
  app:
    image: hibobmaster/matrixchatgptbot:latest
    container_name: matrix-bot-bingai1
    restart: always
    volumes:
      - ./config.json:/app/config.json
      - ./db:/app/db
    networks:
    - matrix

  api:
    image: ghcr.io/waylaidwanderer/node-chatgpt-api:latest
    container_name: node-chatgpt-api
    restart: always
    volumes:
    - ./settings.js:/var/chatgpt-api/settings.js
    networks:
    - matrix

networks:
  matrix:
    external: true

Make sure there is a settings.js in the current working directory.

jaodei commented 1 year ago

It seems both http://node-chatgpt-api:3000/conversation and http://api:3000/conversation work. Anyway, I take your advice.

I have the setttings.js file in the right place.

However, the error of "Error: the settings.js file does not exist." is still there. If I change the latest version of ghcr.io/waylaidwanderer/node-chatgpt-api to a previous one v1.36.0, which luckily I have a copy in the server, the error is gone. But still I have the error of "Error, please retry" when I interact with bing chat. Another look at the log file, it says Bing service unavailable. Do you have the same issue? I can confirm I put the right bing token.

hibobmaster commented 1 year ago

update compose.yaml

- ./settings.js:/var/chatgpt-api/settings.js
+ ./settings.js:/app/settings.js
services:
  app:
    image: hibobmaster/matrixchatgptbot:latest
    container_name: matrix-bot-bingai1
    restart: always
    volumes:
      - ./config.json:/app/config.json
      - ./db:/app/db
    networks:
    - matrix

  api:
    image: ghcr.io/waylaidwanderer/node-chatgpt-api:latest
    container_name: node-chatgpt-api
    restart: always
    volumes:
    - ./settings.js:/app/settings.js
    networks:
    - matrix

networks:
  matrix:
    external: true
hibobmaster commented 1 year ago

There are some bugs in the official https://github.com/waylaidwanderer/node-chatgpt-api dockerfile, i will try to fix it

jaodei commented 1 year ago

cool. updated compose.yaml. it works. however, still got an error: _matrix-bot-bingai1 | await execute_callback(cb.func, room, event) matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 254, in execute_callback matrix-bot-bingai1 | return await func(*args) matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ matrix-bot-bingai1 | File "/app/bot.py", line 232, in message_callback matrix-bot-bingai1 | if sender_id not in self.pandora_data: matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ matrix-bot-bingai1 | AttributeError: 'Bot' object has no attribute 'pandora_data'. Did you mean: 'pandora_init'? matrix-bot-bingai1 | Unclosed client session matrix-bot-bingai1 | client_session: <aiohttp.client.ClientSession object at 0xffff97ebb910> matrix-bot-bingai1 | Unclosed connector matrix-bot-bingai1 | connections: ['[(<aiohttp.clientproto.ResponseHandler object at 0xffff97e9d160>, 5412.762922734)]'] matrix-bot-bingai1 | connector: <aiohttp.connector.TCPConnector object at 0xffff97ebb950> matrix-bot-bingai1 exited with code 0 matrix-bot-bingai1 | 2023-06-01 01:06:35,706 - INFO - matrix chatgpt bot start..... matrix-bot-bingai1 | 2023-06-01 01:06:35,707 - INFO - Login via password

I dont have any pandora key, is that the cause? Thank you.

hibobmaster commented 1 year ago

cool. updated compose.yaml. it works. however, still got an error: _matrix-bot-bingai1 | await execute_callback(cb.func, room, event) matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 254, in execute_callback matrix-bot-bingai1 | return await func(*args) matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ matrix-bot-bingai1 | File "/app/bot.py", line 232, in message_callback matrix-bot-bingai1 | if sender_id not in self.pandora_data: matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ matrix-bot-bingai1 | AttributeError: 'Bot' object has no attribute 'pandora_data'. Did you mean: 'pandora_init'? matrix-bot-bingai1 | Unclosed client session matrix-bot-bingai1 | client_session: <aiohttp.client.ClientSession object at 0xffff97ebb910> matrix-bot-bingai1 | Unclosed connector matrix-bot-bingai1 | connections: ['[(<aiohttp.clientproto.ResponseHandler object at 0xffff97e9d160>, 5412.762922734)]'] matrix-bot-bingai1 | connector: <aiohttp.connector.TCPConnector object at 0xffff97ebb950> matrix-bot-bingai1 exited with code 0 matrix-bot-bingai1 | 2023-06-01 01:06:35,706 - INFO - matrix chatgpt bot start..... matrix-bot-bingai1 | 2023-06-01 01:06:35,707 - INFO - Login via password

I dont have any pandora key, is that the cause? Thank you.

https://github.com/hibobmaster/matrix_chatgpt_bot/wiki/ChatGPT-Web

hibobmaster commented 1 year ago

@jaodei https://github.com/waylaidwanderer/node-chatgpt-api/pull/399 change ghcr.io/waylaidwanderer/node-chatgpt-api:latest to hibobmaster/node-chatgpt-api:latest Verify if it is working.

jaodei commented 1 year ago

changed.

but got similar or same error as below.

: matrix-bot-bingai1 | 2023-06-01 01:35:14,436 - INFO - matrix chatgpt bot start..... : matrix-bot-bingai1 | 2023-06-01 01:35:14,438 - INFO - Login via password : matrix-bot-bingai1 | Traceback (most recent call last): : matrix-bot-bingai1 | File "/app/main.py", line 83, in : matrix-bot-bingai1 | asyncio.run(main()) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run : matrix-bot-bingai1 | return runner.run(main) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run : matrix-bot-bingai1 | return self._loop.run_until_complete(task) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete : matrix-bot-bingai1 | return future.result() : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/app/main.py", line 78, in main : matrix-bot-bingai1 | await matrix_bot.sync_forever(timeout=30000, full_state=True) : matrix-bot-bingai1 | File "/app/bot.py", line 908, in sync_forever : matrix-bot-bingai1 | await self.client.sync_forever(timeout=timeout, full_state=full_state) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/base_client.py", line 111, in wrapper : matrix-bot-bingai1 | return await func(self, *args, *kwargs) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 1232, in sync_forever : matrix-bot-bingai1 | await self.run_response_callbacks([await response]) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/asyncio/tasks.py", line 605, in _wait_for_one : matrix-bot-bingai1 | return f.result() # May raise f.exception(). : matrix-bot-bingai1 | ^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/base_client.py", line 111, in wrapper : matrix-bot-bingai1 | return await func(self, args, *kwargs) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 1074, in sync : matrix-bot-bingai1 | response = await self._send( : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 818, in _send : matrix-bot-bingai1 | await self.receive_response(resp) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 725, in receive_response : matrix-bot-bingai1 | await self._handle_sync(response) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 692, in _handle_sync : matrix-bot-bingai1 | await self._handle_joined_rooms(response) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 614, in _handle_joined_rooms : matrix-bot-bingai1 | await execute_callback(cb.func, room, event) : matrix-bot-bingai1 | File "/usr/local/lib/python3.11/site-packages/nio/client/async_client.py", line 254, in execute_callback : matrix-bot-bingai1 | return await func(args) : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | File "/app/bot.py", line 232, in message_callback : matrix-bot-bingai1 | if sender_id not in self.pandora_data: : matrix-bot-bingai1 | ^^^^^^^^^^^^^^^^^ : matrix-bot-bingai1 | AttributeError: 'Bot' object has no attribute 'pandora_data'. Did you mean: 'pandora_init'? : matrix-bot-bingai1 | Unclosed client session : matrix-bot-bingai1 | client_session: <aiohttp.client.ClientSession object at 0xffffa422f810> : matrix-bot-bingai1 | Unclosed connector : matrix-bot-bingai1 | connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0xffffa4219160>, 7145.929393786)]'] : matrix-bot-bingai1 | connector: <aiohttp.connector.TCPConnector object at 0xffffa422f850> matrix-bot-bingai1[95969]: matrix-bot-bingai1 exited with code 0 matrix-bot-bingai1[95969]: matrix-bot-bingai1 | 2023-06-01 01:35:28,886 - INFO - matrix chatgpt bot start..... matrix-bot-bingai1[95969]: matrix-bot-bingai1 | 2023-06-01 01:35:28,887 - INFO - Login via password

hibobmaster commented 1 year ago

AttributeError: 'Bot' object has no attribute 'pandora_data'. Did you mean: 'pandora_init'? Do you provide accessToken as mentioned in https://github.com/hibobmaster/matrix_chatgpt_bot/wiki/ChatGPT-Web

Pandora is used to ChatGPT web and it is not related to bing ai.

jaodei commented 1 year ago

No. I have no such token in configuration. I don't need chatgpt web at least for now.

jaodei commented 1 year ago

Well. I don't have such configuration at all.

BTW, if I provide this token, I don't need openai API key?

hibobmaster commented 1 year ago

Well. I don't have such configuration at all.

BTW, if I provide this token, I don't need openai API key?

Sorry, my fault. I found a bug in program.

Yes, if you provide access_token, there is no need to use openai API key. !talk, !goon, !new commands will use ChatGPT web which is free.

hibobmaster commented 1 year ago

https://github.com/hibobmaster/matrix_chatgpt_bot/commit/985db37be2e037136b8baab2159a43b99ad28897 Can you pull the latest docker image again and verify if it work?

jaodei commented 1 year ago

It works. Thank you for your great work.

Bing Chat is just quite slow. Takes a minute or so to get a reply. Are you experiencing the same?

hibobmaster commented 1 year ago

@jaodei Thank you for your bug report.

I have the same feeling as you, Bing Chat is really slow. As you may see https://github.com/waylaidwanderer/node-chatgpt-api/commit/90300946bc33c208007346cbecce4b37219cd5ea increase timeout value to 300 seconds.