环境要求

启动模式 CPU * MEM GPU 备注
代理模型 4C*8G 代理模型不依赖GPU
本地模型 8C*32G 24G 本地启动最好有24G以上GPU

环境准备

源码下载

:::success 下载DB-GPT源码

:::

  1. git clone https://github.com/eosphoros-ai/DB-GPT.git

Miniconda环境安装

默认数据库使用SQLite,因此默认启动模式下,无需安装数据库。 如果需要使用其他数据库,可以看后面的高级教程。 我们推荐通过conda的虚拟环境来进行Python虚拟环境的安装。关于Miniconda环境的安装,可以参见Miniconda安装教程

:::color1 创建Python虚拟环境

:::

  1. python >= 3.10
  2. conda create -n dbgpt_env python=3.10
  3. conda activate dbgpt_env
  4. # it will take some minutes
  5. pip install -e ".[default]"
  1. 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
  1. 安装依赖
  1. pip install -e ".[openai]"
  1. 下载Embedding 模型
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://www.modelscope.cn/Jerry0/text2vec-large-chinese.git
  5. 或者
  6. git clone https://www.modelscope.cn/AI-ModelScope/m3e-large.git
  1. 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
  1. LLM_MODEL=chatgpt_proxyllm
  2. PROXY_API_KEY={your-openai-sk}
  3. PROXY_SERVER_URL=https://api.openai.com/v1/chat/completions
  4. # If you use gpt-4
  5. # PROXYLLM_BACKEND=gpt-4
通义
  1. 安装依赖
  1. pip install dashscope
  1. 下载Embedding模型
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. or
  6. git clone https://huggingface.co/moka-ai/m3e-large
  1. 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
  1. #Aliyun tongyi
  2. LLM_MODEL=tongyi_proxyllm
  3. TONGYI_PROXY_API_KEY={your-tongyi-sk}
  4. PROXY_SERVER_URL={your_service_url}
智谱
  1. 安装依赖
  1. pip install zhipuai
  1. 下载Embedding 模型
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. or
  6. git clone https://huggingface.co/moka-ai/m3e-large
  1. 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
  1. LLM_MODEL=zhipu_proxyllm
  2. PROXY_SERVER_URL={your_service_url}
  3. ZHIPU_MODEL_VERSION={version}
  4. ZHIPU_PROXY_API_KEY={your-zhipu-sk}
文心
  1. 下载Embedding 模型
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. or
  6. git clone https://huggingface.co/moka-ai/m3e-large
  1. 配置代理,在.env文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
  1. LLM_MODEL=wenxin_proxyllm
  2. PROXY_SERVER_URL={your_service_url}
  3. WEN_XIN_MODEL_VERSION={version}
  4. WEN_XIN_API_KEY={your-wenxin-sk}
  5. WEN_XIN_API_SECRET={your-wenxin-sct}
Gemini
  1. 安装依赖
  1. pip install google-generativeai
  1. 下载Embedding模型
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. or
  6. git clone https://huggingface.co/moka-ai/m3e-large
  1. 配置代理, 在文件中修改LLM_MODEL, PROXY_API_URL and API_KEY
  1. LLM_MODEL=gemini_proxyllm
  2. GEMINI_PROXY_API_KEY={your_api_key}
deepseek

配置代理, 在文件中修改LLM_MODEL,DEEPSEEK_MODEL_VERSION,API_KEY

  1. LLM_MODEL=deepseek_proxyllm
  2. # deepseek-chat or deepseek-reasoner
  3. DEEPSEEK_MODEL_VERSION=deepseek-chat
  4. DEEPSEEK_API_KEY={your_api_key}
:::color3 ⚠️ 注意.env 配置文件内容不要被覆盖 ::: ## 本地模型 :::warning 说明: 部署时优先选择评测效果更好的模型,推荐Qwen2.5系列 :::
qwen2.5
  1. 硬件需求说明
  1. |—————————-|———————|————————|
  2. | Model | Quantize | VRAM Size |
  3. |————————— |———————|————————|
  4. |qwen2.5-7b | 4-bit | 8GB |
  5. |—————————-|———————|————————|
  6. |qwen2.5-7b | 8-bit | 12GB |
  7. |—————————-|———————|————————|
  8. |qwen2.5-14b | 4-bit | 12GB |
  9. |—————————-|———————|————————|
  10. |qwen2.5-14b | 8-bit | 24GB |
  11. |—————————-|———————|————————|
  1. 模型下载
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. 或者
  6. git clone https://huggingface.co/moka-ai/m3e-large
  7. #### llm model, if you use openai or Azure or tongyi llm api service, you don’t need to download llm model
  8. git clone https://www.modelscope.cn/Qwen/Qwen2.5-14B-Instruct.git
  1. 环境变量配置, 配置LLM_MODEL参数在 .env 文件中
  1. LLM_MODEL=Qwen2.5-14B-Instruct
