基础环境
系统基本信息
- Windows 11 家庭中文版
- 处理器:Intel® Core™ i7-8750H CPU @ 2.20GHz 2.21 GHz
- 内存:16.0 GB (15.9 GB 可用)
软件版本
- 显卡驱动版本
-
Anaconda Version:4.5.11
-
Docker Version:Docker version 25.0.3, build 4debf41
-
docker-compose Version:Docker Compose version v2.24.6-desktop.1
开始部署
显卡驱动
参考:win11配置深度学习环境GPU - 知乎 (zhihu.com)
对应版本pytorch :Previous PyTorch Versions | PyTorch
我这里是:
pip install torch==1.10.0+cu102 torchvision==0.11.0+cu102 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
下载模型
安装git和git-lfs
yum -y install git git-lfs
拉取运行模型代码
git clone https://github.com/THUDM/ChatGLM3.git
拉取模型
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
git clone https://www.modelscope.cn/Xorbits/bge-large-zh-v1.5.git
修改配置文件openai_api_demo
目录下
- api_server.py
# set LLM path
MODEL_PATH = os.environ.get('MODEL_PATH', 'D:\\Code\\Github\\ChatGLM3\\chatglm3-6b')
# set Embedding Model path
EMBEDDING_PATH = os.environ.get('EMBEDDING_PATH', 'D:\\Code\\Github\\ChatGLM3\\bge-large-zh-v1.5')
- requirements.txt
删除 torch>=2.1.0 (因为咱们这里用 GPU,手动安装)
安装依赖
安装完成后 启动api_server.py
cd D:\Code\Github\ChatGLM3\openai_api_demo
python api_server.py
部署m3e模型
docker run -d -p 6008:6008 --name=m3e-large-api registry.cn-hangzhou.aliyuncs.com/fastgpt_docker/m3e-large-api:latest
部署one-api
docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v D:/docker/one-api/data:/data justsong/one-api
登录one-api
地址:http://192.168.18.216:3000/
账号:root
密码:123456
添加chatglm3渠道
- 类型:自定义渠道。
- 名称:chatglm3-6b-gpu
- 模型名称可以自定义:chatglm3-6b-gpu
- 密钥随便填:sk-aaabbbcccdddeeefffggghhhiiijjjkkk
- 代理地址填入 ChatGLM3-6B 的 API 地址
添加m3e渠道
- 类型:自定义渠道。
- 名称:m3e
- 模型名称可以自定义:m3e
- 密钥随便填:sk-aaabbbcccdddeeefffggghhhiiijjjkkk
- 代理地址填入m3e的 API 地址,此处我填的本地地址
添加新令牌
- 名称:fastGPT
- 过期时间:永不过期
- 取消无限额度:设置成取消无限额度
在部署fastGPT的时候会用到
部署FastGPT
GITHUB地址:https://github.com/labring/FastGPT
文档地址:快速了解 FastGPT | FastGPT (fastai.site)
这里使用Docker-compose模式部署
参考官方链接:Docker Compose 快速部署 | FastGPT (fastai.site)
- docker-compose.yml
# 非 host 版本, 不使用本机代理
# (不懂 Docker 的,只需要关心 OPENAI_BASE_URL 和 CHAT_API_KEY 即可!)
version: '3.3'
services:
pg:
image: ankane/pgvector:v0.5.0 # git
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/pgvector:v0.5.0 # 阿里云
container_name: pg
restart: always
ports: # 生产环境建议不要暴露
- 5432:5432
networks:
- fastgpt
environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgres
volumes:
- ./pg/data:/var/lib/postgresql/data
mongo:
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18
container_name: mongo
restart: always
ports:
- 27017:27017
networks:
- fastgpt
command: mongod --keyFile /data/mongodb.key --replSet rs0
environment:
- MONGO_INITDB_ROOT_USERNAME=myusername
- MONGO_INITDB_ROOT_PASSWORD=mypassword
volumes:
- ./mongo/data:/data/db
entrypoint:
- bash
- -c
- |
openssl rand -base64 128 > /data/mongodb.key
chmod 400 /data/mongodb.key
chown 999:999 /data/mongodb.key
exec docker-entrypoint.sh $$@
fastgpt:
container_name: fastgpt
image: ghcr.io/labring/fastgpt:latest # git
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest # 阿里云
ports:
- 3020:3000
networks:
- fastgpt
depends_on:
- mongo
- pg
restart: always
environment:
# root 密码,用户名为: root
- DEFAULT_ROOT_PSW=1234
# 中转地址,如果是用官方号,不需要管。务必加 /v1
- OPENAI_BASE_URL=http://192.168.18.216:3000/v1
- CHAT_API_KEY=sk-9t3ZGiTqUdiay3ZFDcCb578f527042399eBdC402F50e7aA3
- DB_MAX_LINK=5 # database max link
- TOKEN_KEY=any
- ROOT_KEY=root_key
- FILE_TOKEN_KEY=filetoken
# mongo 配置,不需要改. 用户名myusername,密码mypassword。
- MONGODB_URI=mongodb://myusername:mypassword@mongo:27017/fastgpt?authSource=admin
# pg配置. 不需要改
- PG_URL=postgresql://username:password@pg:5432/postgres
volumes:
- ./config.json:/app/data/config.json
networks:
fastgpt:
部署完Docker-compose后,mongo会有问题,执行如下指令后重启即可
- config.json (这里增加了
chatglm3-6b-gpu
和m3e
)
{
"systemEnv": {
"openapiPrefix": "fastgpt",
"vectorMaxProcess": 15,
"qaMaxProcess": 15,
"pgHNSWEfSearch": 100
},
"llmModels": [
{
"model": "chatglm3-6b-gpu",
"name": "chatglm3-6b-gpu",
"maxContext": 16000,
"maxResponse": 4000,
"quoteMaxToken": 13000,
"maxTemperature": 1.2,
"vision": false,
"datasetProcess": true,
"usedInClassify": true,
"usedInExtractFields": true,
"usedInToolCall": true,
"usedInQueryExtension": true,
"toolChoice": true,
"functionCall": true,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
},
{
"model": "gpt-3.5-turbo",
"name": "gpt-3.5-turbo",
"maxContext": 16000,
"avatar": "/imgs/model/openai.svg",
"maxResponse": 4000,
"quoteMaxToken": 13000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": false,
"usedInClassify": true,
"usedInExtractFields": true,
"usedInToolCall": true,
"usedInQueryExtension": true,
"toolChoice": true,
"functionCall": true,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
},
{
"model": "gpt-4-0125-preview",
"name": "gpt-4-turbo",
"avatar": "/imgs/model/openai.svg",
"maxContext": 125000,
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": false,
"usedInClassify": true,
"usedInExtractFields": true,
"usedInToolCall": true,
"usedInQueryExtension": true,
"toolChoice": true,
"functionCall": false,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
},
{
"model": "gpt-4-vision-preview",
"name": "gpt-4-vision",
"avatar": "/imgs/model/openai.svg",
"maxContext": 128000,
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"charsPointsPrice": 0,
"censor": false,
"vision": true,
"datasetProcess": false,
"usedInClassify": false,
"usedInExtractFields": false,
"usedInToolCall": false,
"usedInQueryExtension": false,
"toolChoice": true,
"functionCall": false,
"customCQPrompt": "",
"customExtractPrompt": "",
"defaultSystemChatPrompt": "",
"defaultConfig": {}
}
],
"vectorModels": [
{
"model": "m3e",
"name": "m3e",
"price": 0.1,
"defaultToken": 1000,
"maxToken": 1800
},
{
"model": "m3e",
"name": "M3E(测试使用)",
"price": 0.1,
"defaultToken": 1000,
"maxToken": 1800
}
],
"reRankModels": [],
"audioSpeechModels": [
{
"model": "tts-1",
"name": "OpenAI TTS1",
"charsPointsPrice": 0,
"voices": [
{
"label": "Alloy",
"value": "alloy",
"bufferId": "openai-Alloy"
},
{
"label": "Echo",
"value": "echo",
"bufferId": "openai-Echo"
},
{
"label": "Fable",
"value": "fable",
"bufferId": "openai-Fable"
},
{
"label": "Onyx",
"value": "onyx",
"bufferId": "openai-Onyx"
},
{
"label": "Nova",
"value": "nova",
"bufferId": "openai-Nova"
},
{
"label": "Shimmer",
"value": "shimmer",
"bufferId": "openai-Shimmer"
}
]
}
],
"whisperModel": {
"model": "whisper-1",
"name": "Whisper1",
"charsPointsPrice": 0
}
}
访问FastGPT
地址:http://192.168.18.216:3020/login
账号:root
密码:1234
剩下的就是自己玩吧,可以添加知识库学习,创建应用,应用关联知识库等
参考链接如下(感谢):
https://zhuanlan.zhihu.com/p/460806048
https://pytorch.org/get-started/previous-versions/
评论区