环境要求
启动模式 | CPU * MEM | GPU | 备注 |
---|---|---|---|
代理模型 | 4C*8G | 代理模型不依赖GPU | |
本地模型 | 8C*32G | 24G | 本地启动最好有24G以上GPU |
环境准备
源码下载
:::success 下载DB-GPT源码
:::
git clone https://github.com/eosphoros-ai/DB-GPT.git
Miniconda环境安装
默认数据库使用SQLite,因此默认启动模式下,无需安装数据库。 如果需要使用其他数据库,可以看后面的高级教程。 我们推荐通过conda的虚拟环境来进行Python虚拟环境的安装。关于Miniconda环境的安装,可以参见Miniconda安装教程。
:::color1 创建Python虚拟环境
:::
python >= 3.10
conda create -n dbgpt_env python=3.10
conda activate dbgpt_env
# it will take some minutes
pip install -e ".[default]"
cp .env.template .env
模型部署
DB-GPT可以通过代理模式部署在硬件较低的服务器上,也可以在GPU下进行私有化本地模型的部署。 如果您的硬件配置较低,可以使用第三方大模型API服务,如OpenAI、Azure、通义、文心等进行安装。
:::color3 ⚠️ 注意: 需要确保安装了git-lfs
- CentOS安装: yum install git-lfs
- Ubuntu安装: apt-get install git-lfs
- MacOS安装: brew install git-lfs
:::
代理模型
OpenAI
- 安装依赖
pip install -e ".[openai]"
- 下载Embedding 模型
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://www.modelscope.cn/Jerry0/text2vec-large-chinese.git
或者
git clone https://www.modelscope.cn/AI-ModelScope/m3e-large.git
- 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
LLM_MODEL=chatgpt_proxyllm
PROXY_API_KEY={your-openai-sk}
PROXY_SERVER_URL=https://api.openai.com/v1/chat/completions
# If you use gpt-4
# PROXYLLM_BACKEND=gpt-4
通义
- 安装依赖
pip install dashscope
- 下载Embedding模型
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
or
git clone https://huggingface.co/moka-ai/m3e-large
- 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
#Aliyun tongyi
LLM_MODEL=tongyi_proxyllm
TONGYI_PROXY_API_KEY={your-tongyi-sk}
PROXY_SERVER_URL={your_service_url}
智谱
- 安装依赖
pip install zhipuai
- 下载Embedding 模型
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
or
git clone https://huggingface.co/moka-ai/m3e-large
- 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
LLM_MODEL=zhipu_proxyllm
PROXY_SERVER_URL={your_service_url}
ZHIPU_MODEL_VERSION={version}
ZHIPU_PROXY_API_KEY={your-zhipu-sk}
文心
- 下载Embedding 模型
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
or
git clone https://huggingface.co/moka-ai/m3e-large
- 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
LLM_MODEL=wenxin_proxyllm
PROXY_SERVER_URL={your_service_url}
WEN_XIN_MODEL_VERSION={version}
WEN_XIN_API_KEY={your-wenxin-sk}
WEN_XIN_API_SECRET={your-wenxin-sct}
Gemini
- 安装依赖
pip install google-generativeai
- 下载Embedding模型
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
or
git clone https://huggingface.co/moka-ai/m3e-large
- 配置代理, 在文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
LLM_MODEL=gemini_proxyllm
GEMINI_PROXY_API_KEY={your_api_key}
deepseek
配置代理, 在文件中修改LLM_MODEL,DEEPSEEK_MODEL_VERSION,API_KEY
LLM_MODEL=deepseek_proxyllm
# deepseek-chat or deepseek-reasoner
DEEPSEEK_MODEL_VERSION=deepseek-chat
DEEPSEEK_API_KEY={your_api_key}
qwen2.5
- 硬件需求说明
|—————————-|———————|————————|
| Model | Quantize | VRAM Size |
|————————— |———————|————————|
|qwen2.5-7b | 4-bit | 8GB |
|—————————-|———————|————————|
|qwen2.5-7b | 8-bit | 12GB |
|—————————-|———————|————————|
|qwen2.5-14b | 4-bit | 12GB |
|—————————-|———————|————————|
|qwen2.5-14b | 8-bit | 24GB |
|—————————-|———————|————————|
- 模型下载
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
或者
git clone https://huggingface.co/moka-ai/m3e-large
#### llm model, if you use openai or Azure or tongyi llm api service, you don’t need to download llm model
git clone https://www.modelscope.cn/Qwen/Qwen2.5-14B-Instruct.git
- 环境变量配置, 配置LLM_MODEL参数在
.env
文件中
LLM_MODEL=Qwen2.5-14B-Instruct
百川
- 硬件需求说明
|—————————-|———————|————————|
| Model | Quantize | VRAM Size |
|————————— |———————|————————|
|Baichuan-7b | 4-bit | 8GB |
|—————————-|———————|————————|
|Baichuan-7b | 8-bit | 12GB |
|—————————-|———————|————————|
|Baichuan-13b | 4-bit | 12GB |
|—————————-|———————|————————|
|Baichuan-13b | 8-bit | 24GB |
|—————————-|———————|————————|
- 模型下载
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
或者
git clone https://huggingface.co/moka-ai/m3e-large
#### llm model
git clone https://huggingface.co/baichuan-inc/Baichuan2-7B-Chat
或者
git clone https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat
- 环境变量配置, 配置LLM_MODEL参数在
.env
文件中
LLM_MODEL=baichuan2-13b
ChatGLM/ChatGLM2
- 硬件需求说明
|—————————-|———————|————————|
| Model | Quantize | VRAM Size |
|————————— |———————|————————|
|ChatGLM-6b | 4-bit | 7GB |
|—————————-|———————|————————|
|ChatGLM-6b | 8-bit | 9GB |
|—————————-|———————|————————|
|ChatGLM-6b | FP16 | 14GB |
|—————————-|———————|————————|
- 模型下载
cd DB-GPT
mkdir models and cd models
#### embedding model
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
or
git clone https://huggingface.co/moka-ai/m3e-large
#### llm model
git clone https://huggingface.co/THUDM/chatglm2-6b
- 环境变量配置, 配置LLM_MODEL参数在
.env
文件中
LLM_MODEL=chatglm2-6b
llama.cpp(CPU运行)
:::success ⚠️ 注: llama.cpp 可以在Mac M1或者Mac M2运行
:::
DB-GPT同时也支持更低成本的推理框架llama.cpp, 可以通过llama-cpp-python 来进行使用
文件准备
在使用llama.cpp之前,首先需要准备gguf格式的模型文件,有两种方法可以获取,你可以选择一种方法获取对应的文件。
:::color1 方法1: 下载已转换的模型
:::
如果你想使用Vicuna-13b-v1.5,你可以下载已经转换好的文件TheBloke/vicuna-13B-v1.5-GGUF,只需要这一个文件。下载文件并将其放到模型路径, 需要将模型重命名为: ggml-model-q4_0.gguf.
:::color1 方法2: 自己转换文件
:::
你在使用中也可以根据llama.cpp#prepare-data–run中的说明自行转换模型文件,并把转换后的文件放在models目录中,并命名为ggml-model-q4_0.gguf
。
安装依赖
llama.cpp在DB-GPT中是可选安装项, 你可以通过以下命令进行安装
pip install -e ".[llama_cpp]"
修改配置文件
修改.env文件使用llama.cpp, 然后可以通过运行命令进行服务启动
LLM_MODEL=llama-cpp
llama_cpp_prompt_template=vicuna_v1.1
更多项说明
环境变量 | 默认值 | 描述 |
---|---|---|
llama_cpp_prompt_template | None | Prompt template 现在可以支持zero_shot, vicuna_v1.1,alpaca,llama-2,baichuan-chat,internlm-chat , 如果是None, 可以根据模型路径来自动获取模型 Prompt template |
llama_cpp_model_path | None | 模型路径 |
llama_cpp_n_gpu_layers | 1000000000 | 要将多少网络层转移到GPU上,将其设置为1000000000以将所有层转移到GPU上。如果您的 GPU 内存不足,可以设置较低的数字,例如:10。 |
llama_cpp_n_threads | None | 要使用的线程数量。如果为None,则线程数量将自动确定。 |
llama_cpp_n_batch | 512 | 在调用llama_eval时,批处理在一起的prompt tokens的最大数量 |
llama_cpp_n_gqa | None | 对于 llama-2 70B 模型,Grouped-query attention 必须为8。 |
llama_cpp_rms_norm_eps | 5e-06 | 对于llama-2模型来说,5e-6是一个不错的值。 |
llama_cpp_cache_capacity | None | 模型缓存最大值. 例如: 2000MiB, 2GiB |
llama_cpp_prefer_cpu | False | 如果有可用的GPU,默认情况下会优先使用GPU,除非配置了 prefer_cpu=False。 |
配置元数据库(可选)
当前DB-GPT在元数据与系统数据管理上,支持两种数据库。sqlite
与MySQL
如果是本地测试使用,可以用sqlite
,如果是生产环境,我们推荐使用MySQL
, 使用sqlite
可以跳过此部分内容。
sqlite
系统默认是sqlite,如果使用sqlite,无需做额外操作,系统会默认创建并升级Schema
MySQL
⚠️ 当使用MySQL时,在v0.4.7版本之后,我们不在做MySQL数据库Schema的自动创建与升级, 主要是为安全生产考虑。
- 执行脚本初始化表结构, 如果是做版本升级需要提对应的DDL变更来更新表结构
$ mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql
- 修改
.env
文件配置MySQL数据库
LOCAL_DB_TYPE=mysql
LOCAL_DB_USER= {your username}
LOCAL_DB_PASSWORD={your_password}
LOCAL_DB_HOST=127.0.0.1
LOCAL_DB_PORT=3306
测试数据(可选)
DB-GPT项目默认内置了一部分测试数据,可以通过以下命令加载到本地数据库中进行测试。
:::color1 Linux&Unix平台
:::
bash ./scripts/examples/load_examples.sh
:::color1 Windows平台
:::
.\scripts\examples\load_examples.bat
运行服务
DB-GPT服务被打包到一个server当中,可以通过如下命令启动整个DB-GPT服务。
$ python dbgpt/app/dbgpt_server.py
# 说明: v0.4.4 版本进行了代码与架构重构, v0.4.3(含) 之前的版本运行命令如下
# python pilot/server/dbgpt_server.py
:::danger
特殊说明: ⚠️ v0.4.3及以前版本运行服务命令为: python pilot/server/dbgpt_server.py
:::
访问服务
:::info 打开浏览器访问 http://localhost:5670
注⚠️: v0.5.4之前版本端口为5000, http://localhost:5000
具体端口配置查看.env
文件中WEB_SERVER_PORT=5670
配置
:::