Linux搭建DB-GPT

准备工作

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

下载完成应该是2.5GB大小

1
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese /usr/local/lib/python3.10/site-packages/models/text2vec-large-chinese
1
wget https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip
1
2
3
4
.git/
.github/
./.mypy_cache/
models/

以下为用ollama作为代理模型的.env设置

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#*******************************************************************#
#**             DB-GPT  - GENERAL SETTINGS                        **#  
#*******************************************************************#

#*******************************************************************#
#**                        Webserver Port                         **#
#*******************************************************************#
DBGPT_WEBSERVER_PORT=5678
## Whether to enable the new web UI, enabled by default,False use old ui
# USE_NEW_WEB_UI=True
#*******************************************************************#
#***                       LLM PROVIDER                          ***#
#*******************************************************************#

# TEMPERATURE=0

#*******************************************************************#
#**                         LLM MODELS                            **#
#*******************************************************************#
# LLM_MODEL, see dbgpt/configs/model_config.LLM_MODEL_CONFIG
LLM_MODEL=ollama_proxyllm
PROXY_API_KEY=not_used
PROXY_SERVER_URL=http://192.168.2.128:11434
## LLM model path, by default, DB-GPT will read the model path from LLM_MODEL_CONFIG based on the LLM_MODEL.
## Of course you can specify your model path according to LLM_MODEL_PATH
## In DB-GPT, the priority from high to low to read model path:
##    1. environment variable with key: {LLM_MODEL}_MODEL_PATH (Avoid multi-model conflicts)
##    2. environment variable with key: MODEL_PATH
##    3. environment variable with key: LLM_MODEL_PATH
##    4. the config in dbgpt/configs/model_config.LLM_MODEL_CONFIG
# LLM_MODEL_PATH=/app/models/glm-4-9b-chat
# LLM_PROMPT_TEMPLATE=vicuna_v1.1
MODEL_SERVER=http://127.0.0.1:8000
LIMIT_MODEL_CONCURRENCY=5
MAX_POSITION_EMBEDDINGS=4096
QUANTIZE_QLORA=True
QUANTIZE_8bit=True
# QUANTIZE_4bit=False
## SMART_LLM_MODEL - Smart language model (Default: vicuna-13b)
## FAST_LLM_MODEL - Fast language model (Default: chatglm-6b)
# SMART_LLM_MODEL=vicuna-13b
# FAST_LLM_MODEL=chatglm-6b
## Proxy llm backend, this configuration is only valid when "LLM_MODEL=proxyllm", When we use the rest API provided by deployment frameworks like fastchat as a proxyllm, 
## "PROXYLLM_BACKEND" is the model they actually deploy. We can use "PROXYLLM_BACKEND" to load the prompt of the corresponding scene. 
PROXYLLM_BACKEND=glm4:latest

### You can configure parameters for a specific model with {model name}_{config key}=xxx
### See dbgpt/model/parameter.py
## prompt template for current model
# llama_cpp_prompt_template=vicuna_v1.1
## llama-2-70b must be 8
# llama_cpp_n_gqa=8
## Model path
# llama_cpp_model_path=/data/models/TheBloke/vicuna-13B-v1.5-GGUF/vicuna-13b-v1.5.Q4_K_M.gguf

### LLM cache
## Enable Model cache
# MODEL_CACHE_ENABLE=True
## The storage type of model cache, now supports: memory, disk
# MODEL_CACHE_STORAGE_TYPE=disk
## The max cache data in memory, we always store cache data in memory fist for high speed. 
# MODEL_CACHE_MAX_MEMORY_MB=256
## The dir to save cache data, this configuration is only valid when MODEL_CACHE_STORAGE_TYPE=disk
## The default dir is pilot/data/model_cache
# MODEL_CACHE_STORAGE_DISK_DIR=

