chatgpt-mirai-qq-bot icon indicating copy to clipboard operation
chatgpt-mirai-qq-bot copied to clipboard

Go-cqhttp版本 API 模式无法连上OpenAI

Open King-Of-Knights opened this issue 1 year ago • 5 comments

提交 issue 前,请先确认:

  • [x] 我已看过 FAQ,此问题不在列表中
  • [x] 我已看过其他 issue,他们不能解决我的问题
  • [x] 我认为这不是 Mirai 或者 OpenAI 的 BUG

表现
描述 BUG 的表现情况

同样的配置,在Mirai版本,API是正常使用,在Go-cqhttp下连接不上"api.openai.com"

运行环境:

  • 操作系统:CentOS
  • Docker: ?
  • 项目版本:?

复现步骤
描述你是如何触发这个 BUG 的

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

预期行为
描述你认为正常情况下应该看见的情况

截图

Warning: running as root
2023-03-11 17:18:14,706 Warning: cannot enable SSH socket upgrades
2023-03-11 17:18:14,706  No module named 'paramiko'
2023-03-11 17:18:14,706 created tcp socket '0.0.0.0:14500'
2023-03-11 17:18:14,708 no uinput module (not usually needed)
2023-03-11 17:18:16,165 pointer device emulation using XTest
2023-03-11 17:18:16,214 serving html content from '/usr/share/xpra/www'
2023-03-11 17:18:16,216 wrote pid 8 to '/tmp/0/server.pid'
2023-03-11 17:18:16,234 Warning: socket directory '/tmp/0'
2023-03-11 17:18:16,234  expected permissions 700 but found 750
2023-03-11 17:18:16,234 Warning: some of the sockets are in an unknown state:
2023-03-11 17:18:16,234  /run/user/1000/xpra/VM-4-13-centos-0
2023-03-11 17:18:16,235  /tmp/0/socket
2023-03-11 17:18:16,235  please wait as we allow the socket probing to timeout
2023-03-11 17:18:22,244 created unix domain socket '/run/user/1000/xpra/VM-4-13-centos-0'
2023-03-11 17:18:22,244 created unix domain socket '/tmp/0/socket'
2023-03-11 17:18:22,244 xvfb pid=12
2023-03-11 17:18:22,301 Warning: cannot watch for application menu changes without pyinotify:
2023-03-11 17:18:22,302  No module named 'pyinotify'
2023-03-11 17:18:22,309 Warning: cannot load menu data
2023-03-11 17:18:22,309  No module named 'xdg'
2023-03-11 17:18:22,318 Warning: webcam forwarding is disabled
2023-03-11 17:18:22,318  the virtual video directory '/sys/devices/virtual/video4linux' was not found
2023-03-11 17:18:22,318  make sure that the 'v4l2loopback' kernel module is installed and loaded
2023-03-11 17:18:22,318  or use the 'webcam=no' option
2023-03-11 17:18:22,318 found 0 virtual video devices for webcam forwarding
2023-03-11 17:18:22,321 started command `xterm -e python bot.py 2>&1 | tee /tmp/log.txt` with pid 54
2023-03-11 17:18:22,428 7.5GB of system memory
2023-03-11 17:18:22,541 waiting for initialization thread to complete
2023-03-11 17:18:22,542 xpra is ready.
2023-03-11 17:18:22,542 xpra X11 seamless version 4.4.3-r0 64-bit
2023-03-11 17:18:22,543  uid=0 (root), gid=0 (root)
2023-03-11 17:18:22,543  running with pid 8 on Linux Debian 11 bullseye
2023-03-11 17:18:22,552  connected to X11 display :0 with 24 bit colors
2023-03-11 17:18:22,979 OpenGL is supported on display ':0'
2023-03-11 17:18:22,979  using 'llvmpipe (LLVM 11.0.1, 256 bits)' renderer
2023-03-11 17:18:23.590 | ERROR    | config:scan_presets:264 - 检查预设:正常 <==> presets/default.txt [失败:文件不存在]
2023-03-11 17:18:23.590 | SUCCESS  | config:scan_presets:262 - 检查预设:猫娘 <==> presets/catgirl.txt [成功]
2023-03-11 17:18:23.591 | SUCCESS  | config:scan_presets:275 - 注册预设:catgirl <==> ./presets/catgirl.txt [成功]
2023-03-11 17:18:23.591 | SUCCESS  | config:scan_presets:275 - 注册预设:预设模板 <==> ./presets/预设模板.txt [成功]
2023-03-11 17:18:23.591 | INFO     | __main__::10 - 检测到 Onebot 配置,将以 Onebot 模式启动……
2023-03-11 17:18:23.961 | INFO     | manager.bot:login_openai:107 - 正在登录第 1 个 OpenAI 账号
2023-03-11 17:18:23.961 | INFO     | manager.bot:__login_openai_apikey:247 - 尝试使用 api_key 登录中...
2023-03-11 17:18:23.962 | INFO     | manager.bot:__check_proxy:169 - 正在检查代理配置:http://127.0.0.1:10809
2023-03-11 17:18:25.579 | SUCCESS  | manager.bot:login_openai:122 - 登录成功!
2023-03-11 17:18:25.579 | SUCCESS  | manager.bot:login_openai:139 - 成功登录 1/1 个 OpenAI 账号!
2023-03-11 17:18:25.579 | INFO     | manager.bot:login:78 - AI 类型:chatgpt-web - 可用账号: 0 个
2023-03-11 17:18:25.580 | INFO     | manager.bot:login:78 - AI 类型:openai-api - 可用账号: 1 个
2023-03-11 17:18:25.580 | INFO     | manager.bot:login:78 - AI 类型:bing-cookie - 可用账号: 0 个
[2023-03-11 17:18:25 +0000] [63] [INFO] Running on http://0.0.0.0:8554 (CTRL + C to quit)
2023-03-11 17:18:25,582 - hypercorn.error - INFO - info - Running on http://0.0.0.0:8554 (CTRL + C to quit)
 * Serving Quart app ''
 * Environment: production
 * Please use an ASGI server (e.g. Hypercorn) directly in production
 * Debug mode: False
 * Running on http://0.0.0.0:8554 (CTRL + C to quit)