百川
  1. 硬件需求说明
  1. |—————————-|———————|————————|
  2. | Model | Quantize | VRAM Size |
  3. |————————— |———————|————————|
  4. |Baichuan-7b | 4-bit | 8GB |
  5. |—————————-|———————|————————|
  6. |Baichuan-7b | 8-bit | 12GB |
  7. |—————————-|———————|————————|
  8. |Baichuan-13b | 4-bit | 12GB |
  9. |—————————-|———————|————————|
  10. |Baichuan-13b | 8-bit | 24GB |
  11. |—————————-|———————|————————|
  1. 模型下载
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. 或者
  6. git clone https://huggingface.co/moka-ai/m3e-large
  7. #### llm model
  8. git clone https://huggingface.co/baichuan-inc/Baichuan2-7B-Chat
  9. 或者
  10. git clone https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat
  1. 环境变量配置, 配置LLM_MODEL参数在 .env 文件中
  1. LLM_MODEL=baichuan2-13b
ChatGLM/ChatGLM2
  1. 硬件需求说明
  1. |—————————-|———————|————————|
  2. | Model | Quantize | VRAM Size |
  3. |————————— |———————|————————|
  4. |ChatGLM-6b | 4-bit | 7GB |
  5. |—————————-|———————|————————|
  6. |ChatGLM-6b | 8-bit | 9GB |
  7. |—————————-|———————|————————|
  8. |ChatGLM-6b | FP16 | 14GB |
  9. |—————————-|———————|————————|
  1. 模型下载
  1. cd DB-GPT
  2. mkdir models and cd models
  3. #### embedding model
  4. git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
  5. or
  6. git clone https://huggingface.co/moka-ai/m3e-large
  7. #### llm model
  8. git clone https://huggingface.co/THUDM/chatglm2-6b
  1. 环境变量配置, 配置LLM_MODEL参数在 .env 文件中
  1. 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中是可选安装项, 你可以通过以下命令进行安装
  1. pip install -e ".[llama_cpp]"

修改配置文件

修改.env文件使用llama.cpp, 然后可以通过运行命令进行服务启动

  1. LLM_MODEL=llama-cpp
  2. 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在元数据与系统数据管理上,支持两种数据库。sqliteMySQL 如果是本地测试使用,可以用sqlite,如果是生产环境,我们推荐使用MySQL, 使用sqlite可以跳过此部分内容。

sqlite

系统默认是sqlite,如果使用sqlite,无需做额外操作,系统会默认创建并升级Schema


MySQL

⚠️ 当使用MySQL时,在v0.4.7版本之后,我们不在做MySQL数据库Schema的自动创建与升级, 主要是为安全生产考虑。

  1. 执行脚本初始化表结构, 如果是做版本升级需要提对应的DDL变更来更新表结构
  1. $ mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql
  1. 修改.env文件配置MySQL数据库
  1. LOCAL_DB_TYPE=mysql
  2. LOCAL_DB_USER= {your username}
  3. LOCAL_DB_PASSWORD={your_password}
  4. LOCAL_DB_HOST=127.0.0.1
  5. LOCAL_DB_PORT=3306

测试数据(可选)

DB-GPT项目默认内置了一部分测试数据,可以通过以下命令加载到本地数据库中进行测试。

:::color1 Linux&Unix平台

:::

  1. bash ./scripts/examples/load_examples.sh

:::color1 Windows平台

:::

  1. .\scripts\examples\load_examples.bat

运行服务

DB-GPT服务被打包到一个server当中,可以通过如下命令启动整个DB-GPT服务。

  1. $ python dbgpt/app/dbgpt_server.py
  2. # 说明: v0.4.4 版本进行了代码与架构重构, v0.4.3(含) 之前的版本运行命令如下
  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配置

:::