前言
有个小兄弟在搭建ChatGPT,遇到了一些坑,所以这里我也搭建的一下,整个搭建的步骤也不难,但是API KEY调用的时候需要付费以及现在搭建的话还涉及到速率限制和被封号的风险,所以还是有面临的问题,机器人的话建议简单玩玩儿就行,有兴趣了还是本地化部署Web端。
两种方式
项目地址
目前最新的GPT版本对标的为3.5

环境准备
Linux服务器为Centos
python版本 python3
cd /usr/local
wget http://npm.taobao.org/mirrors/python/3.8.0/Python-3.8.0.tgz #下载python3.8安装包
tar -xzf Python-3.8.0.tgz
mkdir python3
cd python-3.8.0
./configure --prefix=/usr/local/python3
make #编译
make install #安装

安装成功后,添加软链接
ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
这里参数的话最好选择sf,强制执行,否则容易报错。
避坑指南
这里需要注意pip的版本,因为前面安装包失败所以更新了pip的版本,所以在安装的时候报错

pip的版本过高了,这里安装低版本的pip
python3 -m pip install pip==21.3.1

重新安装其余包

更新api版本
python3 -m pip install --upgrade openai

这里当前版本为0.27.4
配置文件修改
查看当前目录,修改json文件,按照要求进行修改
config.json文件内容示例
{
"open_ai_api_key": "YOUR API KEY", # 填入上面创建的 OpenAI API KEY
"model": "gpt-3.5-turbo", # 模型名称。当use_azure_chatgpt为true时,其名称为Azure上model deployment名称
"proxy": "127.0.0.1:7890", # 代理客户端的ip和端口
"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": ["画", "看", "找"], # 开启图片回复的前缀
"conversation_max_tokens": 1000, # 支持上下文记忆的最多字符数
"speech_recognition": false, # 是否开启语音识别
"group_speech_recognition": false, # 是否开启群组语音识别
"use_azure_chatgpt": false, # 是否使用Azure ChatGPT service代替openai ChatGPT service. 当设置为true时需要设置 open_ai_api_base,如 https://xxx.openai.azure.com/
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", # 人格描述,
}
这里openAI API KEY为openapi中的key,前提是有openai的账号。
详细的配置可以参考


启动
OpenAPI登录创建api密钥

修改配置文件内容,添加api key
centos服务器安装v2ray客户端
{
"inbounds": [
{
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true
}
}
],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "xx.xx.xx.xx",
"port": xxx,
"users": [
{
"id": "xxxxxxxxxx",
"alterId": 64
}
]
}
]
},
"streamSettings": {
"network": "<network>",
"security": "<security>",
"tlsSettings": {},
"tcpSettings": {},
"kcpSettings": {},
"wsSettings": {},
"httpSettings": {},
"quicSettings": {}
}
}
]
}
}
事实证明这个ai的配置文件修改太麻烦了,直接自己导出配置文件比较香

右键导出客户端配置文件,上传到v2ray的客户端中,

检查配置文件
./v2ray test ./config.json



启动项目之后,使用微信扫码登录,该微信即变为了AI机器人


回显是正常的,这里发现openai对于这种请求做了限制,直接限制了速率。

限制了速率,需付费使用,付费使用应该没什么问题,就是比较贵,另外最大的问题是TX“封号”。
参考文章