#*******************************************************************#
#**                         EMBEDDING SETTINGS                    **#
#*******************************************************************#
EMBEDDING_MODEL=text2vec
#EMBEDDING_MODEL=m3e-large
#EMBEDDING_MODEL=bge-large-en
#EMBEDDING_MODEL=bge-large-zh
KNOWLEDGE_CHUNK_SIZE=500
KNOWLEDGE_SEARCH_TOP_SIZE=5
KNOWLEDGE_GRAPH_SEARCH_TOP_SIZE=200
## Maximum number of chunks to load at once, if your single document is too large,
## you can set this value to a higher value for better performance.
## if out of memory when load large document, you can set this value to a lower value.
# KNOWLEDGE_MAX_CHUNKS_ONCE_LOAD=10
#KNOWLEDGE_CHUNK_OVERLAP=50
# Control whether to display the source document of knowledge on the front end.
KNOWLEDGE_CHAT_SHOW_RELATIONS=False
# Whether to enable Chat Knowledge Search Rewrite Mode
KNOWLEDGE_SEARCH_REWRITE=False
## EMBEDDING_TOKENIZER   - Tokenizer to use for chunking large inputs
## EMBEDDING_TOKEN_LIMIT - Chunk size limit for large inputs
# EMBEDDING_MODEL=all-MiniLM-L6-v2
# EMBEDDING_TOKENIZER=all-MiniLM-L6-v2
# EMBEDDING_TOKEN_LIMIT=8191

## Openai embedding model, See dbgpt/model/parameter.py
# EMBEDDING_MODEL=proxy_openai
# proxy_openai_proxy_server_url=https://api.openai.com/v1
# proxy_openai_proxy_api_key={your-openai-sk}
# proxy_openai_proxy_backend=text-embedding-ada-002


## qwen embedding model, See dbgpt/model/parameter.py
# EMBEDDING_MODEL=proxy_tongyi
# proxy_tongyi_proxy_backend=text-embedding-v1
# proxy_tongyi_proxy_api_key={your-api-key}

## qianfan embedding model, See dbgpt/model/parameter.py
#EMBEDDING_MODEL=proxy_qianfan
#proxy_qianfan_proxy_backend=bge-large-zh
#proxy_qianfan_proxy_api_key={your-api-key}
#proxy_qianfan_proxy_api_secret={your-secret-key}


## Common HTTP embedding model
# EMBEDDING_MODEL=proxy_http_openapi
# proxy_http_openapi_proxy_server_url=http://localhost:8100/api/v1/embeddings
# proxy_http_openapi_proxy_api_key=1dce29a6d66b4e2dbfec67044edbb924
# proxy_http_openapi_proxy_backend=text2vec

#*******************************************************************#
#**                         RERANK SETTINGS                       **#
#*******************************************************************#
## Rerank model
# RERANK_MODEL=bge-reranker-base
## If you not set RERANK_MODEL_PATH, DB-GPT will read the model path from EMBEDDING_MODEL_CONFIG based on the RERANK_MODEL.
# RERANK_MODEL_PATH=
## The number of rerank results to return
# RERANK_TOP_K=3

## Common HTTP rerank model
# RERANK_MODEL=rerank_proxy_http_openapi
# rerank_proxy_http_openapi_proxy_server_url=http://127.0.0.1:8100/api/v1/beta/relevance
# rerank_proxy_http_openapi_proxy_api_key={your-api-key}
# rerank_proxy_http_openapi_proxy_backend=bge-reranker-base




#*******************************************************************#
#**                  DB-GPT METADATA DATABASE SETTINGS            **#
#*******************************************************************#
### SQLite database (Current default database)
# LOCAL_DB_TYPE=sqlite

### MYSQL database
LOCAL_DB_TYPE=mysql
LOCAL_DB_USER=root
LOCAL_DB_PASSWORD=nicaicai
LOCAL_DB_HOST=172.18.0.4
LOCAL_DB_PORT=3306
LOCAL_DB_NAME=dbgpt
### This option determines the storage location of conversation records. The default is not configured to the old version of duckdb. It can be optionally db or file (if the value is db, the database configured by LOCAL_DB will be used)
#CHAT_HISTORY_STORE_TYPE=db

