Merge branch 'TY_V4.0_TESTING' into Agent_Hub_Dev

This commit is contained in:
yhjun1026 2023-10-20 10:44:05 +08:00
commit 1920f0d699
52 changed files with 960 additions and 151 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 732 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

View File

@ -0,0 +1,69 @@
序号,大项,明细,备注,预算,实际,费用小计,超额,已支出,支出小计,其他
1,中央空调,内外机,1拖5 140 31600,30600,30600,30600,0,30600,30600,
2,基装,地砖,,106000,32100,107948.4,1948.4,32100,107948.4,1948.4
3,,地板,,,,,,,,
4,,门,颜色升级,,37450,,,37450,,
5,,橱柜,浴柜、马桶、花洒 自选,,,,,,,
6,,卫生间墙地,,,28149.4,,,28149.4,,
7,,厨房,墙、地(大改小增项)、菜盆去掉自选,,,,,,,
8,,打拆改建,,,10249,,,10249,,
9,其他费用,物业装修管理费(物业),405.58,26936.23,405.58,20836.23,-6100,405.58,20036.23,
10,,建渣清运费(物业),281.65,,281.65,,,281.65,,
11,,打拆清运费(物业),1300,,1300,,,1300,,
,,预交水费,200,,200,,,200,,
,,客卧加墙,1500,,1500,,,1500,,
,,天然气暗改,1800,,1800,,,1800,,
,,天然气明改,719,,719,,,719,,
,,开槽150,0,,0,,,0,,
,,防水增加,358,,358,,,358,,
,,墙砖背胶(大砖上墙加背胶),208,,208,,,208,,
,,美缝3000,3100,,3100,,,2500,,
,,淋浴隔断18980439828,3130,,3130,,,3130,,
,,橱柜增加费用,4500,,,,,,,
,,电费,200,,200,,,200,,
,,门锁,844,,844,,,844,,
,,空调机位封窗,1500,,1500,,,1300,,
,,开关灯安装,1000,,,,,,,
,,空调机位门,600,,,,,,,
,,瓷白胶,190,,190,,,190,,
,,瓷白胶人工,300,,300,,,300,,
,,每逢增加(橱柜浴柜),,,,,,,,
,,乳胶漆人工,,,,,,,,
12,,乳胶漆自购,4800,,4800,,,4800,,
13,水电改造,材料,16446,18636,16446,18425,-211,16446,18425,
14,,人工,,,,,,,,
,,开关插座补,531,,320,,,320,,
15,,开关插座,1659,,1659,,,1659,,
16,封窗,,15000,14500,14500,14500,0,4500,14500,
,,,,,,,,8000,,
17,,,,,,,,2000,,
18,基装(自购),马桶*2,9000,8200,8200,20000,,8200,20000,
19,,花洒*2,3000,4000,4000,,,4000,,
20,,浴柜*2,5000,4600,4600,,,4600,,
21,,菜盆,2500,3200,3200,,,3200,,
22,衣柜定做,鞋柜亮面、衣柜肤质、板材克诺斯邦、侧面表层,40*730,33000,5000,31000,,5000,31000,
23,,,,,15000,,,15000,,
,,,,,11000,,,11000,,
24,,,,,,,,,,
25,基础家电,燃气热水器,计划史密斯智能4000,3798,3798,18551,,3798,18841,24期免息
,,燃气热水器安装,,355,355,,,355,,
26,,洗碗机,计划西门子5999,6999,6999,,,6999,,
27,,冰箱,计划西门子,6000,,,,,,
28,,电视,,8000,,,,,,
,,洗衣机(安装),,290,,,,290,,
,,抽油烟机+灶具(升级),方太型号升级,3900,3900,,,3900,,
29,,洗衣机,计划西门子6500,3499,3499,,,3499,,
30,软装,沙发,15000,71799.8,,10877.8,,,9777.8,
31,,茶几,5000,,,,,,,
32,,电视柜,6000,,,,,,,
33,,餐桌,7000,,,,,,,
34,,床*2,7000,,,,,,,
,,床垫*2,13000,,,,,,,
,,窗帘,10400,,10500,,,9400,,
,,洞灯,399.8,,377.8,,,377.8,,
,,书桌,2000,,,,,,,
35,,灯具,6000,,,,,,,
36,合计,,,354313.03,272738.43,272738.43,-4362.6,,271128.43,-83184.6
37,,,,,,,,,,
38,双十一,,,,,38551,,,,
,,,,,,,,,,
1 序号 大项 明细 备注 预算 实际 费用小计 超额 已支出 支出小计 其他
2 1 中央空调 内外机 1拖5 140 31600 30600 30600 30600 0 30600 30600
3 2 基装 地砖 106000 32100 107948.4 1948.4 32100 107948.4 1948.4
4 3 地板
5 4 颜色升级 37450 37450
6 5 橱柜 浴柜、马桶、花洒 自选
7 6 卫生间墙地 28149.4 28149.4
8 7 厨房 墙、地(大改小增项)、菜盆去掉自选
9 8 打拆改建 10249 10249
10 9 其他费用 物业装修管理费(物业) 405.58 26936.23 405.58 20836.23 -6100 405.58 20036.23
11 10 建渣清运费(物业) 281.65 281.65 281.65
12 11 打拆清运费(物业) 1300 1300 1300
13 预交水费 200 200 200
14 客卧加墙 1500 1500 1500
15 天然气暗改 1800 1800 1800
16 天然气明改 719 719 719
17 开槽(150) 0 0 0
18 防水增加 358 358 358
19 墙砖背胶(大砖上墙加背胶) 208 208 208
20 美缝3000 3100 3100 2500
21 淋浴隔断(18980439828) 3130 3130 3130
22 橱柜增加费用 4500
23 电费 200 200 200
24 门锁 844 844 844
25 空调机位封窗 1500 1500 1300
26 开关灯安装 1000
27 空调机位门 600
28 瓷白胶 190 190 190
29 瓷白胶人工 300 300 300
30 每逢增加(橱柜浴柜)
31 乳胶漆人工
32 12 乳胶漆自购 4800 4800 4800
33 13 水电改造 材料 16446 18636 16446 18425 -211 16446 18425
34 14 人工
35 开关插座补 531 320 320
36 15 开关插座 1659 1659 1659
37 16 封窗 15000 14500 14500 14500 0 4500 14500
38 8000
39 17 2000
40 18 基装(自购) 马桶*2 9000 8200 8200 20000 8200 20000
41 19 花洒*2 3000 4000 4000 4000
42 20 浴柜*2 5000 4600 4600 4600
43 21 菜盆 2500 3200 3200 3200
44 22 衣柜定做 鞋柜亮面、衣柜肤质、板材克诺斯邦、侧面表层 40*730 33000 5000 31000 5000 31000
45 23 15000 15000
46 11000 11000
47 24
48 25 基础家电 燃气热水器 计划史密斯智能4000 3798 3798 18551 3798 18841 24期免息
49 燃气热水器安装 355 355 355
50 26 洗碗机 计划西门子5999 6999 6999 6999
51 27 冰箱 计划西门子 6000
52 28 电视 8000
53 洗衣机(安装) 290 290
54 抽油烟机+灶具(升级) 方太型号升级 3900 3900 3900
55 29 洗衣机 计划西门子6500 3499 3499 3499
56 30 软装 沙发 15000 71799.8 10877.8 9777.8
57 31 茶几 5000
58 32 电视柜 6000
59 33 餐桌 7000
60 34 床*2 7000
61 床垫*2 13000
62 窗帘 10400 10500 9400
63 洞灯 399.8 377.8 377.8
64 书桌 2000
65 35 灯具 6000
66 36 合计 354313.03 272738.43 272738.43 -4362.6 271128.43 -83184.6
67 37
68 38 双十一 38551
69

View File

