使用docker部署chatgpt-on-wechat

目标:能够调用文心一言接口并回复微信公众号的信息

最终效果

chatgpt-on-wechat 部署

下载代码

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

docker部署

docker run -tdi --name gpt -v /data/chatgpt-on-wechat:/data/chatgpt-on-wechat python:3.8.1 bash

修改配置

docker exec -ti gpt bash
cd /data/chatgpt-on-wechat/
cp config-template.json config.json
config.json配置如下:
{
  "use_baidu_wenxin": "True",
  "baidu_wenxin_model": "eb-instant",
  "baidu_wenxin_api_key": "文心一言的api_key",
  "baidu_wenxin_secret_key": "文心一言的secret_key",
  "channel_type": "wechatmp",
  "wechatmp_port": 80,
  "wechatmp_app_id": "微信公众号的app_id",
  "wechatmp_app_secret": "微信公众号的app_secret",
  "wechatmp_token": "微信公众号里配置的token",
  "wechatmp_aes_key": "微信公众号里配置的aes_key",
  "hot_reload": false,
  "single_chat_prefix": [""],
  "single_chat_reply_prefix": "",
  "group_chat_prefix": [
    "@bot"
  ],
  "group_name_white_list": [
    "None",
    "None2"
  ],
  "group_chat_in_one_session": [
    "None"
  ],
  "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 查看详细指令。",
  "use_linkai": false,
  "linkai_api_key": "",
  "linkai_app_code": ""
}

安装依赖

pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install -r requirements-optional.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install azure-cognitiveservices-speech -i https://pypi.tuna.tsinghua.edu.cn/simple

启动chatgpt-on-wechat

nohup python3 app.py & tail -f nohup.out

改行使用文心一言

注册文心千帆账号

创建百度智云应用

https://console.bce.baidu.com/ai/?_=1690337487675#/ai/wenxinworkshop/app/list


在应用列表能看见api key和secret key,配置到配置文件中。

注意,模型选择的时候要使用api最后的名字,不能使用模型名字,否则会调用失败
列入如果使用ernie-bot-turbo模型,在配置中要写eb-instant

对接微信公众号

申请微信公众号

申请地址:https://mp.weixin.qq.com/
申请好后,配置并启用服务器设置,红框中的信息用于配置后续的服务。注意这里需要把chatgpt-on-wechat服务映射到公网Ip的80端口。

proxy部署(不使用OPENAI或有海外服务器则不需要部署)

下载、配置proxy

mkdir -p /data/clash
cd /data/clash
wget https://github.com/Dreamacro/clash/releases/download/v1.17.0/clash-linux-amd64-v1.17.0.gz
gzip -d clash-linux-amd64-v1.17.0.gz
chmod a+x clash-linux-amd64-v1.17.0
./clash-linux-amd64-v1.17.0 -d /data/clash/

修改 /data/clash/config.yaml文件,配置文件参考

mixed-port: 7890
bind-address: '*'
allow-lan: true #监听0.0.0.0,使本机以外和容器也能访问
proxies:
  - name: "ssr"
    type: ssr
    server: "proxy的地址"
    port: proxy的端口
    cipher: proxy的加密方式
    password: proxy的密码
    obfs: 混淆
    obfs-param: "混淆参数"
    protocol: 协议
    plugin: ""
  - name: "ss"
    type: ss
    server: "proxy的地址"
    port: proxy的端口
    cipher: proxy的加密方式
    password: "proxy的密码"
enhanced-mode: fake-ip #不配置会报ssl异常

启动proxy

nohup ./clash-linux-amd64-v1.17.0 -f clash/config.yaml &

OPENAI使用失败

失败原因:不能用大陆的信用卡付费,需要使用美国信用卡。可以使用虚拟信用卡解决,但是存在封号风险,为了避免号被封,遂放弃。

azure使用失败

失败原因:需要有企业信息和企业邮箱才能注册,个人用户注册失败。

posted @ 2023-07-15 13:12  打个酱油6161  阅读(1509)  评论(0编辑  收藏  举报