[2023-03-11 17:20:38 +0000] [63] [INFO] 127.0.0.1:11426 GET /ws 1.1 101 - 993
2023-03-11 17:20:58.783 | DEBUG    | middlewares.concurrentlock:handle_request:40 - [Concurrent] 排队中,前面还有 0 个人!
2023-03-11 17:20:58.784 | DEBUG    | middlewares.concurrentlock:handle_request:42 - [Concurrent] 排到了!
2023-03-11 17:20:58.788 | DEBUG    | middlewares.timeout:create_timeout_task:12 - [Timeout] 开始计时……
2023-03-11 17:21:04.957 | ERROR    | universal:request:147 - HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(, 'Connection to api.openai.com timed out. (connect timeout=None)'))
Traceback (most recent call last):

  File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           │          └ 
           └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
          └ TimeoutError(110, 'Connection timed out')
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
    │            └ ('2001::adfc:4a0c', 443, 0, 0)
    └ None

TimeoutError: [Errno 110] Connection timed out


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       │    └ 
                       └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
    │    │              └ 
    │    └ 
    └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
    │    └ 
    └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
    │    │             │    └ 
    │    │             └ 
    │    └ None
    └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 179, in _new_conn
    raise ConnectTimeoutError(
          └ 

urllib3.exceptions.ConnectTimeoutError: (, 'Connection to api.openai.com timed out. (connect timeout=None)')


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
           │    └ 
           └ 
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              │       └ 
              └ Retry(total=0, connect=None, read=False, redirect=None, status=None)
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
          │             │      │    │        │             └ 'unknown'
          │             │      │    │        └ 
          │             │      │    └ ConnectTimeoutError(, 'Connection to api.openai.com timed out. (...
          │             │      └ '/v1/chat/completions'
          │             └ 
          └ 

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(, 'Connection to api.openai.com timed out. (connect timeout=None)'))


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/app/bot.py", line 11, in 
    import onebot_bot

  File "", line 1178, in _find_and_load
  File "", line 1149, in _find_and_load_unlocked
  File "", line 690, in _load_unlocked
  File "", line 940, in exec_module
  File "", line 241, in _call_with_frames_removed

  File "/app/onebot_bot.py", line 177, in 
    bot.run(host=config.onebot.reverse_ws_host, port=config.onebot.reverse_ws_port)
    │   │        │      │      │                     │      │      └ 8554
    │   │        │      │      │                     │      └ Onebot(qq=, manager_qq=, reverse_ws_host='0.0.0.0', reverse_ws_port=8554)
    │   │        │      │      │                     └ 
    │   │        │      │      └ '0.0.0.0'
    │   │        │      └ Onebot(qq=, manager_qq=, reverse_ws_host='0.0.0.0', reverse_ws_port=8554)
    │   │        └ 
    │   └ 
    └ 

  File "/usr/local/lib/python3.11/site-packages/aiocqhttp/__init__.py", line 222, in run
    self._server_app.run(host=host, port=port, *args, **kwargs)
    │    │           │        │          │      │       └ {'use_reloader': False}
    │    │           │        │          │      └ ()
    │    │           │        │          └ 8554
    │    │           │        └ '0.0.0.0'
    │    │           └ 
    │    └ 
    └ 
  File "/usr/local/lib/python3.11/site-packages/quart/app.py", line 1423, in run
    loop.run_until_complete(asyncio.gather(*tasks))
    │    │                  │       │       └ [
    │    │                  └ 
    │    └ 
    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
    │    └ 
    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
    │    └ 
    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
    │      └ 
    └ )>
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ 
    │    │            │    │           └ )>
    │    │            │    └ 
    │    │            └ )>
    │    └ 
    └ )>

  File "/app/onebot_bot.py", line 91, in _
    await handle_message(response, f"friend-{event.user_id}", msg.display, chain)
          │              │                                    │   │        └ MessageChain([Plain(text='test')])
          │              │                                    │   └ 
          │              │                                    └ MessageChain([Plain(text='test')])
          │              └ .response at 0x7f7b6f6a5620>
          └ 

  File "/app/universal.py", line 155, in handle_message
    await action(session_id, message.strip(), conversation_context, respond)
          │      │           │       │        │                     └ .respond at 0x7f7b6f6a5ee0>
          │      │           │       │        └ None
          │      │           │       └ 
          │      │           └ 'test'
          │      └ 'friend-'
          └ .wrap_request..call at 0x7f7b6f6a6200>

  File "/app/universal.py", line 47, in call
    await m.handle_request(session_id, message, respond, conversation_context, n)
          │ │              │           │        │        │                     └ .wrap_request..call at 0x7f7b6f6a6160>
          │ │              │           │        │        └ None
          │ │              │           │        └ .respond at 0x7f7b6f6a5ee0>
          │ │              │           └ 'test'
          │ │              └ 'friend-'
          │ └ 
          └ 

  File "/app/middlewares/concurrentlock.py", line 43, in handle_request
    await action(session_id, prompt, conversation_context, respond)
          │      │           │       │                     └ .respond at 0x7f7b6f6a5ee0>
          │      │           │       └ None
          │      │           └ 'test'
          │      └ 'friend-'
          └ .wrap_request..call at 0x7f7b6f6a6160>

  File "/app/universal.py", line 47, in call
    await m.handle_request(session_id, message, respond, conversation_context, n)
          │ │              │           │        │        │                     └ .wrap_request..call at 0x7f7b6f6a60c0>
          │ │              │           │        │        └ None
          │ │              │           │        └ .respond at 0x7f7b6f6a5ee0>
          │ │              │           └ 'test'
          │ │              └ 'friend-'
          │ └ 
          └ 

  File "/app/middlewares/middleware.py", line 9, in handle_request
    await action(session_id, prompt, conversation_context, respond)
          │      │           │       │                     └ .respond at 0x7f7b6f6a5ee0>
          │      │           │       └ None
          │      │           └ 'test'
          │      └ 'friend-'
          └ .wrap_request..call at 0x7f7b6f6a60c0>

  File "/app/universal.py", line 47, in call
    await m.handle_request(session_id, message, respond, conversation_context, n)
          │ │              │           │        │        │                     └ .wrap_request..call at 0x7f7b6f6a6020>
          │ │              │           │        │        └ None
          │ │              │           │        └ .respond at 0x7f7b6f6a5ee0>
          │ │              │           └ 'test'
          │ │              └ 'friend-'
          │ └ 
          └ 

  File "/app/middlewares/ratelimit.py", line 25, in handle_request
    await action(session_id, prompt, conversation_context, respond)
          │      │           │       │                     └ .respond at 0x7f7b6f6a5ee0>
          │      │           │       └ None
          │      │           └ 'test'
          │      └ 'friend-'
          └ .wrap_request..call at 0x7f7b6f6a6020>

  File "/app/universal.py", line 47, in call
    await m.handle_request(session_id, message, respond, conversation_context, n)
          │ │              │           │        │        │                     └ .request at 0x7f7b6f6a5f80>
          │ │              │           │        │        └ None
          │ │              │           │        └ .respond at 0x7f7b6f6a5ee0>
          │ │              │           └ 'test'
          │ │              └ 'friend-'
          │ └ 
          └ 

  File "/app/middlewares/timeout.py", line 30, in handle_request
    await action(session_id, prompt, conversation_context, respond)
          │      │           │       │                     └ .respond at 0x7f7b6f6a5ee0>
          │      │           │       └ None
          │      │           └ 'test'
          │      └ 'friend-'
          └ .request at 0x7f7b6f6a5f80>

