ChatGPT近期以强大的对话和信息整合能力风靡全网,可以写代码、改论文、讲故事,几乎无所不能,这让人不禁有个大胆的想法,能否用他的对话模型把我们的微信打造成一个智能机器人,可以在与好友对话中给出意想不到的回应,而且再也不用担心女朋友影响我们 打游戏 工作了。

本项目是基于ChatGPT的微信聊天机器人,通过 OpenAI 接口生成对话内容,使用 itchat 实现微信消息的接收和自动回复。

简介

已实现特性

  • 文本对话: 接收私聊及群组中的微信消息,使用ChatGPT生成回复内容,完成自动回复
  • 规则定制化: 支持私聊中按指定规则触发自动回复,支持对群组设置自动回复白名单
  • 多账号: 支持多微信账号同时运行
  • 图片生成: 支持根据描述生成图片,并自动发送至个人聊天或群聊
  • 上下文记忆: 支持多轮对话记忆,且为每个好友维护独立的上下会话
  • 语音识别: 支持接收和处理语音消息,通过文字或语音回复
  • 插件化: 支持个性化插件,提供角色扮演、文字冒险、与操作系统交互、访问网络数据等能力

Github地址: https://github.com/zhayujie/chatgpt-on-wechat

更新日志

2023.04.05: 支持微信个人号部署,兼容角色扮演等预设插件,使用文档。(contributed by @JS00000 in #686)

2023.04.05: 增加能让ChatGPT使用工具的tool插件,使用文档。工具相关issue可反馈至chatgpt-tool-hub。(contributed by @goldfishh in #663)

2023.03.25: 支持插件化开发,目前已实现 多角色切换、文字冒险游戏、管理员指令、Stable Diffusion等插件,使用参考 #578。(contributed by @lanvent in #565)

2023.03.09: 基于 whisper API(后续已接入更多的语音API服务) 实现对微信语音消息的解析和回复,添加配置项 "speech_recognition":true 即可启用,使用参考 #415。(contributed by wanggang1987 in #385)

2023.03.02: 接入ChatGPT API (gpt-3.5-turbo),默认使用该模型进行对话,需升级openai依赖 (pip3 install --upgrade openai)。网络问题参考 #351

2023.02.09: 扫码登录存在封号风险,请谨慎使用,参考#58

2023.02.05: 在openai官方接口方案中 (GPT-3模型) 实现上下文对话

2022.12.18: 支持根据描述生成图片并发送,openai版本需大于0.25.0

2022.12.17: 原来的方案是从 ChatGPT页面 获取session_token,使用 revChatGPT 直接访问web接口,但随着ChatGPT接入Cloudflare人机验证,这一方案难以在服务器顺利运行。 所以目前使用的方案是调用 OpenAI 官方提供的 API,回复质量上基本接近于ChatGPT的内容,劣势是暂不支持有上下文记忆的对话,优势是稳定性和响应速度较好。

效果

个人聊天

single-chat-sample.jpg

群组聊天

group-chat-sample.jpg

图片生成

image-create-sample.jpg

快速开始

准备

1. OpenAI账号注册

前往 OpenAI注册页面 创建账号,参考这篇 教程 可以通过虚拟手机号来接收验证码。创建完账号则前往 API管理页面 创建一个 API Key 并保存下来,后面需要在项目中配置这个key。

项目中使用的对话模型是 davinci,计费方式是每1k字 (包含请求和回复) 消耗 $0.02,图片生成是每张消耗 $0.016,账号创建有免费的 $18 额度,使用完可以更换邮箱重新注册。

2.运行环境

支持 Linux、MacOS、Windows 系统(可在Linux服务器上长期运行),同时要求安装有 Python(版本需在 3.7.1~3.9.X 之间,Linux环境建议使用3.7.X)。

(1) 克隆项目代码:

git clone https://github.com/zhayujie/chatgpt-on-wechat
cd chatgpt-on-wechat/

(2) 安装核心依赖 (必选):

能够使用itchat创建机器人,并具有文字交流功能所需的最小依赖集合。

pip3 install -r requirements.txt

(3) 拓展依赖 (可选,建议安装):

pip3 install -r requirements-optional.txt

如果某项依赖安装失败请注释掉对应的行再继续。

配置

配置文件的模板在根目录的config-template.json中,需复制该模板创建最终生效的 config.json 文件:

cp config-template.json config.json

然后在config.json中填入自定义配置,各配置项含义如下:

# config.json文件内容示例
{ 
  "open_ai_api_key": "YOUR API KEY"                           # 填入上面创建的 OpenAI API KEY
  "single_chat_prefix": ["bot", "@bot"],                      # 私聊时文本需要包含该前缀才能触发机器人回复
  "single_chat_reply_prefix": "[bot] ",                       # 私聊时自动回复的前缀,用于区分真人
  "group_chat_prefix": ["@bot"],                              # 群聊时包含该前缀则会触发机器人回复
  "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], # 开启自动回复的群名称列表
  "image_create_prefix": ["画", "看", "找"]                    # 开启图片回复的前缀
}

配置说明:

  • 个人聊天中,需要以 "bot" 或 "@bot" 为开头的内容触发机器人,对应配置中的 single_chat_prefix;机器人回复的内容会以 "[bot]" 作为前缀, 以区分真人,对应的配置为 single_chat_reply_prefix
  • 群组聊天中,群名称需配置在 group_name_white_list 中才能开启群聊自动回复,默认只要被@就会触发机器人自动回复,另外群聊天中只要检测到以 "@bot" 开头的内容,同样会自动回复,这对应配置 group_chat_prefix
  • 对于图像生成,在满足个人或群组触发条件外,还需要额外的关键词,对应配置 image_create_prefix
  • 关于OpenAI对话及图片接口的参数配置(内容自由度、回复字数限制、图片大小等),可以参考 对话接口图像接口 文档直接在 代码 bot\openai\open_ai_bot.py 中进行调整。

运行

1.如果是开发机本地调试,直接在项目根目录下执行:

python3 app.py

终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了(注意:用于登录的微信需要在支付处已完成实名认证)。扫码登录后,就可以在微信手机端通过配置的关键词触发自动回复了。

2.如果是服务器部署,则使用nohup命令在后台运行:

touch nohup.out                                   # 首次运行需要新建日志文件                     
nohup python3 app.py & tail -f nohup.out          # 后台运行程序并输出日志

扫码登录后程序即可运行于服务器后台,此时可通过 ctrl+c 关闭日志,不会影响后台程序的运行。使用 ps -ef | grep app.py | grep -v grep 命令可查看运行于后台的进程,如果想要重新启动程序可以先 kill 掉对应的进程。日志关闭后如果想要再次查看只需输入 tail -f nohup.out

注:如果 扫码后手机提示登录验证需要等待5s,而终端的二维码再次刷新并提示 Log in time out, reloading QR code,此时需参考此 issue 修改一行代码即可解决。

联系

欢迎提交PR、Issues,以及Star支持一下。程序运行遇到问题优先查看 常见问题列表 ,其次前往 Issues 中搜索。如果你想了解更多项目细节,并与开发者们交流更多关于AI技术的实践,欢迎加入星球:

已有 130 条评论

  1. xiaxuesis xiaxuesis

    大佬,我在centos7.7下面部署你的项目,发现还是3.9.9的python更加适合,如果3.8版本的,使用gemini的时候报错,大概意思是google.generativeai没有什么属性来着。
    另外,大佬能帮助开发个小插件么,可否邮件回复我,谢谢!

    1. zyj zyj

      对的,gemini sdk要求3.9以上的python版本的

  2. 123 123

    hi

  3. [...]作者的博客: https://zhayujie.com/chatgpt-on-wechat.html[...]

  4. [...]链接:https://zhayujie.com/chatgpt-on-wechat.html[...]

  5. 萌新 萌新

    大佬我在服务器上按教程部署的时候报这个错误 win上正常运行 能帮我看看吗
    root@ip-172-31-15-69:/home/admin/gptwechat/chatgpt-on-wechat# python3 app.py
    [INFO][2023-05-31 01:39:18][config.py:198] - [INIT] load config: {'open_ai_api_key': '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', 'model': 'gpt-3.5-turbo', 'proxy': '', 'single_chat_prefix': ['bot', '@bot'], 'single_chat_reply_prefix': '[bot] ', 'group_chat_prefix': ['@bot'], 'group_name_white_list': ['ChatGPT测试群', 'ChatGPT测试群2'], 'group_chat_in_one_session': ['ChatGPT测试群'], 'image_create_prefix': ['画', '看', '找'], 'speech_recognition': False, 'group_speech_recognition': False, 'voice_reply_voice': False, 'conversation_max_tokens': 1000, 'expires_in_seconds': 3600, 'character_desc': '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。', 'subscribe_msg': '感谢您的关注!\n这里是ChatGPT,可以自由对话。\n支持语音对话。\n支持图片输入。\n支持图片输出,画字开头的消息将按要求创作图片。\n支持tool、角色扮演和文字冒险等丰富的插件。\n输入{trigger_prefix}#help 查看详细指令。'}
    [INFO][2023-05-31 01:39:18][config.py:148] - [Config] User datas file not found, ignore.
    [ERROR][2023-05-31 01:39:18][app.py:52] - App startup failed!
    [ERROR][2023-05-31 01:39:18][app.py:53] - No module named 'pyqrcode'
    Traceback (most recent call last):
    File "/home/admin/gptwechat/chatgpt-on-wechat/app.py", line 45, in run
    channel = channel_factory.create_channel(channel_name)
    File "/home/admin/gptwechat/chatgpt-on-wechat/channel/channel_factory.py", line 13, in create_channel
    from channel.wechat.wechat_channel import WechatChannel
    File "/home/admin/gptwechat/chatgpt-on-wechat/channel/wechat/wechat_channel.py", line 18, in
    from channel.wechat.wechat_message import *
    File "/home/admin/gptwechat/chatgpt-on-wechat/channel/wechat/wechat_message.py", line 7, in
    from lib import itchat
    File "/home/admin/gptwechat/chatgpt-on-wechat/lib/itchat/__init__.py", line 8, in
    from .components import load_components
    File "/home/admin/gptwechat/chatgpt-on-wechat/lib/itchat/components/__init__.py", line 3, in
    from .login import load_login
    File "/home/admin/gptwechat/chatgpt-on-wechat/lib/itchat/components/login.py", line 17, in
    from pyqrcode import QRCode
    ModuleNotFoundError: No module named 'pyqrcode'

  6. RickD RickD

    大佬,目前itchat除了扫码登入之外,有没有可以通过账号密码进行登入呢;类似QQ这个框架的https://github.com/Mrs4s/go-cqhttp

  7. dootbear dootbear

    Hi zyj,

    我在Mac 的terminal 上按照你上面的步骤, run "pip3 install -r requirements.txt" 没问题。

    但是下一步, 运行 ”pip3 install -r requirements-optional.txt“ 出错了:


    Building wheels for collected packages: pysilk_mod, web.py, lxml, opengraph-py3, wikipedia, betterproto, grpclib, sgmllib3k, stringcase
    Building wheel for pysilk_mod (pyproject.toml) ... error
    error: subprocess-exited-with-error

    × Building wheel for pysilk_mod (pyproject.toml) did not run successfully.
    │ exit code: 1
    ╰─> [31 lines of output]
    running bdist_wheel
    running build
    running build_py

    creating build/temp.macosx-13-arm64-cpython-311/src/silk/src
    clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -DVERSION_INFO=1.6.0 -Isrc/silk/interface -I/private/var/folders/tm/_3kdtj8s3vg3c7llk9s09wp80000gn/T/pip-build-env-l6qiw4qx/overlay/lib/python3.11/site-packages/pybind11/include -I/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c src/silk/src/SKP_Silk_interpolate.c -o build/temp.macosx-13-arm64-cpython-311/src/silk/src/SKP_Silk_interpolate.o -mmacosx-version-min=10.14 -fvisibility=hidden -g0 -stdlib=libc++
    src/silk/src/SKP_Silk_interpolate.c:28:10: fatal error: 'SKP_Silk_main.h' file not found
    #include "SKP_Silk_main.h"
    ^~~~~~~~~~~~~~~~~
    1 error generated.
    error: command '/usr/bin/clang' failed with exit code 1
    [end of output]

    note: This error originates from a subprocess, and is likely not a problem with pip.
    ERROR: Failed building wheel for pysilk_mod
    Building wheel for web.py (pyproject.toml) ... done


    Stored in directory: /Users/ylei/Library/Caches/pip/wheels/3b/25/2a/105d6a15df6914f4d15047691c6c28f9052cc1173e40285d03
    Building wheel for stringcase (setup.py) ... done
    Created wheel for stringcase: filename=stringcase-1.2.0-py3-none-any.whl size=3569 sha256=e18fc79a065d297d8f64f7084f2338866d53694ee47d1977b341bc38432580fc
    Stored in directory: /Users/ylei/Library/Caches/pip/wheels/b4/33/6d/d0820be98063da218c3206fbad2381cd2db3fbb1a0f0d254b5
    Successfully built web.py lxml opengraph-py3 wikipedia betterproto grpclib sgmllib3k stringcase
    Failed to build pysilk_mod
    ERROR: Could not build wheels for pysilk_mod, which is required to install pyproject.toml-based projects

    请问要怎么修改,才能继续安装?

    谢谢, dootbear

    1. zyj zyj

      你的python3和pip3版本是多少,更新pip3后试试呢

      1. 圆滚滚 圆滚滚

        src/silk/src/SKP_Silk_interpolate.c:28:10: fatal error: 'SKP_Silk_main.h' file not found
        #include "SKP_Silk_main.h"
        ^~~~~~~~~~~~~~~~~
        1 error generated.
        error: command '/usr/bin/clang' failed with exit code 1
        [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for pysilk_mod
        Failed to build pysilk_mod
        ERROR: Could not build wheels for pysilk_mod, which is required to install pyproject.toml-based projects
        jinlinghui@MacBook-Pro chatgpt-on-wechat %

        大佬,我也有这个问题,更新pip3之后也安装失败,请问怎么解决啊

  8. loong loong

    请求返回的时间是错误的。服务器在国外,服务器时间也是正确的。

    wechat_channel.py:173] - [WX] sendMsg=Reply(type=TEXT, content=[ChatGPT]: 非常抱歉,我的回答确实有误。我应该检查时区信息,以便在回答问题时提供正确的时间和日期。 根据中国标准时间,今天是2021年6月14日,是端午节。再次表示歉意并感谢您的指正。),

    1. zyj zyj

      目前chatgpt不支持获取网络数据的,可以关注下 tool 插件的接入

  9. 嘿嘿嘿 嘿嘿嘿

    能不能把这个接入qq呢 那个bot on everything 功能较少 wx小号不好搞 而且会被封

    1. zyj zyj

      插件准备合到bot-on-any了

  10. madision madision

    老哥,目前扫码封号的问题可以解决吗

    1. zyj zyj

      这个目前没有好办法

  11. takuya takuya

    大佬,这个好像默认是 gpt-3,要怎么改成 gpt- 3.5?需要去官网购买吗?还是改代码?

    1. zyj zyj

      目前最新代码默认使用的就是gpt-3.5模型

  12. 鄂西北的风 鄂西北的风

    大佬,企业微信版本的什么时候出来呀?急求呀 或者有没有类似的接入企业微信的推送下 万分感谢

    1. zyj zyj

      看看这个:https://github.com/mostlittlebee/chatgpt-on-wecom

  13. 小也子 小也子

    1.卸载了itchat,itchat-uos=1.5.
    [ERROR][2023-03-09 15:31:31][app.py:19] - App startup failed!
    [ERROR][2023-03-09 15:31:31][app.py:20] - mismatched tag: line 64, column 4
    Traceback (most recent call last):
    File "E:\chatgpt-on-wechat\chatgpt-on-wechat-master\app.py", line 17, in
    channel.startup()
    File "E:\chatgpt-on-wechat\chatgpt-on-wechat-master\channel\wechat\wechat_channel.py", line 37, in startup
    itchat.auto_login(enableCmdQR=2)
    File "E:\python\lib\site-packages\itchat\components\register.py", line 35, in auto_login
    self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,
    File "E:\python\lib\site-packages\itchat\components\login.py", line 53, in login
    status = self.check_login()
    File "E:\python\lib\site-packages\itchat\components\login.py", line 137, in check_login
    if process_login_info(self, r.text):
    File "E:\python\lib\site-packages\itchat\components\login.py", line 172, in process_login_info
    for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
    File "E:\python\lib\xml\dom\minidom.py", line 2000, in parseString
    return expatbuilder.parseString(string)
    File "E:\python\lib\xml\dom\expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
    File "E:\python\lib\xml\dom\expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
    xml.parsers.expat.ExpatError: mismatched tag: line 64, column 4

    1. zyj zyj

      卸载后要重新安装 itchat-uos=1.5.0.dev0

      1. 小也子 小也子

        itchat-uos是1.5.0版本的

      2. 小也子 小也子

        对于代理ip能出一个教程吗,有点迷糊

        1. zyj zyj

          https://github.com/zhayujie/chatgpt-on-wechat/issues/351

          1. 小也子 小也子

            itchat-uos卸载重装还是一样的错误

  14. ZzYun ZzYun

    微信扫完码报错,已实名,
    itchat : 1.3.10
    itchat-uos : 1.5.0.dev0
    python:3.9.13
    pip:23.0.1
    错误:
    Please scan the QR code to log in.
    Please press confirm on your phone.
    [ERROR][2023-03-06 23:01:37][app.py:19] - App startup failed!
    [ERROR][2023-03-06 23:01:37][app.py:20] - mismatched tag: line 64, column 4
    Traceback (most recent call last):
    File "C:\Users\zzy\chatgpt-on-wechat\app.py", line 17, in
    channel.startup()
    File "C:\Users\zzy\chatgpt-on-wechat\channel\wechat\wechat_channel.py", line 37, in startup
    itchat.auto_login(enableCmdQR=2)
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\register.py", line 35, in auto_login
    self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 54, in login
    status = self.check_login()
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 138, in check_login
    if process_login_info(self, r.text):
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 173, in process_login_info
    for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\xml\dom\minidom.py", line 1998, in parseString
    return expatbuilder.parseString(string)
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\xml\dom\expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
    File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\xml\dom\expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
    xml.parsers.expat.ExpatError: mismatched tag: line 64, column 4

    1. 小也子 小也子

      解决了嘛,老哥

    2. zyj zyj

      参考这个 https://github.com/zhayujie/chatgpt-on-wechat/issues/333

      1. ZzYun ZzYun

        大佬,我把itchat卸载后,报错[ERROR][2023-03-07 13:42:07][app.py:19] - App startup failed!
        [ERROR][2023-03-07 13:42:07][app.py:20] - No module named 'itchat'
        Traceback (most recent call last):
        File "C:\Users\zzy\chatgpt-on-wechat\app.py", line 14, in
        channel = channel_factory.create_channel("wx")
        File "C:\Users\zzy\chatgpt-on-wechat\channel\channel_factory.py", line 12, in create_channel
        from channel.wechat.wechat_channel import WechatChannel
        File "C:\Users\zzy\chatgpt-on-wechat\channel\wechat\wechat_channel.py", line 6, in
        import itchat
        ModuleNotFoundError: No module named 'itchat'

        1. 你好openai代理怎么配置 你好openai代理怎么配置

          你好openai代理怎么配置

        2. zyj zyj

          把 itchat-uos==1.5.0.dev0 卸载了然后 重装下

          1. ZzYun ZzYun

            大佬,找到问题了,我号被封了...

            1. 小也子 小也子

              您的问题解决了吗

              1. 小也子 小也子

                方便加个联系方式沟通一下吗

              2. ZzYun ZzYun

                解决了

          2. ZzYun ZzYun

            重装itchat后,扫码又出一个二维码,在itchat/components/login.py 的while not isLoggedIn 循环前增加一个time.sleep(15)
            扫完码又报错
            [ERROR][2023-03-07 16:30:52][app.py:19] - App startup failed!
            [ERROR][2023-03-07 16:30:52][app.py:20] - list index out of range
            Traceback (most recent call last):
            File "C:\Users\zzy\chatgpt-on-wechat\app.py", line 17, in
            channel.startup()
            File "C:\Users\zzy\chatgpt-on-wechat\channel\wechat\wechat_channel.py", line 37, in startup
            itchat.auto_login(enableCmdQR=2)
            File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\register.py", line 35, in auto_login
            self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,
            File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 61, in login
            status = self.check_login()
            File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 152, in check_login
            if process_login_info(self, r.text):
            File "C:\Users\zzy\AppData\Local\Programs\Python\Python39\lib\site-packages\itchat\components\login.py", line 197, in process_login_info
            skey = re.findall('

            (.*?)

            ', r.text, re.S)[0]
            IndexError: list index out of range

  15. 李明 李明

    作者有考虑加入多个character desc热启动的功能吗,直接在聊天窗口切换模式

  16. 123 123

    openai.error.InvalidRequestError: This model's maximum context length is 4096 tokens. However, you requested 4164 tokens (68 in the messages, 4096 in the completion). Please reduce the length of the messages or completion.

    1. zyj zyj

      参考 https://github.com/zhayujie/chatgpt-on-wechat/issues/343

  17. 大佬方便加微信不 大佬方便加微信不

    大佬方便加微信不

    1. 小也子 小也子

      老哥解决了吗

      1. LLL LLL

        谢谢。

      2. LLL LLL

        执行:python3 app.py后
        [INFO][2023-03-15 23:06:01][config.py:19] - [INIT] load config: {'image_create_prefix': ['画', '看', '找'], 'open_ai_api_key': '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', 'conversation_max_tokens': 1000, 'proxy': '', 'single_chat_prefix': ['bot', '@bot'], 'voice_reply_voice': False, 'speech_recognition': False, 'group_chat_prefix': ['@bot'], 'group_name_white_list': ['ALL_GROUP'], 'single_chat_reply_prefix': '[bot] ', 'character_desc': '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。', 'wechaty_puppet_service_token': '', 'expires_in_seconds': 3600, 'baidu_api_key': '', 'baidu_app_id': '', 'baidu_secret_key': ''}
        [ERROR][2023-03-15 23:06:01][app.py:19] - App startup failed!
        [ERROR][2023-03-15 23:06:01][app.py:20] - invalid syntax (contact.py, line 377)
        Traceback (most recent call last):
        File "app.py", line 14, in
        channel = channel_factory.create_channel("wx")
        File "/root/chatgpt-on-wechat/channel/channel_factory.py", line 12, in create_channel
        from channel.wechat.wechat_channel import WechatChannel
        File "/root/chatgpt-on-wechat/channel/wechat/wechat_channel.py", line 7, in
        import itchat
        File "/usr/local/lib/python3.5/dist-packages/itchat/__init__.py", line 8, in
        from itchat.components import load_components
        File "/usr/local/lib/python3.5/dist-packages/itchat/components/__init__.py", line 1, in
        from .contact import load_contact
        File "/usr/local/lib/python3.5/dist-packages/itchat/components/contact.py", line 377
        url = f"{self.loginInfo['url']}/webwxverifyuser?r={int(time.time())}&pass_ticket={self.loginInfo['pass_ticket']}"
        ^
        SyntaxError: invalid syntax

        请问下这个怎么解决吗。感谢

        1. zyj zyj

          python3.5版本太低了,升级到 3.7~3.9吧

      3. LLL LLL

        执行:python3 app.py后
        [INFO][2023-03-15 23:06:01][config.py:19] - [INIT] load config: {'image_create_prefix': ['画', '看', '找'], 'open_ai_api_key': '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', 'conversation_max_tokens': 1000, 'proxy': '', 'single_chat_prefix': ['bot', '@bot'], 'voice_reply_voice': False, 'speech_recognition': False, 'group_chat_prefix': ['@bot'], 'group_name_white_list': ['ALL_GROUP'], 'single_chat_reply_prefix': '[bot] ', 'character_desc': '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。', 'wechaty_puppet_service_token': '', 'expires_in_seconds': 3600, 'baidu_api_key': '', 'baidu_app_id': '', 'baidu_secret_key': ''}
        [ERROR][2023-03-15 23:06:01][app.py:19] - App startup failed!
        [ERROR][2023-03-15 23:06:01][app.py:20] - invalid syntax (contact.py, line 377)
        Traceback (most recent call last):
        File "app.py", line 14, in
        channel = channel_factory.create_channel("wx")
        File "/root/chatgpt-on-wechat/channel/channel_factory.py", line 12, in create_channel
        from channel.wechat.wechat_channel import WechatChannel
        File "/root/chatgpt-on-wechat/channel/wechat/wechat_channel.py", line 7, in
        import itchat
        File "/usr/local/lib/python3.5/dist-packages/itchat/__init__.py", line 8, in
        from itchat.components import load_components
        File "/usr/local/lib/python3.5/dist-packages/itchat/components/__init__.py", line 1, in
        from .contact import load_contact
        File "/usr/local/lib/python3.5/dist-packages/itchat/components/contact.py", line 377
        url = f"{self.loginInfo['url']}/webwxverifyuser?r={int(time.time())}&pass_ticket={self.loginInfo['pass_ticket']}"
        ^
        SyntaxError: invalid syntax

        请问下这个怎么解决吗。感谢

  18. 秋叶 秋叶

    请问作者大哥,能不能再出一个能运行在openwrt系统里的版本,如果,可以运行在openwrt里,将会迎来一次大的提升

    1. zyj zyj

      可以加入计划

  19. 牛,可以入群吗

  20. 真的很强!

    ChatGPT也是,体验了一番太强了!

    1. 小也子 小也子

      方便给个练习方式吗

  21. [...]文章链接: https://zhayujie.com/chatgpt-on-wechat.html Github仓库:https://github.com/zhayujie/chatgpt-on-wechat[...]

  22. lll lll

    Start auto replying.
    [ERROR][2023-02-10 13:52:49][wechat_channel.py:116] - No module named 'openai'
    Traceback (most recent call last):
    File "E:\Py\pythonProject1\channel\wechat\wechat_channel.py", line 112, in _do_send
    reply_text = super().build_reply_content(query, context)
    File "E:\Py\pythonProject1\channel\channel.py", line 31, in build_reply_content
    return Bridge().fetch_reply_content(query, context)
    File "E:\Py\pythonProject1\bridge\bridge.py", line 9, in fetch_reply_content
    return bot_factory.create_bot("openAI").reply(query, context)
    File "E:\Py\pythonProject1\bot\bot_factory.py", line 24, in create_bot
    from bot.openai.open_ai_bot import OpenAIBot
    File "E:\Py\pythonProject1\bot\openai\open_ai_bot.py", line 6, in
    import openai
    ModuleNotFoundError: No module named 'openai'
    怎么解决的???

    1. zyj zyj

      这是openai没有安装,pip3 show openai看一下,没有的话执行

      pip3 install --upgrade openai

      1. lll lll

        /usr/lib/python3/dist-packages/setuptools/dist.py:723: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
        warnings.warn(
        Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 419, in _parse_attr
        return getattr(StaticModule(module_name), attr_name)
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 26, in __init__
        spec = importlib.util.find_spec(name)
        File "/usr/lib/python3.10/importlib/util.py", line 94, in find_spec
        parent = __import__(parent_name, fromlist=['__path__'])
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/__init__.py", line 9, in
        from openai.api_resources import (
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/__init__.py", line 1, in
        from openai.api_resources.completion import Completion # noqa: F401
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/completion.py", line 4, in
        from openai.api_resources.abstract import DeletableAPIResource, ListableAPIResource
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/abstract/__init__.py", line 3, in
        from openai.api_resources.abstract.api_resource import APIResource
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/abstract/api_resource.py", line 4, in
        from openai import api_requestor, error, util
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_requestor.py", line 21, in
        import aiohttp
        ModuleNotFoundError: No module named 'aiohttp'

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in
        main()
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
        return hook(config_settings)
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
        return self._get_build_requires(
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 143, in _get_build_requires
        self.run_setup()
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 158, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 3, in
        setup()
        File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/core.py", line 122, in setup
        dist.parse_config_files()
        File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 804, in parse_config_files
        parse_configuration(
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 158, in parse_configuration
        meta.parse()
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 498, in parse
        section_parser_method(section_options)
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 469, in parse_section
        self[name] = value
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 222, in __setitem__
        value = parser(value)
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 599, in _parse_version
        version = self._parse_attr(value, self.package_dir)
        File "/usr/lib/python3/dist-packages/setuptools/config.py", line 422, in _parse_attr
        module = importlib.import_module(module_name)
        File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
        File "", line 1050, in _gcd_import
        File "", line 1027, in _find_and_load
        File "", line 992, in _find_and_load_unlocked
        File "", line 241, in _call_with_frames_removed
        File "", line 1050, in _gcd_import
        File "", line 1027, in _find_and_load
        File "", line 1006, in _find_and_load_unlocked
        File "", line 688, in _load_unlocked
        File "", line 883, in exec_module
        File "", line 241, in _call_with_frames_removed
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/__init__.py", line 9, in
        from openai.api_resources import (
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/__init__.py", line 1, in
        from openai.api_resources.completion import Completion # noqa: F401
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/completion.py", line 4, in
        from openai.api_resources.abstract import DeletableAPIResource, ListableAPIResource
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/abstract/__init__.py", line 3, in
        from openai.api_resources.abstract.api_resource import APIResource
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_resources/abstract/api_resource.py", line 4, in
        from openai import api_requestor, error, util
        File "/tmp/pip-install-liwnd95m/openai_26aa7405968e4fe48cdd08d6aac568f5/openai/api_requestor.py", line 21, in
        import aiohttp
        ModuleNotFoundError: No module named 'aiohttp'
        现在是这样

        1. lll lll

          我是 服务器的

          1. zyj zyj

            更新下 pip 再安装openai试试

            你的python3 -V 版本是多少?

  23. jayhwqjay jayhwqjay

    大佬,我根据公司常用FAQ案例训练了下机器人。我在https://platform.openai.com/playground页面可以选择到自己训练的模型,输出问题能得到对应的答复。但是在我们这个代码里面需要怎么配置下才能读到我训练后的model?期待大佬的回复。

  24. momo momo

    大佬登录失败,报这个错误怎么解决。[ERROR][2023-02-13 11:43:58][app.py:19] - App startup failed!
    [ERROR][2023-02-13 11:43:58][app.py:20] - list index out of range
    Traceback (most recent call last):
    File "app.py", line 17, in
    channel.startup()
    File "/home/chatgpt-on-wechat/channel/wechat/wechat_channel.py", line 37, in startup
    itchat.auto_login(enableCmdQR=2)
    File "/usr/local/python3/lib/python3.7/site-packages/itchat/components/register.py", line 36, in auto_login
    loginCallback=loginCallback, exitCallback=exitCallback)
    File "/usr/local/python3/lib/python3.7/site-packages/itchat/components/login.py", line 60, in login
    status = self.check_login()
    File "/usr/local/python3/lib/python3.7/site-packages/itchat/components/login.py", line 151, in check_login
    if process_login_info(self, r.text):
    File "/usr/local/python3/lib/python3.7/site-packages/itchat/components/login.py", line 196, in process_login_info
    skey = re.findall('

    (.*?)

    ', r.text, re.S)[0]
    IndexError: list index out of range

    1. TACO TACO

      我也出现了,后来发现是微信没实名认证

  25. 海星 海星

    可以切换其他的对话模型吗

    1. zyj zyj

      可以在 bot/openai/open_ai_bot.py 中修改,目前使用的text-davinci-003是官方接口中效果最好的

  26. 123 123

    怎么都是自己回复自己,不是机器人回复?

  27. bob bob

    请问为什么登录用的微信号为什么必须要实名?

    1. zyj zyj

      itchat依赖微信网页版,不实名用不了

  28. Hotdog Hotdog

    Start auto replying.
    [ERROR][2023-02-10 13:52:49][wechat_channel.py:116] - No module named 'openai'
    Traceback (most recent call last):
    File "E:\Py\pythonProject1\channel\wechat\wechat_channel.py", line 112, in _do_send
    reply_text = super().build_reply_content(query, context)
    File "E:\Py\pythonProject1\channel\channel.py", line 31, in build_reply_content
    return Bridge().fetch_reply_content(query, context)
    File "E:\Py\pythonProject1\bridge\bridge.py", line 9, in fetch_reply_content
    return bot_factory.create_bot("openAI").reply(query, context)
    File "E:\Py\pythonProject1\bot\bot_factory.py", line 24, in create_bot
    from bot.openai.open_ai_bot import OpenAIBot
    File "E:\Py\pythonProject1\bot\openai\open_ai_bot.py", line 6, in
    import openai
    ModuleNotFoundError: No module named 'openai'

    1. Hotdog Hotdog

      解决了

      1. chat chat

        怎么解决呢

        1. zyj zyj

          安装下openai模块,注意对应的pip3是不是和用来运行程序的python3一致

  29. cr130 cr130

    感谢大佬,蛮有趣的。
    登录成功后,一段时间未@使用,不再回复,需要重新登录(只发生过一次这种)

    1. zyj zyj

      一般不会出现,可以贴一下报错

      1. 小也子 小也子

        itchat卸载了 itchat-uos版本1.5.0
        [ERROR][2023-03-09 15:31:31][app.py:19] - App startup failed!
        [ERROR][2023-03-09 15:31:31][app.py:20] - mismatched tag: line 64, column 4
        Traceback (most recent call last):
        File "E:\chatgpt-on-wechat\chatgpt-on-wechat-master\app.py", line 17, in
        channel.startup()
        File "E:\chatgpt-on-wechat\chatgpt-on-wechat-master\channel\wechat\wechat_channel.py", line 37, in startup
        itchat.auto_login(enableCmdQR=2)
        File "E:\python\lib\site-packages\itchat\components\register.py", line 35, in auto_login
        self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,
        File "E:\python\lib\site-packages\itchat\components\login.py", line 53, in login
        status = self.check_login()
        File "E:\python\lib\site-packages\itchat\components\login.py", line 137, in check_login
        if process_login_info(self, r.text):
        File "E:\python\lib\site-packages\itchat\components\login.py", line 172, in process_login_info
        for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
        File "E:\python\lib\xml\dom\minidom.py", line 2000, in parseString
        return expatbuilder.parseString(string)
        File "E:\python\lib\xml\dom\expatbuilder.py", line 925, in parseString
        return builder.parseString(string)
        File "E:\python\lib\xml\dom\expatbuilder.py", line 223, in parseString
        parser.Parse(string, True)
        xml.parsers.expat.ExpatError: mismatched tag: line 64, column 4
        是什么情况呢

  30. ahui ahui

    项目中使用的对话模型是 davinci,计费方式是每1k字 (包含请求和回复) 消耗 $0.02,图片生成是每张消耗 $0.016,账号创建有免费的 $18 额度,使用完可以更换邮箱重新注册。

    这个收费是什么意思啊?是OpenAI收的吗?更换邮箱重新注册是指重新注册OpenAI账号吗?

    1. zyj zyj

      调用openai接口的费用。是的,免费额度用完了要么充值要么重新注册

  31. 私聊可回复,群聊不论是@还是@bot都没有反应,前缀都是对的,都无效。

    1. zyj zyj

      config.json中group_name_white_list有配置吗

  32. leuoson leuoson

    你好,我成功的在本机上运行完成了,但是每当我需要画一个东西,openapi会回复,他自己不支持画图,我看了我的配置:"image_create_prefix": ["画", "看", "找"],是正确的

    1. zyj zyj

      你收到的消息是怎么样的,需要类似这样的格式: "画一张图"

  33. aa aa

    扫码登录的时候等了5s , 点继续登录没啥反应,应该是没登录上,重新扫第一个码登录也是登录补上

    1. zyj zyj

      看这个issue: https://github.com/zhayujie/chatgpt-on-wechat/issues/8

  34. clown clown

    "single_chat_prefix": ["", "@bot"]这样可以取消前缀吗

    1. zyj zyj

      可以的, 或者这样 "single_chat_prefix": [""],

  35. aa aa

    不能取消前缀吗

  36. 小明 小明

    国内网,扫二维码之后没有反应,是需要国外的VPN吗

    1. aa aa

      同问,扫码没反应

      1. zyj zyj

        扫码后登录成功了吗? 参考:https://github.com/zhayujie/chatgpt-on-wechat/issues/142

        不过现在登录有风险,先不要尝试了

  37. Hotdog Hotdog

    二维码扫描后出现报错'wxsid'
    已经安装itchat和itchat-uos

    1. zyj zyj

      itchat可以先卸载。 只安装 itchat-uos就好,并且确保版本是 1.5.0.dev0

  38. momo momo

    大佬今天用pip3 install openai==0.25.0,安装OpenAI的时候 找不到0.25.0的版本是为什么?(国外的服务器)

    Could not find a version that satisfies the requirement openai==0.25.0 (from versions: 0.0.2, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.2.1, 0.2.3, 0.2.4, 0.2.5, 0.2.6, 0.3.0, 0.4.0, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5)
    No matching distribution found for openai==0.25.0

    1. zyj zyj

      1. openai安装问题: 一般是python版本太低,参考 https://github.com/zhayujie/chatgpt-on-wechat/issues/94

      2.需要国内服务器

      1. momo momo

        好的 谢谢大佬

        1. ys ys

          请问运行的时候出现以下错误,有办法解决吗?谢谢~
          ERROR][2023-03-21 02:57:35][app.py:19] - App startup failed!
          [ERROR][2023-03-21 02:57:35][app.py:20] - Expecting value: line 10 column 26 (char 337)
          Traceback (most recent call last):
          File "app.py", line 11, in
          config.load_config()
          File "/root/chatgpt-on-wechat/config.py", line 18, in load_config
          config = json.loads(config_str)
          File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
          return _default_decoder.decode(s)
          File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
          obj, end = self.raw_decode(s, idx=_w(s, 0).end())
          File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
          raise JSONDecodeError("Expecting value", s, err.value) from None
          json.decoder.JSONDecodeError: Expecting value: line 10 column 26 (char 337)

          1. zyj zyj

            config.json配置文件内容格式存在问题,可以把内容复制到 https://json.cn 中进行校验

  39. 君莫笑 君莫笑

    老师您微信加不上,提示被搜索过多,还有其他方式加您吗

  40. 海星 海星

    网页版微信无法登陆 有没有什么好办法呢

    1. zyj zyj

      目前依赖网页版,暂时没好办法。

      1. 海星 海星

        从3.11降到3.7.8就可以了 还发现ubantu部署要更新openssl这个是比较麻烦的 可以提醒一下其他人

  41. 大佬 大佬

    扫码后的微信不想当机器人怎么取消呢?
    就是把成功后的机器人还原为最初的微信

    1. zyj zyj

      把程序关掉就行了, 如果是本地的话直接 ctrl+c, 如果是服务器后台部署就kill掉进程

      1. 小明 小明

        老师您好,我扫码没反应,是因为用的国内网吗,请指教

    2. zyj zyj

      把程序关掉就行了, 如果是本地的话直接 ctrl+c, 如果是服务器后台部署就kill掉进程

      1. Yuanyuan Yuanyuan

        嗷嗷谢谢大佬
        "single_chat_reply_prefix": "[bot] ", # 私聊时自动回复的前缀,用于区分真人
        这个前缀在群聊中并没有体现出来捏?是哪里不太对吗,没有报错

        1. zyj zyj

          群聊的回复前缀配置是 group_chat_reply_prefix ,用法相同

  42. WT WT

    请问这个二维码通过微信扫不出来有什么好办法解决吗

    1. zyj zyj

      可以先在 https://github.com/zhayujie/chatgpt-on-wechat/issues 提一个issue哈,贴一下python版本、操作系统环境,以及二维码的样式截图

  43. Poppy Poppy

    请问这个后台设置成了自动默认中文回复吗?

    1. zyj zyj

      因为默认设定就是用中文的,你可以自定义这个配置,参考: https://github.com/zhayujie/chatgpt-on-wechat/issues/45

  44. 毛毛 毛毛

    你好,我今天运行了你的项目,刚开始一切都很顺利,能正常运行,但是当接收到微信消息的时候就出错了,错误反馈是openAI的API Kye错误
    [ERROR][2023-02-05 19:47:11][open_ai_bot.py:49] - Incorrect API key provided: YOUR API KEY. You can find your API key at https://platform.openai.com/account/api-keys.

    1. zyj zyj

      1.二维码刷新问题: 首先要确认下修改的login.py文件的路径 在你用于运行项目 python3的site-packages嘛?另外,加上sleep 15s 以后仅对第一个二维码生效,如果第一个没扫上就ctrl+c关掉程序,重新启动。 15s应该是比较容易扫上的

      2.这个问题在今天最新的版本解决了,可以获取下最新代码, 问题原因在这 https://github.com/zhayujie/chatgpt-on-wechat/issues/50

    2. 毛毛 毛毛

      已经解决了,是我的openAI key没有填对

    3. zyj zyj

      这个原因是你需要在 config.json 中填写你在 openai 官网申请的 api_key,参考上文中 "快速开始-准备" 一节

      1. 毛毛 毛毛

        你好,现在是这样的情况,
        1.现在时不时会自己掉线,出现这个报错;requests.exceptions.ProxyError: HTTPSConnectionPool(host='wx.qq.com', port=443): Max retries exceeded with url: /cgi-bin/mmwebwx-bin/webwxsync?sid=RyP5dKvbwBeTygyf&skey=@crypt_b627fd3e_45af7f94b1adf9cf32054675039871b8&pass_ticket=SZu8en6Wws%2FCrdkzwlRSuQQJHnXOsOGLlJJYrXyzY7tl%2FyD1wDQfMFhJ9IRO1Wcn (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
        2.有时候没有任何保证错,但是等很久chatGTP就是没有任何反馈,
        请问你有遇到以上这两种情况吗?

        1. zyj zyj

          1.第一个问题,确认下有没有开代理,如果开了要关掉
          2.没有反馈可以先看下终端是否有日志,如果没有任何输出可能是 对话中没有关键词触发

          如果还是有问题,可以加微信 eijuyahz 交流

          1. 毛毛 毛毛

            1.对于第一个问题,是必须要开代理的,因为chatGTP在国内不开放,而且我发现,如果不开代理,微信扫码就会一直登不上,扫一次会另外弹出来一个二维码,同时反馈信息:Please scan the QR code to log in.
            Please press confirm on your phone.
            Log in time out, reloading QR code.
            Getting uuid of QR code.
            Downloading QR code.
            2.对于第2个问题,已经发生很多次,每次都卡住不动,只能重启程序;确定是通过手机端微信带关键词触发的,但是终端一直没有响应,既没有收到来自手机端的关键词,也没有收到来自服务器的反馈

            1. zyj zyj

              1.这个方案用的是openai的官方api,国内外都能访问;但是连接wx必须要求国内网络,所以需要把代理关掉。

              扫一次弹出来第二个二维码的问题,参考:https://github.com/zhayujie/chatgpt-on-wechat/issues/8 , 改一行代码可以解决问题

              2.第一个问题解决后,第二个问题应该也能解决了

              1. 毛毛 毛毛

                1.第一个问题我按照你的方法,把代理关了,然后在login.py 的59行添加了time.sleep(15),重启VScode后执行app.py,但是还是会出现扫一次弹一个新的二维码,我尝试了4次才成功,成功运行后,问了几个问题测试,结果又出错了,以下是报错日志:
                [ERROR][2023-02-06 22:12:06][open_ai_bot.py:49] - The server had an error while processing your request. Sorry about that!
                Traceback (most recent call last):
                File "d:\python project\chatgpt-on-wechat\bot\openai\open_ai_bot.py", line 37, in reply_text
                response = openai.Completion.create(
                ^^^^^^^^^^^^^^^^^^^^^^^^^
                File "F:\python3\Lib\site-packages\openai\api_resources\completion.py", line 25, in create
                return super().create(*args, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "F:\python3\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 115, in create
                response, _, api_key = requestor.request(
                ^^^^^^^^^^^^^^^^^^
                File "F:\python3\Lib\site-packages\openai\api_requestor.py", line 181, in request
                resp, got_stream = self._interpret_response(result, stream)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "F:\python3\Lib\site-packages\openai\api_requestor.py", line 396, in _interpret_response
                self._interpret_response_line(
                File "F:\python3\Lib\site-packages\openai\api_requestor.py", line 429, in _interpret_response_line
                raise self.handle_error_response(
                openai.error.RateLimitError: The server had an error while processing your request. Sorry about that!
                [ERROR][2023-02-06 22:12:06][wechat_channel.py:116] - object of type 'NoneType' has no len()
                Traceback (most recent call last):
                File "d:\python project\chatgpt-on-wechat\channel\wechat\wechat_channel.py", line 112, in _do_send
                reply_text = super().build_reply_content(query, context).strip()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "d:\python project\chatgpt-on-wechat\channel\channel.py", line 31, in build_reply_content
                return Bridge().fetch_reply_content(query, context)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "d:\python project\chatgpt-on-wechat\bridge\bridge.py", line 9, in fetch_reply_content
                return bot_factory.create_bot("openAI").reply(query, context)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "d:\python project\chatgpt-on-wechat\bot\openai\open_ai_bot.py", line 29, in reply
                Session.save_session(query, reply_content, from_user_id)
                File "d:\python project\chatgpt-on-wechat\bot\openai\open_ai_bot.py", line 150, in save_session
                Session.discard_exceed_conversation(user_session[user_id], max_tokens)
                File "d:\python project\chatgpt-on-wechat\bot\openai\open_ai_bot.py", line 160, in discard_exceed_conversation
                count += len(history_conv["question"]) + len(history_conv["answer"])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
                TypeError: object of type 'NoneType' has no len()

  45. 行遇书 行遇书

    扫码登录后报错

    Please scan the QR code to log in.
    Please press confirm on your phone.
    [ERROR][2023-02-05 18:26:11][app.py:19] - App startup failed!
    [ERROR][2023-02-05 18:26:11][app.py:20] - mismatched tag: line 64, column 4
    Traceback (most recent call last):
    File "app.py", line 17, in
    channel.startup()
    File "/Users/xuedongfeng/PycharmProjects/chatGPT2wechat/chatgpt-on-wechat/channel/wechat/wechat_channel.py", line 37, in startup
    itchat.auto_login(enableCmdQR=2)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/itchat/components/register.py", line 34, in auto_login
    self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/itchat/components/login.py", line 48, in login
    status = self.check_login()
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/itchat/components/login.py", line 131, in check_login
    process_login_info(self, r.text)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/itchat/components/login.py", line 164, in process_login_info
    for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/xml/dom/minidom.py", line 1969, in parseString
    return expatbuilder.parseString(string)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
    xml.parsers.expat.ExpatError: mismatched tag: line 64, column 4

    1. zyj zyj

      可以检查下是否安装了 itchat-uos,以及版本是否为 1.5.0.dev0 (执行 pip3 show itchat-uos)。

      以及当前网络是否正常, 确认没有使用代理

      1. 行遇书 行遇书

        好的,检查了,因为安装了多个版本的python3导致了这个问题,已经解决了,感谢;

  46. [...]链接:https://zhayujie.com/chatgpt-on-wechat.html[...]

  47. 1 1

    大佬,为什么我的登录了却没有反应?

    1. 啊哈 啊哈

      不存在能不能,胆,大小胆,大胆想法,有误,大小,能力,对话不对话等,其只是个机器,除你等不管怎么想,说,做,可想,说,做无限任何任何都完美

    2. zyj zyj

      登录后日志有什么输出嘛

  48. 123 123

    源码

    1. zyj zyj

      源码见Github: https://github.com/zhayujie/chatgpt-on-wechat

  49. [...]链接: https://zhayujie.com/chatgpt-on-wechat.html[...]

添加新评论