This commit is contained in:
yhjun1026 2023-06-13 15:14:50 +08:00
parent 85176111b9
commit 4690ac26ea
10 changed files with 288 additions and 1148 deletions

45
echarts.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,10 @@
import json
import os
import glob
import zipfile
import requests
import datetime
from pathlib import Path
from typing import List
from urllib.parse import urlparse
@ -69,6 +72,31 @@ def create_directory_if_not_exists(directory_path: str) -> bool:
return True
def load_native_plugins(cfg: Config):
print("load_native_plugins")
### TODO 默认拉主分支,后续拉发布版本
branch_name = cfg.plugins_git_branch
native_plugin_repo ="DB-GPT-Plugins"
url = "https://github.com/csunny/{repo}/archive/{branch}.zip"
response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name),
headers={'Authorization': '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'})
if response.status_code == 200:
plugins_path_path = Path(cfg.plugins_dir)
files = glob.glob(os.path.join(plugins_path_path, f'{native_plugin_repo}*'))
for file in files:
os.remove(file)
now = datetime.datetime.now()
time_str = now.strftime('%Y%m%d%H%M%S')
file_name = f"{plugins_path_path}/{native_plugin_repo}-{branch_name}-{time_str}.zip"
print(file_name)
with open(file_name, "wb") as f:
f.write(response.content)
print("文件已保存到本地")
else:
print("获取Release信息失败状态码为", response.status_code)
def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]:
"""Scan the plugins directory for plugins and loads them.
@ -104,7 +132,7 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
if (
"_abc_impl" in a_keys
and a_module.__name__ != "AutoGPTPluginTemplate"
and denylist_allowlist_check(a_module.__name__, cfg)
# and denylist_allowlist_check(a_module.__name__, cfg)
):
loaded_plugins.append(a_module())

View File

@ -91,6 +91,8 @@ class Config(metaclass=Singleton):
self.plugins: List[AutoGPTPluginTemplate] = []
self.plugins_openai = []
self.plugins_git_branch = os.getenv("PLUGINS_GIT_BRANCH", "plugin_dashboard")
plugins_allowlist = os.getenv("ALLOWLISTED_PLUGINS")
if plugins_allowlist:
self.plugins_allowlist = plugins_allowlist.split(",")

View File

@ -0,0 +1,193 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Awesome-pyecharts</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
</head>
<body >
<div id="1620936bc2e84d1784e33f4d8f688466" class="chart-container" style="width:900px; height:500px; "></div>
<script>
var chart_1620936bc2e84d1784e33f4d8f688466 = echarts.init(
document.getElementById('1620936bc2e84d1784e33f4d8f688466'), 'white', {renderer: 'canvas'});
var option_1620936bc2e84d1784e33f4d8f688466 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"aria": {
"enabled": false
},
"color": [
"#5470c6",
"#91cc75",
"#fac858",
"#ee6666",
"#73c0de",
"#3ba272",
"#fc8452",
"#9a60b4",
"#ea7ccc"
],
"series": [
{
"type": "bar",
"name": "\u9500\u552e\u989d",
"legendHoverLink": true,
"data": [
820,
932,
901,
934,
1290,
1330,
1320
],
"realtimeSort": false,
"showBackground": false,
"stackStrategy": "samesign",
"cursor": "pointer",
"barMinHeight": 0,
"barCategoryGap": "20%",
"barGap": "30%",
"large": false,
"largeThreshold": 400,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"clip": true,
"zlevel": 0,
"z": 2,
"label": {
"show": true,
"margin": 8
}
}
],
"legend": [
{
"data": [
"\u9500\u552e\u989d"
],
"selected": {},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14,
"backgroundColor": "transparent",
"borderColor": "#ccc",
"borderWidth": 1,
"borderRadius": 0,
"pageButtonItemGap": 5,
"pageButtonPosition": "end",
"pageFormatter": "{current}/{total}",
"pageIconColor": "#2f4554",
"pageIconInactiveColor": "#aaa",
"pageIconSize": 15,
"animationDurationUpdate": 800,
"selector": false,
"selectorPosition": "auto",
"selectorItemGap": 7,
"selectorButtonGap": 10
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"enterable": false,
"confine": false,
"appendToBody": false,
"transitionDuration": 0.4,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5,
"order": "seriesAsc"
},
"xAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"data": [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"
]
}
],
"yAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
}
}
],
"title": [
{
"show": true,
"text": "\u9500\u552e\u989d\u7edf\u8ba1",
"target": "blank",
"subtarget": "blank",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
]
};
chart_1620936bc2e84d1784e33f4d8f688466.setOption(option_1620936bc2e84d1784e33f4d8f688466);
</script>
</body>
</html>

View File

@ -186,6 +186,21 @@ class BaseChat(ABC):
response, self.prompt_template.sep
)
)
# ### MOCK
# ai_response_text = """{
# "thoughts": "可以从users表和tran_order表联合查询按城市和订单数量进行分组统计并使用柱状图展示。",
# "reasoning": "为了分析用户在不同城市的分布情况需要查询users表和tran_order表使用LEFT JOIN将两个表联合起来。按照城市进行分组统计每个城市的订单数量。使用柱状图展示可以直观地看出每个城市的订单数量方便比较。",
# "speak": "根据您的分析目标,我查询了用户表和订单表,统计了每个城市的订单数量,并生成了柱状图展示。",
# "command": {
# "name": "histogram-executor",
# "args": {
# "title": "订单城市分布柱状图",
# "sql": "SELECT users.city, COUNT(tran_order.order_id) AS order_count FROM users LEFT JOIN tran_order ON users.user_name = tran_order.user_name GROUP BY users.city"
# }
# }
# }"""
self.current_message.add_ai_message(ai_response_text)
prompt_define_response = (
self.prompt_template.output_parser.parse_prompt_response(

File diff suppressed because one or more lines are too long

BIN
pilot/server/db-gpt-test.db Normal file

Binary file not shown.

View File

@ -35,7 +35,7 @@ from pilot.conversation import (
chat_mode_title,
default_conversation,
)
from pilot.common.plugins import scan_plugins
from pilot.common.plugins import scan_plugins, load_native_plugins
from pilot.server.gradio_css import code_highlight_css
from pilot.server.gradio_patch import Chatbot as grChatbot
@ -670,6 +670,7 @@ if __name__ == "__main__":
# 配置初始化
cfg = Config()
load_native_plugins(cfg)
dbs = cfg.local_db.get_database_list()
signal.signal(signal.SIGINT, signal_handler)
async_db_summery()

View File

@ -17,7 +17,7 @@ importlib-resources==5.12.0
sqlparse==0.4.4
kiwisolver==1.4.4
matplotlib==3.7.0
matplotlib==3.7.1
multidict==6.0.4
packaging==23.0
psutil==5.9.4