> File "/app/universal.py", line 114, in request
    async for rendered in task:
                          └ 

  File "/app/conversation.py", line 85, in ask
    async for item in self.adapter.ask(prompt):
                      │    │       │   └ 'test'
                      │    │       └ 
                      │    └ 
                      └ 

  File "/app/adapter/chatgpt/api.py", line 66, in ask
    raise resp
          └ ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/c...

  File "/app/adapter/chatgpt/api.py", line 49, in ask_sync
    for resp in self.bot.ask_stream(prompt, role=self.hashed_user_id):
                │    │   │          │            │    └ 'user-878b7bbebc9cde9b'
                │    │   │          │            └ 
                │    │   │          └ 'test'
                │    │   └ 
                │    └ 
                └ 

  File "/usr/local/lib/python3.11/site-packages/revChatGPT/V3.py", line 81, in ask_stream
    response = self.session.post(
               │    │       └ 
               │    └ 
               └ 
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           │    │               │         │          │       └ {'headers': {'Authorization': 'Bearer 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'}, 'stream': True}
           │    │               │         │          └ {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'system', 'content': 'You are ChatGPT, a large language model trained by Ope...
           │    │               │         └ None
           │    │               └ 'https://api.openai.com/v1/chat/completions'
           │    └ 
           └ 
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           │    │    │       └ {'timeout': None, 'allow_redirects': True, 'proxies': OrderedDict(), 'stream': True, 'verify': True, 'cert': None}
           │    │    └ 
           │    └ 
           └ 
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        │       │    │          └ {'timeout': None, 'proxies': OrderedDict(), 'stream': True, 'verify': True, 'cert': None}
        │       │    └ 
        │       └ 
        └ 
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 553, in send
    raise ConnectTimeout(e, request=request)
          │                         └ 
          └ 

requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(, 'Connection to api.openai.com timed out. (connect timeout=None)'))

其他内容
Mirai版的可以正常使用,Go-cqhttp版本连接超时

King-Of-Knights avatar Mar 12 '23 13:03 King-Of-Knights

Connection timeout 是超时了。和我没关系,是你部署的网络有问题。 网络太差建议配置代理。

lss233 avatar Mar 12 '23 13:03 lss233

@lss233 您看这段:

2023-03-11 17:18:23.961 | INFO     | manager.bot:login_openai:107 - 正在登录第 1 个 OpenAI 账号
2023-03-11 17:18:23.961 | INFO     | manager.bot:__login_openai_apikey:247 - 尝试使用 api_key 登录中...
2023-03-11 17:18:23.962 | INFO     | manager.bot:__check_proxy:169 - 正在检查代理配置:http://127.0.0.1:10809
2023-03-11 17:18:25.579 | SUCCESS  | manager.bot:login_openai:122 - 登录成功!
2023-03-11 17:18:25.579 | SUCCESS  | manager.bot:login_openai:139 - 成功登录 1/1 个 OpenAI 账号!

我认为我的网络环境是OK的,我还试过access_token了,Mirai版本下我可以登录ChatGPT账号,在Go-cqhttp版本连接不上,配置文件上,我只是把[Mirai]改成了[onebot],补充了一下反向代理的东西,其他的没动,我感觉是Go-cqhttp版本版本没有获取到系统代理

King-Of-Knights avatar Mar 12 '23 13:03 King-Of-Knights

@lss233 大大,我研究了一下,从我v2ray的访问记录来看,目前的API key方法好像不会走系统代理,导致国内机器没办法用,我用以下方法创建docker就成功了:

docker run --name mirai-chatgpt-bot -e XPRA_PASSWORD=1 -e HTTP_PROXY="http://127.0.0.1:10809" -e HTTPS_PROXY="http://127.0.0.1:10809" -v /usr/local/config.cfg:/app/config.cfg --network host lss233/chatgpt-mirai-qq-bot:browser-version

King-Of-Knights avatar Mar 12 '23 16:03 King-Of-Knights

你在容器里 IP 是隔离的,不能用 127.0.0.1 这个地址。

lss233 avatar Mar 12 '23 23:03 lss233

你在容器里 IP 是隔离的,不能用 127.0.0.1 这个地址。

他这个设置确实有问题,不过确实是不走代理的,同样环境下,web可以走代理,但是api不走代理,那个api的代理配置文件,只有验证的时候走一下,用的时候不走代理

chung1912 avatar Mar 14 '23 14:03 chung1912