openai的聊天机器人最近大火,上手试了试,和过去相比进步太多了
已失效 目前解决方案 Setup · acheong08/ChatGPT Wiki (github.com)
5分钟在QQ群搭建ChatGPT机器人! - Chris’s blog (chrisyy.top)
下面的操作可以在自己的虚拟机里弄,也可以在云服务器里弄
[ChatGPT] 使用Python对接OpenAi APi 实现智能QQ机器人(三) - 搭建QQ机器人 - Lucent’s Blog
跟进 Tag ““ does not correspond to any known ansi directive
更新到python3.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz tar -zxf Python-3.9.0.tgz cd Python-3.9.0sudo apt-get install libffi-devsudo apt-get install openssl./configure --prefix=/usr/local/python3 ./configure --enable-optimizations make && make install python3 -V
配置cqhttp 放在一个文件夹里
修改qq账号
修改ws-reverse
中universal
为 ws://127.0.0.1:8080/onebot/v11/ws
最后servers部分的配置
然后再次运行./go-cqhttp,完成登录后按Ctrl+A+D放到后台运行
框架设置 安装 1 2 3 4 5 6 7 8 9 mkdir ~/.pipvi ~/.pip/pip.conf 复制如下内容(阿里镜像源为例): [global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com
1 2 3 4 5 6 7 screen -S robot python3 --version 查看版本 python3 -m venv venv source venv/bin/activatepip3 install nb-cli pip3 install nonebot-adapter-onebot nb
按空格选择
测试
要与机器人互动,可以首先使用/echo
命令让其输出一些信息,斜杠/
是nonebot默认的命令起始符号,可以自定义设置。
安装插件 1 nb plugin install nonebot-plugin-chatgpt
修改配置 bot.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 import nonebotfrom nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter nonebot.init() app = nonebot.get_asgi() driver = nonebot.get_driver() driver.register_adapter(ONEBOT_V11Adapter) nonebot.load_builtin_plugins("echo" ) nonebot.load_from_toml("pyproject.toml" ) if __name__ == "__main__" : nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!" ) nonebot.run(app="__mp_main__:app" )
pyproject.toml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [tool.poetry] name = "bot" version = "0.1.0" description = "bot" authors = [] readme = "README.md" [tool.poetry.dependencies] python = "^3.7.3" nonebot2 = "^2.0.0-beta.1" [tool.poetry.dev-dependencies] nb-cli = "^0.6.0" [tool.nonebot] plugins = ["nonebot_plugin_chatgpt" ] plugin_dirs = ["bot/plugins" ] [build-system] requires = ["poetry_core>=1.0.0" ] build-backend = "poetry.core.masonry.api"
.env.dev
1 2 3 4 5 6 7 8 9 10 11 12 HOST=127.0.0.1 PORT=8080 LOG_LEVEL=DEBUG FASTAPI_RELOAD=true command_start=[""] CHATGPT_SESSION_TOKEN="xxx" # token信息 CHATGPT_COMMAND="。" # 触发聊天的命令 CHATGPT_TO_ME="False" # 是否需要@机器人 CHATGPT_CD_TIME="5"
token获取 打开https://chat.openai.com/chat
运行 1 2 3 screen -S qqrobot source venv/bin/activate nb run
完成后按Ctrl+A+D放到后台运行
1 screen -r qqrobot #打开qqrobot中断窗口
相关资料 参考网站 ChatGPT (openai.com)
5分钟在QQ群搭建ChatGPT机器人! - Chris’s blog (chrisyy.top)
运行框架 nonebot/awesome-nonebot: NoneBot 相关资源汇总 (github.com)
安装 | NoneBot
chrisyy2003/lingyin-bot (github.com)
插件 A-kirami/nonebot-plugin-chatgpt (github.com)
FokersBoolean/AliceBot (github.com)