#*******************************************************************#
#**                         COMMANDS                              **#
#*******************************************************************#
EXECUTE_LOCAL_COMMANDS=False

#*******************************************************************#
#**            VECTOR STORE / KNOWLEDGE GRAPH SETTINGS            **#
#*******************************************************************#
VECTOR_STORE_TYPE=Chroma
# GRAPH_STORE_TYPE=TuGraph
# KNOWLEDGE_GRAPH_EXTRACT_SEARCH_TOP_SIZE=5
# KNOWLEDGE_GRAPH_EXTRACT_SEARCH_RECALL_SCORE=0.3
# KNOWLEDGE_GRAPH_COMMUNITY_SEARCH_TOP_SIZE=20
# KNOWLEDGE_GRAPH_COMMUNITY_SEARCH_RECALL_SCORE=0.0

# GRAPH_COMMUNITY_SUMMARY_ENABLED=True  # enable the graph community summary
# TRIPLET_GRAPH_ENABLED=True  # enable the graph search for triplets
# DOCUMENT_GRAPH_ENABLED=True  # enable the graph search for documents and chunks

# KNOWLEDGE_GRAPH_CHUNK_SEARCH_TOP_SIZE=5  # the top size of knowledge graph search for chunks
# KNOWLEDGE_GRAPH_EXTRACTION_BATCH_SIZE=20  # the batch size of triplet extraction from the text

### Chroma vector db config
#CHROMA_PERSIST_PATH=/root/DB-GPT/pilot/data

### Milvus vector db config
#VECTOR_STORE_TYPE=Milvus
#MILVUS_URL=127.0.0.1
#MILVUS_PORT=19530
#MILVUS_USERNAME
#MILVUS_PASSWORD
#MILVUS_SECURE=

### Weaviate vector db config
#VECTOR_STORE_TYPE=Weaviate
#WEAVIATE_URL=https://kt-region-m8hcy0wc.weaviate.network

## ElasticSearch vector db config
#VECTOR_STORE_TYPE=ElasticSearch
ELASTICSEARCH_URL=127.0.0.1
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD={your_password}

### TuGraph config
# TUGRAPH_HOST=172.18.0.8
# TUGRAPH_PORT=7687
# TUGRAPH_USERNAME=admin
# TUGRAPH_PASSWORD=73@TuGraph
# TUGRAPH_VERTEX_TYPE=entity
# TUGRAPH_EDGE_TYPE=relation
# TUGRAPH_PLUGIN_NAMES=leiden

#*******************************************************************#
#**                  WebServer Language Support                   **#
#*******************************************************************#
# en, zh, fr, ja, ko, ru
#LANGUAGE=en
LANGUAGE=zh


#*******************************************************************#
# **    PROXY_SERVER (openai interface | chatGPT proxy service), use chatGPT as your LLM.
# ** if your server can visit openai, please set PROXY_SERVER_URL=https://api.openai.com/v1/chat/completions
# ** else if you have a chatgpt proxy server, you can set PROXY_SERVER_URL={your-proxy-serverip:port/xxx}
#*******************************************************************#
#PROXY_API_KEY=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
#PROXY_SERVER_URL=https://api.openai.com/v1/chat/completions

# from https://bard.google.com/     f12-> application-> __Secure-1PSID
BARD_PROXY_API_KEY={your-bard-token}

#*******************************************************************#
# **  PROXY_SERVER +                                              **#
#*******************************************************************#

# Aliyun tongyi
TONGYI_PROXY_API_KEY={your-tongyi-sk}

## Baidu wenxin
#WEN_XIN_MODEL_VERSION={version}
#WEN_XIN_API_KEY={your-wenxin-sk}
#WEN_XIN_API_SECRET={your-wenxin-sct}

## Zhipu
#ZHIPU_MODEL_VERSION={version}
#ZHIPU_PROXY_API_KEY={your-zhipu-sk}

## Baichuan
#BAICHUN_MODEL_NAME={version}
#BAICHUAN_PROXY_API_KEY={your-baichuan-sk}
#BAICHUAN_PROXY_API_SECRET={your-baichuan-sct}

# Xunfei Spark
#XUNFEI_SPARK_API_VERSION={version}
#XUNFEI_SPARK_APPID={your_app_id}
#XUNFEI_SPARK_API_KEY={your_api_key}
#XUNFEI_SPARK_API_SECRET={your_api_secret}

## Yi Proxyllm, https://platform.lingyiwanwu.com/docs
#YI_MODEL_VERSION=yi-34b-chat-0205
#YI_API_BASE=https://api.lingyiwanwu.com/v1
#YI_API_KEY={your-yi-api-key}

## Moonshot Proxyllm, https://platform.moonshot.cn/docs/
# MOONSHOT_MODEL_VERSION=moonshot-v1-8k
# MOONSHOT_API_BASE=https://api.moonshot.cn/v1
# MOONSHOT_API_KEY={your-moonshot-api-key}

## Deepseek Proxyllm, https://platform.deepseek.com/api-docs/
# DEEPSEEK_MODEL_VERSION=deepseek-chat
# DEEPSEEK_API_BASE=https://api.deepseek.com/v1
# DEEPSEEK_API_KEY={your-deepseek-api-key}


#*******************************************************************#
#**    SUMMARY_CONFIG                                             **#
#*******************************************************************#
SUMMARY_CONFIG=FAST

#*******************************************************************#
#**    MUlti-GPU                                                  **#
#*******************************************************************#
## See https://developer.nvidia.com/blog/cuda-pro-tip-control-gpu-visibility-cuda_visible_devices/
## If CUDA_VISIBLE_DEVICES is not configured, all available gpus will be used
# CUDA_VISIBLE_DEVICES=0
## You can configure the maximum memory used by each GPU.
# MAX_GPU_MEMORY=16Gib

#*******************************************************************#
#**                         LOG                                   **#
#*******************************************************************#
# FATAL, ERROR, WARNING, WARNING, INFO, DEBUG, NOTSET
DBGPT_LOG_LEVEL=INFO
# LOG dir, default: ./logs
#DBGPT_LOG_DIR=


#*******************************************************************#
#**                         API_KEYS                              **#
#*******************************************************************#
# API_KEYS - The list of API keys that are allowed to access the API. Each of the below are an option, separated by commas.
# API_KEYS=dbgpt

#*******************************************************************#
#**                         ENCRYPT                               **#
#*******************************************************************#
# ENCRYPT KEY - The key used to encrypt and decrypt the data
# ENCRYPT_KEY=your_secret_key

#*******************************************************************#
#**                         File Server                           **#
#*******************************************************************#
## The local storage path of the file server, the default is pilot/data/file_server
# FILE_SERVER_LOCAL_STORAGE_PATH =

#*******************************************************************#
#**                     Application Config                        **#
#*******************************************************************#
## Non-streaming scene retries
# DBGPT_APP_SCENE_NON_STREAMING_RETRIES_BASE=1
## Non-streaming scene parallelism
# DBGPT_APP_SCENE_NON_STREAMING_PARALLELISM_BASE=1

#*******************************************************************#
#**                   Observability Config                        **#
#*******************************************************************#
## Whether to enable DB-GPT send trace to OpenTelemetry
# TRACER_TO_OPEN_TELEMETRY=False
## Following configurations are only valid when TRACER_TO_OPEN_TELEMETRY=True
## More details see https://opentelemetry-python.readthedocs.io/en/latest/exporter/otlp/otlp.html
# OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4317
# OTEL_EXPORTER_OTLP_TRACES_INSECURE=False
# OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE=
# OTEL_EXPORTER_OTLP_TRACES_HEADERS=
# OTEL_EXPORTER_OTLP_TRACES_TIMEOUT=
# OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=

#*******************************************************************#
#**                     FINANCIAL CHAT Config                     **#
#*******************************************************************#
# FIN_REPORT_MODEL=/app/models/bge-large-zh
1
2
3
4
5
6
7
8
9
#!/bin/bash
# 导入前删除数据库,确保每次启动都是全新
mysql -h"$DB_HOST" -u"$DB_USER" -p"$DB_PWD" -e "DROP DATABASE IF EXISTS EXAMPLE_1;"
mysql -h"$DB_HOST" -u"$DB_USER" -p"$DB_PWD" -e "DROP DATABASE IF EXISTS dbgpt;"

mysql -h"$dbhost" -u"$dbuser" -p"$dbpwd" < ./assets/schema/dbgpt.sql
# 加载样例数据
bash /DB-GPT/scripts/examples/load_examples.sh
dbgpt start webserver

搭建Mysql数据库,供DB-GPT使用,使DB-GPT容器与Mysql数据库分离。

Dockerfile构建

/DB-GPT目录中创建Dockerfile并写入以下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
FROM python:3.10-bookworm

# 克隆项目到根目录
# RUN git clone --depth 1 https://github.com/eosphoros-ai/DB-GPT.git /DB-GPT
COPY . /DB-GPT/

# 复制宿主机的unzip命令到容器
COPY sqlite3 /usr/local/bin/

WORKDIR /DB-GPT
# 当前路径加入到python运行的读取路径【非常关键】
ENV PYTHONPATH="${PYTHONPATH}:/DB-GPT"

# 安装依赖
# 172.18.0.5为nexus服务所在1panel-network网络分配的IP,所以要使用传统的构建模式,连接到nexus所在网络`DOCKER_BUILDKIT=0 docker build --network=1panel-network -t dbgpt-agent .`
RUN pip install --upgrade pip -i http://172.18.0.5:8081/repository/proxy-pypi/simple --trusted-host 172.18.0.5 \
    && pip install -e ".[default]" -i http://172.18.0.5:8081/repository/proxy-pypi/simple --trusted-host 172.18.0.5

RUN pip install -e ".[openai]" -i http://172.18.0.5:8081/repository/proxy-pypi/simple --trusted-host 172.18.0.5

# 安装连接PG、MYSQL、SQLSERVER数据库需要的库
RUN pip install psycopg2-binary clickhouse_connect pymssql "neo4j>=5.20.0" -i http://172.18.0.5:8081/repository/proxy-pypi/simple --trusted-host 172.18.0.5 \
    && pip cache purge


RUN apt-get update && \
    apt-get install -y --no-install-recommends mariadb-client bash && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
RUN chmod +x /DB-GPT/start.sh
EXPOSE 5678

ENTRYPOINT ["/DB-GPT/start.sh"]

构建镜像

1
DOCKER_BUILDKIT=0 docker build --network=1panel-network -t dbgpt-agent .

启动容器

1
docker run --name dbgpt -v /xxxx/dbgpt_backups/models:/DB-GPT/models -v /xxxx/dbgpt_backups/.env:/DB-GPT/.env --network=1panel-network -e dbhost=172.18.0.4 -e dbuser=root -e dbpwd=nicaicai -itd -p 5678:5678 dbgpt-agent

其他-镜像推送到阿里云

1
2
3
docker login --username=[username] registry.cn-hangzhou.aliyuncs.com
docker tag dbgpt-agent:latest registry.cn-hangzhou.aliyuncs.com/btzry/dbbpt-agent:ollama
docker push registry.cn-hangzhou.aliyuncs.com/btzry/dbbpt-agent:ollama

DB-GPT的设置信息存放在 /DB-GPT/pilot/meta_data/dbgpt.db