@ -1,25 +1,24 @@
ChatAgent
==================================
ChatAgent can automatically select the right tool to answer and solve user problems through LLM.
![ChatAgent](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
![ChatAgent](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/chat_agent0.png)
### 1.Update Plugins From Git
Update the latest plug-in information from the DB-GPT official plug-in repository.
![Update From Github](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
![Update From Github](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/agent_hub_1.png)
### 2.Install Plugin
Install the plugin you want to use from the list of agent hub plugins.
![Install Plugin](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
![Update From Github](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/agent_hub_1.png)
### 3.Upload My Local Plugin File
If you want to use a private plug-in developed by yourself, you can upload the plug-in first and then use it.
![Upload Private Plugin](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
### 4.Select installed plug-ins dialog
Select an installed plugin to have a conversation.
![Select Plugins](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
![Select Plugins](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/chat_agent1.png)
![Success Use](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/chat_agent2.png)
### 5.Uninstall My Plugin
Uninstall plugins you no longer need.
![Uninstall Plugin](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)
![Uninstall Plugin](https://github.com/eosphoros-ai/DB-GPT/blob/82d8e4f3bd74bfe7f19b96e51d3483f382227bed/assets/chat_agent/agent_hub_2.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -97,4 +97,10 @@ pip install langchain>=0.0.286
```commandline
pip install --use-pep517 fschat
```
```
##### Q9: alembic.util.exc.CommandError: Target database is not up to date.
delete files in `DB-GPT/pilot/meta_data/alembic/versions/` and reboot.
```commandline
rm -rf DB-GPT/pilot/meta_data/alembic/versions/*
```

View File

@ -0,0 +1,98 @@
Standalone Deployment
==================================
(standalone-index)=
### Install Prepare
```commandline
git clone https://github.com/eosphoros-ai/DB-GPT.git
cd DB-GPT
```
### Create conda environment
```commandline
conda create -n dbgpt_env python=3.10
conda activate dbgpt_env
```
### Install Default Requirements
```commandline
# Install Default Requirements
pip install -e ".[default]"
```
### Download and Prepare LLM Model and Embedding Model
```{tip}
If you don't have high performance hardware server
```
you can use openai api, tongyi api , bard api, etc.
```commandline
mkdir models && cd models
# download embedding model, eg: text2vec-large-chinese
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
```
set proxy api in .env
```commandline
#set LLM_MODEL TYPE
LLM_MODEL=proxyllm
#set your Proxy Api key and Proxy Server url
PROXY_API_KEY={your-openai-sk}
PROXY_SERVER_URL=https://api.openai.com/v1/chat/completions
```
```{tip}
If you have high performance hardware server
```
```commandline
mkdir models && cd models
# # download embedding model, eg: vicuna-13b-v1.5 or
git clone https://huggingface.co/lmsys/vicuna-13b-v1.5
# download embedding model, eg: text2vec-large-chinese
git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese
popd
```
### Start all services with a single command.
```commandline
LLM_MODEL=vicuna-13b-v1.5
dbgpt start webserver --port 6006
```
By default, the "dbgpt start webserver" command will start the Webserver, Model Controller, and Model Worker in a single Python process. Here, we specify the service to be started on port 6006.
### View and validate the model service in the command line, you can use the following commands
##### 1.list the started model services and deployed Model Workers, you can use the following command
```commandline
dbgpt model list
```
output is:
```commandline
+-----------------+------------+------------+------+---------+---------+-----------------+----------------------------+
| Model Name | Model Type | Host | Port | Healthy | Enabled | Prompt Template | Last Heartbeat |
+-----------------+------------+------------+------+---------+---------+-----------------+----------------------------+
| vicuna-13b-v1.5 | llm | 172.17.0.9 | 6006 | True | True | | 2023-10-16T19:49:59.201313 |
| WorkerManager | service | 172.17.0.9 | 6006 | True | True | | 2023-10-16T19:49:59.246756 |
+-----------------+------------+------------+------+---------+---------+-----------------+----------------------------+
```
The WorkerManager is the management process for Model Workers
##### validate the deployed model in the command line, you can use the following command
```commandline
dbgpt model chat --model_name vicuna-13b-v1.5
```
Then an interactive page will be launched where you can have a conversation with the deployed LLM in the terminal.
```commandline
Chatbot started with model vicuna-13b-v1.5. Type 'exit' to leave the chat.
You: Hello
Bot: Hello! How can I assist you today?
You:
```

View File

@ -0,0 +1,123 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2023, csunny
# This file is distributed under the same license as the DB-GPT package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: DB-GPT 👏👏 0.3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-17 17:24+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
"Language-Team: zh_CN <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
#: ../../getting_started/application/chatagent/chatagent.md:1
#: ../../getting_started/application/chatagent/chatagent.md:3
#: 17aae18073594c7498c8b2434d50b218 77f0177e55e144a89e3bcf735b0d52de
msgid "ChatAgent"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:3
#: 41b42808938245dc946960571c09026a
msgid ""
"ChatAgent can automatically select the right tool to answer and solve "
"user problems through LLM. ![ChatAgent](https://github.com/eosphoros-ai"
"/DB-GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:6
#: bb76bb44442647a091d008c9e1427e4a
msgid "1.Update Plugins From Git"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:7
#: a7f188c3de7e4b85b2d3079128b535b2
msgid ""
"Update the latest plug-in information from the DB-GPT official plug-in "
"repository. ![Update From Github](https://github.com/eosphoros-ai/DB-"
"GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:7
#: 612cb75edb2f48a087fc99e6d0890b80
msgid "Update From Github"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:10
#: 1ad3f7680837410cb8018fff5787366f
msgid "2.Install Plugin"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:11
#: b32e9318a8e347339b6c4cad4b966880
msgid ""
"Install the plugin you want to use from the list of agent hub plugins. "
"![Install Plugin](https://github.com/eosphoros-ai/DB-"
"GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:11
#: bee96f7936564bc6be98655bfc6aae0d
msgid "Install Plugin"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:15
#: 20d562b9ed004336bb6df8d163554924
msgid "3.Upload My Local Plugin File"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:16
#: b43e485ff4f042dd80b5950444c0db08
msgid ""
"If you want to use a private plug-in developed by yourself, you can "
"upload the plug-in first and then use it. ![Upload Private "
"Plugin](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:16
#: a05724784c0e45528039b8238fd9ed3c
msgid "Upload Private Plugin"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:19
#: 726b5c4cad7d4be9815e9fbeedaecc2b
msgid "4.Select installed plug-ins dialog"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:20
#: e3d9dc892d054cbca29267cd0fffe7be
msgid ""
"Select an installed plugin to have a conversation. ![Select "
"Plugins](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:20
#: 97f28bacc02444c580f6481b21e6c155
msgid "Select Plugins"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:23
#: d0272e7d94d743289fb2c1613ee85c36
msgid "5.Uninstall My Plugin"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:24
#: 2fee213a12da4674b19fe8891e4318f5
msgid ""
"Uninstall plugins you no longer need. ![Uninstall "
"Plugin](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/)"
msgstr ""
#: ../../getting_started/application/chatagent/chatagent.md:24
#: 32e5405249134863bcaf85b0ef91260f
msgid "Uninstall Plugin"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: DB-GPT 👏👏 0.3.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-26 17:47+0800\n"
"POT-Creation-Date: 2023-10-19 19:31+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
@ -20,12 +20,12 @@ msgstr ""
"Generated-By: Babel 2.12.1\n"
#: ../../getting_started/faq/deploy/deploy_faq.md:1
#: ca823e9d6d1d433db7ed15c8273e1b00
#: fb640f7c38744cbf996dcf7f73f325f6
msgid "Installation FAQ"
msgstr "Installation FAQ"
#: ../../getting_started/faq/deploy/deploy_faq.md:5
#: 3803d098c534434f9f513b3a62de54a4
#: 79fd80e469d14d608554d53a0e0ed2e3
#, fuzzy
msgid ""
"Q1: execute `pip install -e .` error, found some package cannot find "
@ -35,18 +35,18 @@ msgstr ""
"cannot find correct version."
#: ../../getting_started/faq/deploy/deploy_faq.md:6
#: b785864f47e643df9a4669d8da6167d6
#: f1f6e3291d1446b5bbcf744cd4c4e89a
msgid "change the pip source."
msgstr "替换pip源."
#: ../../getting_started/faq/deploy/deploy_faq.md:13
#: ../../getting_started/faq/deploy/deploy_faq.md:20
#: c41f026fb1464c71a45d0746c224ecce f70fb69b568d4fc4ad4c4731b2032eaf
#: 68e1b39a08774a81b9061cc5205e4c1c dd34901f446749e998cd34ec5b6c44f4
msgid "or"
msgstr "或者"
#: ../../getting_started/faq/deploy/deploy_faq.md:27
#: d179e3d695764f838dc354eb0d978bb3
#: 0899f0e28dae443b8f912d96c797b79c
msgid ""
"Q2: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to"
" open database file"
@ -55,86 +55,97 @@ msgstr ""
" open database file"
#: ../../getting_started/faq/deploy/deploy_faq.md:29
#: 55174e8d247a414e8c6c8861d4707a55
#: 3e60d8190e49436b8c40b34a67b7bfb3
msgid "make sure you pull latest code or create directory with mkdir pilot/data"
msgstr "make sure you pull latest code or create directory with mkdir pilot/data"
#: ../../getting_started/faq/deploy/deploy_faq.md:31
#: dbce9e9cae734a5083a6f0fc28bce7cd
#: baeaae20238842d3b8e4ae5b337198e5
msgid "Q3: The model keeps getting killed."
msgstr "Q3: The model keeps getting killed."
#: ../../getting_started/faq/deploy/deploy_faq.md:33
#: 2de5648d2e7546bf85f20f4162003298
#: eb3936307ad64b19b73483ff9ae126f2
msgid ""
"your GPU VRAM size is not enough, try replace your hardware or replace "
"other llms."
msgstr "GPU显存不够, 增加显存或者换一个显存小的模型"
#: ../../getting_started/faq/deploy/deploy_faq.md:35
#: 47810771cd364964b9b5b8fd85bca4ee
#: f6dba770717041699c73b4cd00d48aad
msgid "Q4: How to access website on the public network"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:37
#: e8c5bac6680648509d528ea6aaf5994e
#: 447d9e9374de44bab6d8a03f2c936676
msgid ""
"You can try to use gradio's [network](https://github.com/gradio-"
"app/gradio/blob/main/gradio/networking.py) to achieve."
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:48
#: bb75ec127f574c00a09d92d5206e9357
#: 5e34dd4dfcf34feeb1815dfa974041d0
msgid "Open `url` with your browser to see the website."
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:50
#: 5fdb87b84bd94385a1a93dab8d41ebe8
#: aaef774ce6124021a3862bc0a25d465f
msgid "Q5: (Windows) execute `pip install -e .` error"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:52
#: 31eef51e044044f29f3ad08defa9c305
#: ec3945df451c4ec2b32ebb476f45c82b
msgid "The error log like the following:"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:71
#: aaba0c3060b443e4b9877f70d78321ce
#: 1df09f6d9f9b4c1a8a32d6e271e5ee39
msgid ""
"Download and install `Microsoft C++ Build Tools` from [visual-cpp-build-"
"tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:75
#: 4c8137546e5c4240884f7ea6d9d922bf
#: 251f47bfa5694242a1c9d81a2022b7a0
msgid "Q6: `Torch not compiled with CUDA enabled`"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:82
#: 01daf14f8c494219b1d9a5af4449951e
#: bc9dfdfc47924a0e8d3ec535e23bf923
msgid "Install [CUDA Toolkit](https://developer.nvidia.com/cuda-toolkit-archive)"
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:83
#: c75e6371911e4d5ca6859e51501c9679
#: b5a632baa42745bdbee5d6ba516d8d8b
msgid ""
"Reinstall PyTorch [start-locally](https://pytorch.org/get-started/locally"
"/#start-locally) with CUDA support."
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:85
#: 7cfb9003e505445ebb9ed3d015e184e2
#: 0092fb91642749f5a55b629017c0de6a
msgid "Q7: ImportError: cannot import name 'PersistentClient' from 'chromadb'."
msgstr "Q7: ImportError: cannot import name 'PersistentClient' from 'chromadb'."
#: ../../getting_started/faq/deploy/deploy_faq.md:91
#: e1d5d5d85ddc480d8d81f7b550848cbf
#: 4aa87418f2a54c138bf3b7ff28a7e776
msgid ""
"Q8: pydantic.error_wrappers.ValidationError:1 validation error for "
"HuggingFaceEmbeddings.model_kwargs extra not permitted"
msgstr "Q8: pydantic.error_wrappers.ValidationError:1 validation error for "
msgstr ""
"Q8: pydantic.error_wrappers.ValidationError:1 validation error for "
"HuggingFaceEmbeddings.model_kwargs extra not permitted"
#: ../../getting_started/faq/deploy/deploy_faq.md:102
#: 6b690ab272af44f6b126cfe5ce1435ef
msgid "Q9: alembic.util.exc.CommandError: Target database is not up to date."
msgstr ""
#: ../../getting_started/faq/deploy/deploy_faq.md:103
#: 223026d3b9124363b695937922d8f8d5
msgid "delete files in `DB-GPT/pilot/meta_data/alembic/versions/` and reboot."
msgstr "删除`DB-GPT/pilot/meta_data/alembic/versions/`目录下文件"
#~ msgid ""
#~ "Q2: When use Mysql, Access denied "
#~ "for user 'root@localhost'(using password :NO)"

View File

@ -0,0 +1,117 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2023, csunny
# This file is distributed under the same license as the DB-GPT package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: DB-GPT 👏👏 0.3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-17 17:24+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
"Language-Team: zh_CN <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
#: ../../getting_started/install/cluster/vms/standalone.md:1
#: 40af95d327574e5ea9a6c29f68a7709c
msgid "Standalone Deployment"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:5
#: 7ef23971a0d2415a857d5eb9c4d955ac
msgid "Install Prepare"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:12
#: f3cd2941fa2d49d686fc246237f82e68
msgid "Create conda environment"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:20
#: 589d80d5d97044ee93747091904583c5
msgid "Install Default Requirements"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:26
#: 1d151e72660644e7b43084ffccb99598
msgid "Download and Prepare LLM Model and Embedding Model"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:28
#: 4443c83f8dfa4fdba30929f1e5ecf619
msgid "If you don't have high performance hardware server"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:30
#: 33a6ee878a4a467d8bcfe5dfbdcbe184
msgid "you can use openai api, tongyi api , bard api, etc."
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:39
#: 7efdb99bc36d42819b1fcd1341b45eef
msgid "set proxy api in .env"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:48
#: 50154ece70bc421ebe7ac05966369bc8
msgid "If you have high performance hardware server"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:62
#: 4f3696ed069a4a84b2d794593df23765
msgid "Start all services with a single command."
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:67
#: f5f671962cb14a10aba34c4274d2fc2c
msgid ""
"By default, the \"dbgpt start webserver\" command will start the "
"Webserver, Model Controller, and Model Worker in a single Python process."
" Here, we specify the service to be started on port 6006."
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:69
#: 4883221a356843f6a6335c25847aecd2
msgid ""
"View and validate the model service in the command line, you can use the "
"following commands"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:70
#: 1346eb55d7c647be90a90a867ba04ec3
msgid ""
"1.list the started model services and deployed Model Workers, you can use"
" the following command"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:74
#: 8ab332ebce554758952dbe85c68330a9
msgid "output is:"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:83
#: efb460bbb70842218f5c056cf05ba1a0
msgid "The WorkerManager is the management process for Model Workers"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:85
#: 10e5b79f3d914ee3974b1a0d07962fe2
msgid ""
"validate the deployed model in the command line, you can use the "
"following command"
msgstr ""
#: ../../getting_started/install/cluster/vms/standalone.md:89
#: 39d062e7fea948949c1c5c099893f308
msgid ""
"Then an interactive page will be launched where you can have a "
"conversation with the deployed LLM in the terminal."
msgstr ""

View File

@ -9,7 +9,10 @@ from pilot.base_modules.meta_data.meta_data import Base, engine, session
class MyPluginEntity(Base):
__tablename__ = "my_plugin"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True, comment="autoincrement id")
tenant = Column(String(255), nullable=True, comment="user's tenant")
user_code = Column(String(255), nullable=False, comment="user code")
@ -27,7 +30,7 @@ class MyPluginEntity(Base):
created_at = Column(
DateTime, default=datetime.utcnow, comment="plugin install time"
)
__table_args__ = (UniqueConstraint("user_code", "name", name="uk_name"),)
UniqueConstraint("user_code", "name", name="uk_name")
class MyPluginDao(BaseDao[MyPluginEntity]):

View File

@ -1,7 +1,7 @@
from datetime import datetime
import pytz
from typing import List
from sqlalchemy import Column, Integer, String, Index, DateTime, func, Boolean
from sqlalchemy import Column, Integer, String, Index, DateTime, func, Boolean, DDL
from sqlalchemy import UniqueConstraint
from pilot.base_modules.meta_data.meta_data import Base
@ -9,8 +9,15 @@ from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
char_set_sql = DDL("ALTER TABLE plugin_hub CONVERT TO CHARACTER SET utf8mb4")
class PluginHubEntity(Base):
__tablename__ = "plugin_hub"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(
Integer, primary_key=True, autoincrement=True, comment="autoincrement id"
)
@ -26,10 +33,8 @@ class PluginHubEntity(Base):
created_at = Column(DateTime, default=datetime.utcnow, comment="plugin upload time")
installed = Column(Integer, default=False, comment="plugin already installed count")
__table_args__ = (
UniqueConstraint("name", name="uk_name"),
Index("idx_q_type", "type"),
)
UniqueConstraint("name", name="uk_name")
Index("idx_q_type", "type")
class PluginHubDao(BaseDao[PluginHubEntity]):

View File

@ -154,7 +154,7 @@ class ConnectManager:
db_type = DBType.of_db_type(db_info.db_type)
connect_instance = self.get_cls_by_dbtype(db_type.value())
if db_type.is_file_db():
db_path = db_info.db_path
db_path = db_info.file_path
return connect_instance.from_file_path(db_path)
else:
db_name = db_info.db_name

View File

@ -52,7 +52,18 @@ class RDBMSDatabase(BaseConnect):
custom_table_info: Optional[dict] = None,
view_support: bool = False,
):
"""Create engine from database URI."""
"""Create engine from database URI.
Args:
- engine: Engine sqlalchemy.engine
- schema: Optional[str].
- metadata: Optional[MetaData]
- ignore_tables: Optional[List[str]]
- include_tables: Optional[List[str]]
- sample_rows_in_table_info: int default:3,
- indexes_in_table_info: bool = False,
- custom_table_info: Optional[dict] = None,
- view_support: bool = False,
"""
self._engine = engine
self._schema = schema
if include_tables and ignore_tables:
@ -92,6 +103,15 @@ class RDBMSDatabase(BaseConnect):
engine_args: Optional[dict] = None,
**kwargs: Any,
) -> RDBMSDatabase:
"""Construct a SQLAlchemy engine from uri database.
Args:
host (str): database host.
port (int): database port.
user (str): database user.
pwd (str): database password.
db_name (str): database name.
engine_args (Optional[dict]):other engine_args.
"""
db_url: str = (
cls.driver
+ "://"
@ -329,7 +349,7 @@ class RDBMSDatabase(BaseConnect):
def run(self, command: str, fetch: str = "all") -> List:
"""Execute a SQL command and return a string representing the results."""
print("SQL:" + command)
if not command:
if not command or len(command) <0:
return []
parsed, ttype, sql_type, table_name = self.__sql_parse(command)
if ttype == sqlparse.tokens.DML:

View File

@ -21,7 +21,13 @@ class CSVEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize with csv path."""
"""Initialize with csv path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path, vector_store_config, source_reader=None, text_splitter=None
)

View File

@ -28,7 +28,16 @@ class EmbeddingEngine:
text_splitter: Optional[TextSplitter] = None,
embedding_factory: EmbeddingFactory = None,
):
"""Initialize with knowledge embedding client, model_name, vector_store_config, knowledge_type, knowledge_source"""
"""Initialize with knowledge embedding client, model_name, vector_store_config, knowledge_type, knowledge_source
Args:
- model_name: model_name
- vector_store_config: vector store config: Dict
- knowledge_type: Optional[KnowledgeType]
- knowledge_source: Optional[str]
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
- embedding_factory: EmbeddingFactory
"""
self.knowledge_source = knowledge_source
self.model_name = model_name
self.vector_store_config = vector_store_config
@ -65,6 +74,11 @@ class EmbeddingEngine:
)
def similar_search(self, text, topk):
"""vector db similar search
Args:
- text: query text
- topk: top k
"""
vector_client = VectorStoreConnector(
self.vector_store_config["vector_store_type"], self.vector_store_config
)
@ -75,12 +89,17 @@ class EmbeddingEngine:
return ans
def vector_exist(self):
"""vector db is exist"""
vector_client = VectorStoreConnector(
self.vector_store_config["vector_store_type"], self.vector_store_config
)
return vector_client.vector_name_exists()
def delete_by_ids(self, ids):
"""delete vector db by ids
Args:
- ids: vector ids
"""
vector_client = VectorStoreConnector(
self.vector_store_config["vector_store_type"], self.vector_store_config
)

View File

@ -23,7 +23,13 @@ class PDFEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize pdf word path."""
"""Initialize pdf word path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path, vector_store_config, source_reader=None, text_splitter=None
)

View File

@ -23,7 +23,13 @@ class PPTEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize ppt word path."""
"""Initialize ppt word path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path, vector_store_config, source_reader=None, text_splitter=None
)

View File

@ -29,7 +29,14 @@ class SourceEmbedding(ABC):
text_splitter: Optional[TextSplitter] = None,
embedding_args: Optional[Dict] = None,
):
"""Initialize with Loader url, model_name, vector_store_config"""
"""Initialize with Loader url, model_name, vector_store_config
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
- embedding_args: Optional
"""
self.file_path = file_path
self.vector_store_config = vector_store_config
self.source_reader = source_reader or None
@ -44,21 +51,33 @@ class SourceEmbedding(ABC):
@register
def data_process(self, text):
"""pre process data."""
"""pre process data.
Args:
- text: raw text
"""
@register
def text_splitter(self, text_splitter: TextSplitter):
"""add text split chunk"""
"""add text split chunk
Args:
- text_splitter: TextSplitter
"""
pass
@register
def text_to_vector(self, docs):
"""transform vector"""
"""transform vector
Args:
- docs: List[Document]
"""
pass
@register
def index_to_store(self, docs):
"""index to vector store"""
"""index to vector store
Args:
- docs: List[Document]
"""
self.vector_client = VectorStoreConnector(
self.vector_store_config["vector_store_type"], self.vector_store_config
)
@ -66,7 +85,10 @@ class SourceEmbedding(ABC):
@register
def similar_search(self, doc, topk):
"""vector store similarity_search"""
"""vector store similarity_search
Args:
- query: query
"""
self.vector_client = VectorStoreConnector(
self.vector_store_config["vector_store_type"], self.vector_store_config
)
@ -82,6 +104,7 @@ class SourceEmbedding(ABC):
return self.vector_client.vector_name_exists()
def source_embedding(self):
"""read()->data_process()->text_split()->index_to_store()"""
if "read" in registered_methods:
text = self.read()
if "data_process" in registered_methods:

View File

@ -20,7 +20,13 @@ class StringEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize raw text word path."""
"""Initialize raw text word path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path=file_path,
vector_store_config=vector_store_config,

View File

@ -22,7 +22,13 @@ class URLEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize url word path."""
"""Initialize url word path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path, vector_store_config, source_reader=None, text_splitter=None
)

View File

@ -23,7 +23,13 @@ class WordEmbedding(SourceEmbedding):
source_reader: Optional = None,
text_splitter: Optional[TextSplitter] = None,
):
"""Initialize with word path."""
"""Initialize with word path.
Args:
- file_path: data source path
- vector_store_config: vector store config params.
- source_reader: Optional[BaseLoader]
- text_splitter: Optional[TextSplitter]
"""
super().__init__(
file_path, vector_store_config, source_reader=None, text_splitter=None
)

View File

@ -10,6 +10,10 @@ class ChatHistoryEntity(Base):
id = Column(
Integer, primary_key=True, autoincrement=True, comment="autoincrement id"
)
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
conv_uid = Column(
String(255),
unique=False,
@ -21,12 +25,10 @@ class ChatHistoryEntity(Base):
user_name = Column(String(255), nullable=True, comment="interlocutor")
messages = Column(Text, nullable=True, comment="Conversation details")
__table_args__ = (
UniqueConstraint("conv_uid", name="uk_conversation"),
Index("idx_q_user", "user_name"),
Index("idx_q_mode", "chat_mode"),
Index("idx_q_conv", "summary"),
)
UniqueConstraint("conv_uid", name="uk_conversation")
Index("idx_q_user", "user_name")
Index("idx_q_mode", "chat_mode")
Index("idx_q_conv", "summary")
class ChatHistoryDao(BaseDao[ChatHistoryEntity]):

View File

@ -185,7 +185,7 @@ def run_model_controller():
setup_logging(
"pilot",
logging_level=controller_params.log_level,
logger_filename="dbgpt_model_controller.log",
logger_filename=controller_params.log_file,
)
initialize_controller(host=controller_params.host, port=controller_params.port)

View File

@ -1006,7 +1006,7 @@ def run_worker_manager(
setup_logging(
"pilot",
logging_level=worker_params.log_level,
logger_filename="dbgpt_model_worker_manager.log",
logger_filename=worker_params.log_file,
)
embedded_mod = True
@ -1019,7 +1019,7 @@ def run_worker_manager(
system_app = SystemApp(app)
initialize_tracer(
system_app,
os.path.join(LOGDIR, "dbgpt_model_worker_manager_tracer.jsonl"),
os.path.join(LOGDIR, worker_params.tracer_file),
root_operation_name="DB-GPT-WorkerManager-Entry",
)

View File

@ -46,6 +46,18 @@ class ModelControllerParameters(BaseParameters):
],
},
)
log_file: Optional[str] = field(
default="dbgpt_model_controller.log",
metadata={
"help": "The filename to store log",
},
)
tracer_file: Optional[str] = field(
default="dbgpt_model_controller_tracer.jsonl",
metadata={
"help": "The filename to store tracer span records",
},
)
@dataclass
@ -122,6 +134,18 @@ class ModelWorkerParameters(BaseModelParameters):
],
},
)
log_file: Optional[str] = field(
default="dbgpt_model_worker_manager.log",
metadata={
"help": "The filename to store log",
},
)
tracer_file: Optional[str] = field(
default="dbgpt_model_worker_manager_tracer.jsonl",
metadata={
"help": "The filename to store tracer span records",
},
)
@dataclass

View File

@ -1,16 +1,18 @@
from datetime import datetime
from sqlalchemy import Column, Integer, Text, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from pilot.connections.rdbms.base_dao import BaseDao
from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
from pilot.openapi.api_v1.feedback.feed_back_model import FeedBackBody
Base = declarative_base()
class ChatFeedBackEntity(Base):
__tablename__ = "chat_feed_back"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
conv_uid = Column(String(128))
conv_index = Column(Integer)
@ -33,13 +35,15 @@ class ChatFeedBackEntity(Base):
class ChatFeedBackDao(BaseDao):
def __init__(self):
super().__init__(database="history", orm_base=Base, create_not_exist_table=True)
super().__init__(
database="dbgpt", orm_base=Base, db_engine=engine, session=session
)
def create_or_update_chat_feed_back(self, feed_back: FeedBackBody):
# Todo: We need to have user information first.
def_user_name = ""
session = self.Session()
session = self.get_session()
chat_feed_back = ChatFeedBackEntity(
conv_uid=feed_back.conv_uid,
conv_index=feed_back.conv_index,
@ -73,7 +77,7 @@ class ChatFeedBackDao(BaseDao):
session.close()
def get_chat_feed_back(self, conv_uid: str, conv_index: int):
session = self.Session()
session = self.get_session()
result = (
session.query(ChatFeedBackEntity)
.filter(ChatFeedBackEntity.conv_uid == conv_uid)

View File

@ -21,6 +21,12 @@ CFG = Config()
class BaseChat(ABC):
"""DB-GPT Chat Service Base Module
Include:
stream_call():scene + prompt -> stream response
nostream_call():scene + prompt -> nostream response
"""
chat_scene: str = None
llm_model: Any = None
# By default, keep the last two rounds of conversation records as the context
@ -32,6 +38,14 @@ class BaseChat(ABC):
arbitrary_types_allowed = True
def __init__(self, chat_param: Dict):
"""Chat Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) select param
"""
self.chat_session_id = chat_param["chat_session_id"]
self.chat_mode = chat_param["chat_mode"]
self.current_user_input: str = chat_param["current_user_input"]
@ -359,7 +373,10 @@ class BaseChat(ABC):
)
if len(self.history_message) > self.chat_retention_rounds:
for first_message in self.history_message[0]["messages"]:
if not first_message["type"] in [ModelMessageRoleType.VIEW, ModelMessageRoleType.SYSTEM]:
if not first_message["type"] in [
ModelMessageRoleType.VIEW,
ModelMessageRoleType.SYSTEM,
]:
message_type = first_message["type"]
message_content = first_message["data"]["content"]
history_text += (

View File

@ -18,10 +18,20 @@ logger = logging.getLogger("chat_agent")
class ChatAgent(BaseChat):
"""Chat With Agent through plugin"""
chat_scene: str = ChatScene.ChatAgent.value()
chat_retention_rounds = 0
def __init__(self, chat_param: Dict):
"""Chat Agent Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) agent plugin
"""
if not chat_param["select_param"]:
raise ValueError("Please select a Plugin!")
self.select_plugins = chat_param["select_param"].split(",")
@ -53,7 +63,6 @@ class ChatAgent(BaseChat):
def stream_plugin_call(self, text):
text = text.replace("\n", " ")
print(f"stream_plugin_call:{text}")
return self.api_call.run(text)
def __list_to_prompt_str(self, list: List) -> str:

View File

@ -19,10 +19,17 @@ CFG = Config()
class ChatDashboard(BaseChat):
chat_scene: str = ChatScene.ChatDashboard.value()
report_name: str
"""Number of results to return from the query"""
"""Chat Dashboard to generate dashboard chart"""
def __init__(self, chat_param: Dict):
""" """
"""Chat Dashboard Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) dbname
"""
self.db_name = chat_param["select_param"]
chat_param["chat_mode"] = ChatScene.ChatDashboard
super().__init__(chat_param=chat_param)

View File

@ -19,10 +19,20 @@ CFG = Config()
class ChatExcel(BaseChat):
"""a Excel analyzer to analyze Excel Data"""
chat_scene: str = ChatScene.ChatExcel.value()
chat_retention_rounds = 1
def __init__(self, chat_param: Dict):
"""Chat Excel Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) file path
"""
chat_mode = ChatScene.ChatExcel
self.select_param = chat_param["select_param"]
@ -78,5 +88,4 @@ class ChatExcel(BaseChat):
def stream_plugin_call(self, text):
text = text.replace("\n", " ")
print(f"stream_plugin_call:{text}")
return self.api_call.run_display_sql(text, self.excel_reader.get_df_by_sql_ex)

View File

@ -16,6 +16,14 @@ class ChatWithDbAutoExecute(BaseChat):
"""Number of results to return from the query"""
def __init__(self, chat_param: Dict):
"""Chat Data Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) dbname
"""
chat_mode = ChatScene.ChatWithDbExecute
self.db_name = chat_param["select_param"]
chat_param["chat_mode"] = chat_mode
@ -33,6 +41,9 @@ class ChatWithDbAutoExecute(BaseChat):
self.api_call = ApiCall(display_registry=CFG.command_disply)
def generate_input_values(self):
"""
generate input values
"""
try:
from pilot.summary.db_summary_client import DBSummaryClient
except ImportError:

View File

@ -36,8 +36,8 @@ class DbChatOutputParser(BaseOutputParser):
### tool out data to table view
data_loader = DbDataLoader()
if len(data) <= 1:
data.insert(0, ["result"])
if len(data) < 1:
data.insert(0, [])
df = pd.DataFrame(data[1:], columns=data[0])
if not CFG.NEW_SERVER_MODE and not CFG.SERVER_LIGHT_MODE:
table_style = """<style>

View File

@ -3,7 +3,7 @@ class DbDataLoader:
import pandas as pd
### tool out data to table view
if len(data) <= 1:
if len(data) < 1:
data.insert(0, ["result"])
df = pd.DataFrame(data[1:], columns=data[0])
html_table = df.to_html(index=False, escape=False, sparsify=False)

View File

@ -12,10 +12,17 @@ CFG = Config()
class ChatWithDbQA(BaseChat):
chat_scene: str = ChatScene.ChatWithDbQA.value()
"""Number of results to return from the query"""
"""As a DBA, Chat DB Module, chat with combine DB meta schema """
def __init__(self, chat_param: Dict):
""" """
"""Chat DB Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) dbname
"""
self.db_name = chat_param["select_param"]
chat_param["chat_mode"] = ChatScene.ChatWithDbQA
super().__init__(chat_param=chat_param)

View File

@ -11,11 +11,21 @@ CFG = Config()
class ChatWithPlugin(BaseChat):
"""Chat With Plugin"""
chat_scene: str = ChatScene.ChatExecution.value()
plugins_prompt_generator: PluginPromptGenerator
select_plugin: str = None
def __init__(self, chat_param: Dict):
"""Chat Dashboard Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) plugin selector
"""
self.plugin_selector = chat_param["select_param"]
chat_param["chat_mode"] = ChatScene.ChatExecution
super().__init__(chat_param=chat_param)

View File

@ -19,10 +19,17 @@ CFG = Config()
class ChatKnowledge(BaseChat):
chat_scene: str = ChatScene.ChatKnowledge.value()
"""Number of results to return from the query"""
"""KBQA Chat Module"""
def __init__(self, chat_param: Dict):
""" """
"""Chat Knowledge Module Initialization
Args:
- chat_param: Dict
- chat_session_id: (str) chat session_id
- current_user_input: (str) current user input
- model_name:(str) llm model name
- select_param:(str) space name
"""
from pilot.embedding_engine.embedding_engine import EmbeddingEngine
from pilot.embedding_engine.embedding_factory import EmbeddingFactory
@ -92,7 +99,7 @@ class ChatKnowledge(BaseChat):
context = [d.page_content for d in docs]
context = context[: self.max_token]
relations = list(
set([os.path.basename(d.metadata.get("source", "")) for d in docs])
set([os.path.basename(str(d.metadata.get("source", ""))) for d in docs])
)
input_values = {
"context": context,

View File

@ -21,6 +21,7 @@ def signal_handler(sig, frame):
def async_db_summary(system_app: SystemApp):
"""async db schema into vector db"""
from pilot.summary.db_summary_client import DBSummaryClient
client = DBSummaryClient(system_app=system_app)
@ -94,6 +95,19 @@ class WebWerverParameters(BaseParameters):
daemon: Optional[bool] = field(
default=False, metadata={"help": "Run Webserver in background"}
)
controller_addr: Optional[str] = field(
default=None,
metadata={
"help": "The Model controller address to connect. If None, read model controller address from environment key `MODEL_SERVER`."
},
)
model_name: str = field(
default=None,
metadata={
"help": "The default model name to use. If None, read model name from environment key `LLM_MODEL`.",
"tags": "fixed",
},
)
share: Optional[bool] = field(
default=False,
metadata={
@ -122,3 +136,15 @@ class WebWerverParameters(BaseParameters):
},
)
light: Optional[bool] = field(default=False, metadata={"help": "enable light mode"})
log_file: Optional[str] = field(
default="dbgpt_webserver.log",
metadata={
"help": "The filename to store log",
},
)
tracer_file: Optional[str] = field(
default="dbgpt_webserver_tracer.jsonl",
metadata={
"help": "The filename to store tracer span records",
},
)

View File

@ -115,6 +115,9 @@ def _get_webserver_params(args: List[str] = None):
def initialize_app(param: WebWerverParameters = None, args: List[str] = None):
"""Initialize app
If you use gunicorn as a process manager, initialize_app can be invoke in `on_starting` hook.
Args:
param:WebWerverParameters
args:List[str]
"""
if not param:
param = _get_webserver_params(args)
@ -122,7 +125,7 @@ def initialize_app(param: WebWerverParameters = None, args: List[str] = None):
if not param.log_level:
param.log_level = _get_logging_level()
setup_logging(
"pilot", logging_level=param.log_level, logger_filename="dbgpt_webserver.log"
"pilot", logging_level=param.log_level, logger_filename=param.log_file
)
# Before start
system_app.before_start()
@ -136,14 +139,16 @@ def initialize_app(param: WebWerverParameters = None, args: List[str] = None):
model_start_listener = _create_model_start_listener(system_app)
initialize_components(param, system_app, embedding_model_name, embedding_model_path)
model_path = LLM_MODEL_CONFIG.get(CFG.LLM_MODEL)
model_name = param.model_name or CFG.LLM_MODEL
model_path = LLM_MODEL_CONFIG.get(model_name)
if not param.light:
print("Model Unified Deployment Mode!")
if not param.remote_embedding:
embedding_model_name, embedding_model_path = None, None
initialize_worker_manager_in_client(
app=app,
model_name=CFG.LLM_MODEL,
model_name=model_name,
model_path=model_path,
local_port=param.port,
embedding_model_name=embedding_model_name,
@ -155,12 +160,13 @@ def initialize_app(param: WebWerverParameters = None, args: List[str] = None):
CFG.NEW_SERVER_MODE = True
else:
# MODEL_SERVER is controller address now
controller_addr = param.controller_addr or CFG.MODEL_SERVER
initialize_worker_manager_in_client(
app=app,
model_name=CFG.LLM_MODEL,
model_name=model_name,
model_path=model_path,
run_locally=False,
controller_addr=CFG.MODEL_SERVER,
controller_addr=controller_addr,
local_port=param.port,
start_listener=model_start_listener,
system_app=system_app,
@ -185,7 +191,7 @@ def run_uvicorn(param: WebWerverParameters):
def run_webserver(param: WebWerverParameters = None):
if not param:
param = _get_webserver_params()
initialize_tracer(system_app, os.path.join(LOGDIR, "dbgpt_webserver_tracer.jsonl"))
initialize_tracer(system_app, os.path.join(LOGDIR, param.tracer_file))
with root_tracer.start_span(
"run_webserver",

View File

@ -2,18 +2,20 @@ from datetime import datetime
from typing import List
from sqlalchemy import Column, String, DateTime, Integer, Text, func
from sqlalchemy.orm import declarative_base
from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
from pilot.configs.config import Config
from pilot.connections.rdbms.base_dao import BaseDao
CFG = Config()
Base = declarative_base()
class DocumentChunkEntity(Base):
__tablename__ = "document_chunk"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
document_id = Column(Integer)
doc_name = Column(String(100))
@ -30,11 +32,11 @@ class DocumentChunkEntity(Base):
class DocumentChunkDao(BaseDao):
def __init__(self):
super().__init__(
database="knowledge_management", orm_base=Base, create_not_exist_table=True
database="dbgpt", orm_base=Base, db_engine=engine, session=session
)
def create_documents_chunks(self, documents: List):
session = self.Session()
session = self.get_session()
docs = [
DocumentChunkEntity(
doc_name=document.doc_name,
@ -52,7 +54,7 @@ class DocumentChunkDao(BaseDao):
session.close()
def get_document_chunks(self, query: DocumentChunkEntity, page=1, page_size=20):
session = self.Session()
session = self.get_session()
document_chunks = session.query(DocumentChunkEntity)
if query.id is not None:
document_chunks = document_chunks.filter(DocumentChunkEntity.id == query.id)
@ -82,7 +84,7 @@ class DocumentChunkDao(BaseDao):
return result
def get_document_chunks_count(self, query: DocumentChunkEntity):
session = self.Session()
session = self.get_session()
document_chunks = session.query(func.count(DocumentChunkEntity.id))
if query.id is not None:
document_chunks = document_chunks.filter(DocumentChunkEntity.id == query.id)
@ -107,13 +109,13 @@ class DocumentChunkDao(BaseDao):
return count
# def update_knowledge_document(self, document:KnowledgeDocumentEntity):
# session = self.Session()
# session = self.get_session()
# updated_space = session.merge(document)
# session.commit()
# return updated_space.id
def delete(self, document_id: int):
session = self.Session()
session = self.get_session()
if document_id is None:
raise Exception("document_id is None")
query = DocumentChunkEntity(document_id=document_id)

View File

@ -1,18 +1,20 @@
from datetime import datetime
from sqlalchemy import Column, String, DateTime, Integer, Text, func
from sqlalchemy.orm import declarative_base
from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
from pilot.configs.config import Config
from pilot.connections.rdbms.base_dao import BaseDao
CFG = Config()
Base = declarative_base()
class KnowledgeDocumentEntity(Base):
__tablename__ = "knowledge_document"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
doc_name = Column(String(100))
doc_type = Column(String(100))
@ -26,6 +28,8 @@ class KnowledgeDocumentEntity(Base):
gmt_created = Column(DateTime)
gmt_modified = Column(DateTime)
__table_args__ = {"mysql_charset": "utf8mb4"}
def __repr__(self):
return f"KnowledgeDocumentEntity(id={self.id}, doc_name='{self.doc_name}', doc_type='{self.doc_type}', chunk_size='{self.chunk_size}', status='{self.status}', last_sync='{self.last_sync}', content='{self.content}', result='{self.result}', gmt_created='{self.gmt_created}', gmt_modified='{self.gmt_modified}')"
@ -33,11 +37,11 @@ class KnowledgeDocumentEntity(Base):
class KnowledgeDocumentDao(BaseDao):
def __init__(self):
super().__init__(
database="knowledge_management", orm_base=Base, create_not_exist_table=True
database="dbgpt", orm_base=Base, db_engine=engine, session=session
)
def create_knowledge_document(self, document: KnowledgeDocumentEntity):
session = self.Session()
session = self.get_session()
knowledge_document = KnowledgeDocumentEntity(
doc_name=document.doc_name,
doc_type=document.doc_type,
@ -58,7 +62,7 @@ class KnowledgeDocumentDao(BaseDao):
return doc_id
def get_knowledge_documents(self, query, page=1, page_size=20):
session = self.Session()
session = self.get_session()
knowledge_documents = session.query(KnowledgeDocumentEntity)
if query.id is not None:
knowledge_documents = knowledge_documents.filter(
@ -92,7 +96,7 @@ class KnowledgeDocumentDao(BaseDao):
return result
def get_documents(self, query):
session = self.Session()
session = self.get_session()
knowledge_documents = session.query(KnowledgeDocumentEntity)
if query.id is not None:
knowledge_documents = knowledge_documents.filter(
@ -123,7 +127,7 @@ class KnowledgeDocumentDao(BaseDao):
return result
def get_knowledge_documents_count(self, query):
session = self.Session()
session = self.get_session()
knowledge_documents = session.query(func.count(KnowledgeDocumentEntity.id))
if query.id is not None:
knowledge_documents = knowledge_documents.filter(
@ -150,14 +154,14 @@ class KnowledgeDocumentDao(BaseDao):
return count
def update_knowledge_document(self, document: KnowledgeDocumentEntity):
session = self.Session()
session = self.get_session()
updated_space = session.merge(document)
session.commit()
return updated_space.id
#
def delete(self, query: KnowledgeDocumentEntity):
session = self.Session()
session = self.get_session()
knowledge_documents = session.query(KnowledgeDocumentEntity)
if query.id is not None:
knowledge_documents = knowledge_documents.filter(

View File

@ -57,12 +57,21 @@ class SyncStatus(Enum):
# @singleton
class KnowledgeService:
"""KnowledgeService
Knowledge Management Service:
-knowledge_space management
-knowledge_document management
-embedding management
"""
def __init__(self):
pass
"""create knowledge space"""
def create_knowledge_space(self, request: KnowledgeSpaceRequest):
"""create knowledge space
Args:
- request: KnowledgeSpaceRequest
"""
query = KnowledgeSpaceEntity(
name=request.name,
)
@ -72,9 +81,11 @@ class KnowledgeService:
knowledge_space_dao.create_knowledge_space(request)
return True
"""create knowledge document"""
def create_knowledge_document(self, space, request: KnowledgeDocumentRequest):
"""create knowledge document
Args:
- request: KnowledgeDocumentRequest
"""
query = KnowledgeDocumentEntity(doc_name=request.doc_name, space=space)
documents = knowledge_document_dao.get_knowledge_documents(query)
if len(documents) > 0:
@ -91,9 +102,11 @@ class KnowledgeService:
)
return knowledge_document_dao.create_knowledge_document(document)
"""get knowledge space"""
def get_knowledge_space(self, request: KnowledgeSpaceRequest):
"""get knowledge space
Args:
- request: KnowledgeSpaceRequest
"""
query = KnowledgeSpaceEntity(
name=request.name, vector_type=request.vector_type, owner=request.owner
)
@ -116,6 +129,10 @@ class KnowledgeService:
return responses
def arguments(self, space_name):
"""show knowledge space arguments
Args:
- space_name: Knowledge Space Name
"""
query = KnowledgeSpaceEntity(name=space_name)
spaces = knowledge_space_dao.get_knowledge_space(query)
if len(spaces) != 1:
@ -128,6 +145,11 @@ class KnowledgeService:
return json.loads(context)
def argument_save(self, space_name, argument_request: SpaceArgumentRequest):
"""save argument
Args:
- space_name: Knowledge Space Name
- argument_request: SpaceArgumentRequest
"""
query = KnowledgeSpaceEntity(name=space_name)
spaces = knowledge_space_dao.get_knowledge_space(query)
if len(spaces) != 1:
@ -136,9 +158,12 @@ class KnowledgeService:
space.context = argument_request.argument
return knowledge_space_dao.update_knowledge_space(space)
"""get knowledge get_knowledge_documents"""
def get_knowledge_documents(self, space, request: DocumentQueryRequest):
"""get knowledge documents
Args:
- space: Knowledge Space Name
- request: DocumentQueryRequest
"""
query = KnowledgeDocumentEntity(
doc_name=request.doc_name,
doc_type=request.doc_type,
@ -153,9 +178,12 @@ class KnowledgeService:
res.page = request.page
return res
"""sync knowledge document chunk into vector store"""
def sync_knowledge_document(self, space_name, sync_request: DocumentSyncRequest):
"""sync knowledge document chunk into vector store
Args:
- space: Knowledge Space Name
- sync_request: DocumentSyncRequest
"""
from pilot.embedding_engine.embedding_engine import EmbeddingEngine
from pilot.embedding_engine.embedding_factory import EmbeddingFactory
from pilot.embedding_engine.pre_text_splitter import PreTextSplitter
@ -249,11 +277,6 @@ class KnowledgeService:
doc.chunk_size = len(chunk_docs)
doc.gmt_modified = datetime.now()
knowledge_document_dao.update_knowledge_document(doc)
# async doc embeddings
# thread = threading.Thread(
# target=self.async_doc_embedding, args=(client, chunk_docs, doc)
# )
# thread.start()
executor = CFG.SYSTEM_APP.get_component(
ComponentType.EXECUTOR_DEFAULT, ExecutorFactory
).create()
@ -277,16 +300,21 @@ class KnowledgeService:
return True
"""update knowledge space"""
def update_knowledge_space(
self, space_id: int, space_request: KnowledgeSpaceRequest
):
"""update knowledge space
Args:
- space_id: space id
- space_request: KnowledgeSpaceRequest
"""
knowledge_space_dao.update_knowledge_space(space_id, space_request)
"""delete knowledge space"""
def delete_space(self, space_name: str):
"""delete knowledge space
Args:
- space_name: knowledge space name
"""
query = KnowledgeSpaceEntity(name=space_name)
spaces = knowledge_space_dao.get_knowledge_space(query)
if len(spaces) == 0:
@ -312,6 +340,11 @@ class KnowledgeService:
return knowledge_space_dao.delete_knowledge_space(space)
def delete_document(self, space_name: str, doc_name: str):
"""delete document
Args:
- space_name: knowledge space name
- doc_name: doocument name
"""
document_query = KnowledgeDocumentEntity(doc_name=doc_name, space=space_name)
documents = knowledge_document_dao.get_documents(document_query)
if len(documents) != 1:
@ -332,9 +365,11 @@ class KnowledgeService:
# delete document
return knowledge_document_dao.delete(document_query)
"""get document chunks"""
def get_document_chunks(self, request: ChunkQueryRequest):
"""get document chunks
Args:
- request: ChunkQueryRequest
"""
query = DocumentChunkEntity(
id=request.id,
document_id=request.document_id,
@ -350,6 +385,12 @@ class KnowledgeService:
return res
def async_doc_embedding(self, client, chunk_docs, doc):
"""async document embedding into vector db
Args:
- client: EmbeddingEngine Client
- chunk_docs: List[Document]
- doc: doc
"""
logger.info(
f"async_doc_embedding, doc:{doc.doc_name}, chunk_size:{len(chunk_docs)}, begin embedding to vector store-{CFG.VECTOR_STORE_TYPE}"
)
@ -391,6 +432,10 @@ class KnowledgeService:
return context_template_string
def get_space_context(self, space_name):
"""get space contect
Args:
- space_name: space name
"""
request = KnowledgeSpaceRequest()
request.name = space_name
spaces = self.get_knowledge_space(request)

View File

@ -1,18 +1,21 @@
from datetime import datetime
from sqlalchemy import Column, Integer, Text, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
from pilot.configs.config import Config
from pilot.server.knowledge.request.request import KnowledgeSpaceRequest
from pilot.connections.rdbms.base_dao import BaseDao
CFG = Config()
Base = declarative_base()
class KnowledgeSpaceEntity(Base):
__tablename__ = "knowledge_space"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
name = Column(String(100))
vector_type = Column(String(100))
@ -29,11 +32,11 @@ class KnowledgeSpaceEntity(Base):
class KnowledgeSpaceDao(BaseDao):
def __init__(self):
super().__init__(
database="knowledge_management", orm_base=Base, create_not_exist_table=True
database="dbgpt", orm_base=Base, db_engine=engine, session=session
)
def create_knowledge_space(self, space: KnowledgeSpaceRequest):
session = self.Session()
session = self.get_session()
knowledge_space = KnowledgeSpaceEntity(
name=space.name,
vector_type=CFG.VECTOR_STORE_TYPE,
@ -47,7 +50,7 @@ class KnowledgeSpaceDao(BaseDao):
session.close()
def get_knowledge_space(self, query: KnowledgeSpaceEntity):
session = self.Session()
session = self.get_session()
knowledge_spaces = session.query(KnowledgeSpaceEntity)
if query.id is not None:
knowledge_spaces = knowledge_spaces.filter(
@ -86,14 +89,14 @@ class KnowledgeSpaceDao(BaseDao):
return result
def update_knowledge_space(self, space: KnowledgeSpaceEntity):
session = self.Session()
session = self.get_session()
session.merge(space)
session.commit()
session.close()
return True
def delete_knowledge_space(self, space: KnowledgeSpaceEntity):
session = self.Session()
session = self.get_session()
if space:
session.delete(space)
session.commit()

View File

@ -16,6 +16,9 @@ CFG = Config()
model_path = LLM_MODEL_CONFIG.get(CFG.LLM_MODEL)
if __name__ == "__main__":
"""run llm server including controller, manager worker
If you use gunicorn as a process manager, initialize_app can be invoke in `on_starting` hook.
"""
run_worker_manager(
model_name=CFG.LLM_MODEL,
model_path=model_path,

View File

@ -1,19 +1,22 @@
from datetime import datetime
from sqlalchemy import Column, Integer, Text, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from pilot.base_modules.meta_data.base_dao import BaseDao
from pilot.base_modules.meta_data.meta_data import Base, engine, session
from pilot.configs.config import Config
from pilot.connections.rdbms.base_dao import BaseDao
from pilot.server.prompt.request.request import PromptManageRequest
CFG = Config()
Base = declarative_base()
class PromptManageEntity(Base):
__tablename__ = "prompt_manage"
__table_args__ = {
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
chat_scene = Column(String(100))
sub_chat_scene = Column(String(100))
@ -31,11 +34,11 @@ class PromptManageEntity(Base):
class PromptManageDao(BaseDao):
def __init__(self):
super().__init__(
database="prompt_management", orm_base=Base, create_not_exist_table=True
database="dbgpt", orm_base=Base, db_engine=engine, session=session
)
def create_prompt(self, prompt: PromptManageRequest):
session = self.Session()
session = self.get_session()
prompt_manage = PromptManageEntity(
chat_scene=prompt.chat_scene,
sub_chat_scene=prompt.sub_chat_scene,
@ -51,7 +54,7 @@ class PromptManageDao(BaseDao):
session.close()
def get_prompts(self, query: PromptManageEntity):
session = self.Session()
session = self.get_session()
prompts = session.query(PromptManageEntity)
if query.chat_scene is not None:
prompts = prompts.filter(PromptManageEntity.chat_scene == query.chat_scene)
@ -78,13 +81,13 @@ class PromptManageDao(BaseDao):
return result
def update_prompt(self, prompt: PromptManageEntity):
session = self.Session()
session = self.get_session()
session.merge(prompt)
session.commit()
session.close()
def delete_prompt(self, prompt: PromptManageEntity):
session = self.Session()
session = self.get_session()
if prompt:
session.delete(prompt)
session.commit()

View File

@ -1,6 +1,7 @@
import os
import json
import time
import datetime
import threading
import queue
import logging
@ -27,6 +28,13 @@ class FileSpanStorage(SpanStorage):
def __init__(self, filename: str, batch_size=10, flush_interval=10):
super().__init__()
self.filename = filename
# Split filename into prefix and suffix
self.filename_prefix, self.filename_suffix = os.path.splitext(filename)
if not self.filename_suffix:
self.filename_suffix = ".log"
self.last_date = (
datetime.datetime.now().date()
) # Store the current date for checking date changes
self.queue = queue.Queue()
self.batch_size = batch_size
self.flush_interval = flush_interval
@ -52,7 +60,21 @@ class FileSpanStorage(SpanStorage):
except queue.Full:
pass # If the signal queue is full, it's okay. The flush thread will handle it.
def _get_dated_filename(self, date: datetime.date) -> str:
"""Return the filename based on a specific date."""
date_str = date.strftime("%Y-%m-%d")
return f"{self.filename_prefix}_{date_str}{self.filename_suffix}"
def _roll_over_if_needed(self):
"""Checks if a day has changed since the last write, and if so, renames the current file."""
current_date = datetime.datetime.now().date()
if current_date != self.last_date:
if os.path.exists(self.filename):
os.rename(self.filename, self._get_dated_filename(self.last_date))
self.last_date = current_date
def _write_to_file(self):
self._roll_over_if_needed()
spans_to_write = []
while not self.queue.empty():
spans_to_write.append(self.queue.get())

View File

@ -4,6 +4,8 @@ import asyncio
import json
import tempfile
import time
from unittest.mock import patch
from datetime import datetime, timedelta
from pilot.utils.tracer import SpanStorage, FileSpanStorage, Span, SpanType
@ -122,3 +124,46 @@ def test_non_existent_file(storage: SpanStorage):
assert len(spans_in_file) == 2
assert spans_in_file[0]["trace_id"] == "1"
assert spans_in_file[1]["trace_id"] == "2"
@pytest.mark.parametrize(
"storage", [{"batch_size": 1, "file_does_not_exist": True}], indirect=True
)
def test_log_rollover(storage: SpanStorage):
# mock start date
mock_start_date = datetime(2023, 10, 18, 23, 59)
with patch("datetime.datetime") as mock_datetime:
mock_datetime.now.return_value = mock_start_date
span1 = Span("1", "a", SpanType.BASE, "b", "op1")
storage.append_span(span1)
time.sleep(0.1)
# mock new day
mock_datetime.now.return_value = mock_start_date + timedelta(minutes=1)
span2 = Span("2", "c", SpanType.BASE, "d", "op2")
storage.append_span(span2)
time.sleep(0.1)
# origin filename need exists
assert os.path.exists(storage.filename)
# get roll over filename
dated_filename = os.path.join(
os.path.dirname(storage.filename),
f"{os.path.basename(storage.filename).split('.')[0]}_2023-10-18.jsonl",
)
assert os.path.exists(dated_filename)
# check origin filename just include the second span
spans_in_original_file = read_spans_from_file(storage.filename)
assert len(spans_in_original_file) == 1
assert spans_in_original_file[0]["trace_id"] == "2"
# check the roll over filename just include the first span
spans_in_dated_file = read_spans_from_file(dated_filename)
assert len(spans_in_dated_file) == 1
assert spans_in_dated_file[0]["trace_id"] == "1"

View File

@ -14,7 +14,11 @@ class VectorStoreConnector:
"""
def __init__(self, vector_store_type, ctx: {}) -> None:
"""initialize vector store connector."""
"""initialize vector store connector.
Args:
- vector_store_type: vector store type Milvus, Chroma, Weaviate
- ctx: vector store config params.
"""
self.ctx = ctx
self._register()
@ -30,20 +34,30 @@ class VectorStoreConnector:
"""load document in vector database."""
return self.client.load_document(docs)
def similar_search(self, docs, topk):
"""similar search in vector database."""
return self.client.similar_search(docs, topk)
def similar_search(self, doc: str, topk: int):
"""similar search in vector database.
Args:
- doc: query text
- topk: topk
"""
return self.client.similar_search(doc, topk)
def vector_name_exists(self):
"""is vector store name exist."""
return self.client.vector_name_exists()
def delete_vector_name(self, vector_name):
"""vector store delete"""
"""vector store delete
Args:
- vector_name: vector store name
"""
return self.client.delete_vector_name(vector_name)
def delete_by_ids(self, ids):
"""vector store delete by ids."""
"""vector store delete by ids.
Args:
- ids: vector ids
"""
return self.client.delete_by_ids(ids=ids)
def _match(self, vector_store_type) -> bool: