feat(Agent): ChatAgent And AgentHub

1.Upgrade sqlalchemy to version 2.0
This commit is contained in:
yhjun1026 2023-10-17 15:39:15 +08:00
parent 87243ae504
commit c4f8e0ecad
20 changed files with 94 additions and 68 deletions

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -0,0 +1,23 @@
ChatAgent
==================================
ChatAgent can automatically select the right tool to answer and solve user problems through LLM.
![db plugins demonstration](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/d8bfeee9-e982-465e-a2b8-1164b673847e)
### 1.Update Plugins From Git
![db plugins demonstration](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/7678f07e-9eee-40a9-b980-5b3978a0ed52)
### 2.Install Plugin
After successfully setting up the data source, you can start conversing with the database. You can ask it to generate
SQL for you or inquire about relevant information on the database's metadata.
![db plugins demonstration](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/8acf6a42-e511-48ff-aabf-3d9037485c1c)
### 3.Upload My Local Plugin File
### 4.Select installed plug-ins dialog
![db plugins demonstration](https://github.com/eosphoros-ai/DB-GPT/assets/13723926/e04bc1b1-2c58-4b33-af62-97e89098ace7)
### 5.Uninstall My Plugin

View File

@ -1,13 +1,13 @@
# Tool use with plugin
- DB-GPT supports a variety of plug-ins, such as MySQL, MongoDB, ClickHouse and other database tool plug-ins. In addition, some database management platforms can also package their interfaces and package them into plug-ins, and use the model to realize the ability of "single-sentence requirements"
- DB-GPT supports a variety of plug-ins, such as BaiduSearch, SendEmail. In addition, some database management platforms can also package their interfaces and package them into plug-ins, and use the model to realize the ability of "single-sentence requirements"
## DB-GPT-DASHBOARD-PLUGIN
## Baidu-Search-Plugin
[](https://github.com/csunny/DB-GPT-Plugins/blob/main/src/dbgpt_plugins/Readme.md)
[Db-GPT Plugins](https://github.com/eosphoros-ai/DB-GPT-Plugins/blob/main/src/dbgpt_plugins/Readme.md)
- This is a DB-GPT plugin to generate data analysis charts, if you want to use the test sample data, please first pull the code of [DB-GPT-Plugins](https://github.com/csunny/DB-GPT-Plugins), run the command to generate test DuckDB data, and then copy the generated data file to the `/pilot/mock_datas` directory of the DB-GPT project.
- Perform search queries using the Baidu search engine [DB-GPT-Plugins](https://github.com/eosphoros-ai/DB-GPT-Plugins).
```bash
git clone https://github.com/csunny/DB-GPT-Plugins.git
@ -23,35 +23,5 @@ python /DB-GPT/pilot/webserver.py
<img src="../../assets/dashboard.png" width="680px" />
</p>
- More detail see: [DB-DASHBOARD](https://github.com/csunny/DB-GPT-Plugins/blob/main/src/dbgpt_plugins/Readme.md)
## DB-GPT-SQL-Execution-Plugin
- This is an DbGPT plugin to connect Generic Db And Execute SQL.
## DB-GPT-Bytebase-Plugin
- To use a tool or platform plugin, you should first deploy a plugin. Taking the open-source database management platform Bytebase as an example, you can deploy your Bytebase service with one click using Docker and access it at http://127.0.0.1:5678. More details can be found at https://github.com/bytebase/bytebase.
```bash
docker run --init \
--name bytebase \
--platform linux/amd64 \
--restart always \
--publish 5678:8080 \
--health-cmd "curl --fail http://localhost:5678/healthz || exit 1" \
--health-interval 5m \
--health-timeout 60s \
--volume ~/.bytebase/data:/var/opt/bytebase \
bytebase/bytebase:2.2.0 \
--data /var/opt/bytebase \
--port 8080
```
Note: If your machine's CPU architecture is `ARM`, please use `--platform linux/arm64` instead.
- Select the plugin on DB-GPTAll built-in plugins are from our repository: https://github.com/csunny/DB-GPT-Pluginschoose DB-GPT-Bytebase-Plugin.
Supporting functions include creating projects, creating environments, creating database instances, creating databases, database DDL/DML operations, and ticket approval process, etc.
- More detail see: [DB-DASHBOARD](https://github.com/eosphoros-ai/DB-GPT-Plugins/blob/main/src/dbgpt_plugins/Readme.md)

View File

@ -71,6 +71,20 @@ class MyPluginDao(BaseDao[MyPluginEntity]):
session.close()
return result
def get_by_user_and_plugin(self, user: str, plugin: str) -> MyPluginEntity:
session = self.get_session()
my_plugins = session.query(MyPluginEntity)
if user:
my_plugins = my_plugins.filter(
MyPluginEntity.user_code == user
)
my_plugins = my_plugins.filter(
MyPluginEntity.name == plugin
)
result = my_plugins.first()
session.close()
return result
def list(self, query: MyPluginEntity, page=1, page_size=20)->list[MyPluginEntity]:
session = self.get_session()

View File

@ -21,7 +21,7 @@ TEMP_PLUGIN_PATH = ""
class AgentHub:
def __init__(self, plugin_dir) -> None:
self.hub_dao = PluginHubDao()
self.my_lugin_dao = MyPluginDao()
self.my_plugin_dao = MyPluginDao()
os.makedirs(plugin_dir, exist_ok=True)
self.plugin_dir = plugin_dir
self.temp_hub_file_path = os.path.join(plugin_dir, "temp")
@ -43,11 +43,13 @@ class AgentHub:
# add to my plugins and edit hub status
plugin_entity.installed = plugin_entity.installed + 1
my_plugin_entity = self.__build_my_plugin(plugin_entity)
my_plugin_entity = self.my_plugin_dao.get_by_user_and_plugin(user_name, plugin_name)
if my_plugin_entity is None:
my_plugin_entity = self.__build_my_plugin(plugin_entity)
my_plugin_entity.file_name = file_name
if user_name:
# TODO use user
my_plugin_entity.user_code = ""
my_plugin_entity.user_code = user_name
my_plugin_entity.user_name = user_name
my_plugin_entity.tenant = ""
else:
@ -55,11 +57,15 @@ class AgentHub:
with self.hub_dao.get_session() as session:
try:
session.add(my_plugin_entity)
if my_plugin_entity.id is None:
session.add(my_plugin_entity)
else:
session.merge(my_plugin_entity)
session.merge(plugin_entity)
session.commit()
session.close()
except:
except Exception as e:
logger.error("install merge roll back!" + str(e))
session.rollback()
except Exception as e:
logger.error("install pluguin exception!", e)
@ -72,29 +78,39 @@ class AgentHub:
def uninstall_plugin(self, plugin_name, user):
logger.info(f"uninstall_plugin:{plugin_name},{user}")
plugin_entity = self.hub_dao.get_by_name(plugin_name)
plugin_entity.installed = plugin_entity.installed - 1
my_plugin_entity = self.my_plugin_dao.get_by_user_and_plugin(user, plugin_name)
if plugin_entity is not None:
plugin_entity.installed = plugin_entity.installed - 1
with self.hub_dao.get_session() as session:
try:
my_plugin_q = session.query(MyPluginEntity).filter(MyPluginEntity.name == plugin_name)
if user:
my_plugin_q.filter(MyPluginEntity.user_code == user)
my_plugin_q.delete()
session.merge(plugin_entity)
if plugin_entity is not None:
session.merge(plugin_entity)
session.commit()
except:
session.rollback()
# delete package file if not use
plugin_infos = self.hub_dao.get_by_storage_url(plugin_entity.storage_url)
have_installed = False
for plugin_info in plugin_infos:
if plugin_info.installed > 0:
have_installed = True
break
if not have_installed:
plugin_repo_name = plugin_entity.storage_url.replace(".git", "").strip('/').split('/')[-1]
if plugin_entity is not None:
# delete package file if not use
plugin_infos = self.hub_dao.get_by_storage_url(plugin_entity.storage_url)
have_installed = False
for plugin_info in plugin_infos:
if plugin_info.installed > 0:
have_installed = True
break
if not have_installed:
plugin_repo_name = plugin_entity.storage_url.replace(".git", "").strip('/').split('/')[-1]
files = glob.glob(
os.path.join(self.plugin_dir, f"{plugin_repo_name}*")
)
for file in files:
os.remove(file)
else:
files = glob.glob(
os.path.join(self.plugin_dir, f"{plugin_repo_name}*")
os.path.join(self.plugin_dir, f"{my_plugin_entity.file_name}")
)
for file in files:
os.remove(file)
@ -162,8 +178,9 @@ class AgentHub:
user = Default_User
for my_plugin in my_plugins:
my_plugin_entiy = MyPluginEntity()
my_plugin_entiy = self.my_plugin_dao.get_by_user_and_plugin(user, my_plugin._name)
if my_plugin_entiy is None :
my_plugin_entiy = MyPluginEntity()
my_plugin_entiy.name = my_plugin._name
my_plugin_entiy.version = my_plugin._version
my_plugin_entiy.type = "Personal"
@ -171,8 +188,7 @@ class AgentHub:
my_plugin_entiy.user_name = user
my_plugin_entiy.tenant = ""
my_plugin_entiy.file_name = doc_file.filename
self.my_lugin_dao.update(my_plugin_entiy)
self.my_plugin_dao.update(my_plugin_entiy)
def reload_my_plugins(self):
logger.info(f"load_plugins start!")
@ -182,5 +198,5 @@ class AgentHub:
logger.info(f"get_my_plugin:{user}")
if not user:
user = Default_User
return self.my_lugin_dao.get_by_user(user)
return self.my_plugin_dao.get_by_user(user)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
self.__BUILD_MANIFEST=function(s,c,t,a,e,d,f,n,i,u,b,h,k,j,r,o,p,_,g){return{__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":[t,s,c,a,e,f,b,h,"static/chunks/539-dcd22f1f6b99ebee.js","static/chunks/pages/index-5f6b7fd392ff6866.js"],"/_error":["static/chunks/pages/_error-dee72aff9b2e2c12.js"],"/agent":[s,a,e,i,k,"static/chunks/pages/agent-bf06b377cbd5be86.js"],"/chat/[scene]/[id]":["static/chunks/pages/chat/[scene]/[id]-76515749283bf0a9.js"],"/database":[s,c,a,e,i,b,j,k,"static/chunks/643-d2492f894de95084.js","static/chunks/pages/database-671d42822e30d06f.js"],"/datastores":[t,d,n,u,r,o,p,"static/chunks/pages/datastores-934c240249d280f8.js"],"/datastores/documents":[t,_,s,c,d,n,f,u,r,i,o,p,g,"static/chunks/749-fac3e13c5ab7cff1.js","static/chunks/pages/datastores/documents-cabe6fd9ceb2a4bf.js"],"/datastores/documents/chunklist":[t,s,c,d,f,u,g,"static/chunks/pages/datastores/documents/chunklist-9f3e07d54af4b48c.js"],"/models":[_,s,c,a,d,e,n,j,"static/chunks/991-0cfc6e4020e4d683.js","static/chunks/pages/models-23fdae75ae8c0351.js"],"/prompt":[t,s,c,a,d,e,n,f,"static/chunks/45-b98c4238ff6e0cc1.js",h,"static/chunks/61-4b1a896c7810d559.js","static/chunks/367-88244d673d2fa27b.js","static/chunks/pages/prompt-031e47fc3f1ed3cc.js"],sortedPages:["/","/_app","/_error","/agent","/chat/[scene]/[id]","/database","/datastores","/datastores/documents","/datastores/documents/chunklist","/models","/prompt"]}}("static/chunks/347-4d8f7092e4bdfdfb.js","static/chunks/9-8bf443a54ad1b325.js","static/chunks/29107295-90b90cb30c825230.js","static/chunks/566-074186f7bac9291d.js","static/chunks/479-68b22ee2b7a47fb3.js","static/chunks/262-301259b7bd25a2f2.js","static/chunks/647-f9d834aad2c525c1.js","static/chunks/737-8b1fcf8b6e843f49.js","static/chunks/442-197e6cbc1e54109a.js","static/chunks/995-2f502d60cecceeb6.js","static/chunks/411-d9eba2657c72f766.js","static/chunks/615-2e05a69bfa343278.js","static/chunks/813-cce9482e33f2430c.js","static/chunks/928-74244889bd7f2699.js","static/chunks/341-20a63c15c7f45eaf.js","static/chunks/655-1c948938dfd927ff.js","static/chunks/387-03259b62c3d128f7.js","static/chunks/75fc9c18-a784766a129ec5fb.js","static/chunks/963-0ad205f64dc9848d.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();

View File

@ -0,0 +1 @@
self.__SSG_MANIFEST=new Set([]);self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -309,6 +309,7 @@ def core_requires():
"gTTS==2.3.1",
"langchain>=0.0.286",
"SQLAlchemy==2.0.22",
"fastapi==0.98.0",
"pymysql",
"duckdb==0.8.1",
"duckdb-engine",