Skip to content

Commit cb575ad

Browse files
Merge pull request #73 from DeepInsight-AI/new_pre
V1.2.2
2 parents bc44ae9 + 64e5c19 commit cb575ad

File tree

347 files changed

+20236
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

347 files changed

+20236
-101
lines changed

ai/agents/agent_instance_util.py

Lines changed: 153 additions & 1 deletion
Large diffs are not rendered by default.

ai/agents/prompt/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from .prompt_matplotlib import MYSQL_MATPLOTLIB_TIPS_MESS
2-
from .prompt_echarts import CSV_ECHART_TIPS_MESS, MYSQL_ECHART_TIPS_MESS, POSTGRESQL_ECHART_TIPS_MESS
2+
from .prompt_echarts import CSV_ECHART_TIPS_MESS, MYSQL_ECHART_TIPS_MESS, POSTGRESQL_ECHART_TIPS_MESS, MONGODB_ECHART_TIPS_MESS
33

44
__all__ = [
55
"CSV_ECHART_TIPS_MESS",
66
"MYSQL_ECHART_TIPS_MESS",
77
"MYSQL_MATPLOTLIB_TIPS_MESS",
8-
"POSTGRESQL_ECHART_TIPS_MESS"
8+
"POSTGRESQL_ECHART_TIPS_MESS",
9+
"MONGODB_ECHART_TIPS_MESS"
910
]

ai/agents/prompt/prompt_echarts.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,67 @@
335335
].
336336
337337
'''
338+
339+
MONGODB_ECHART_TIPS_MESS = '''
340+
Here are some examples of generating mongodb and pyecharts Code based on the given question.
341+
Please generate new one based on the data and question human asks you, import the neccessary libraries and make sure the code is correct.
342+
343+
IMPORTANT: You need to follow the coding style, and the type of the x, y axis. But also need to focus on the column name of the uploaded tables(if exists). Generally, PyEcharts does not accept numpy.int or numpy.float, etc. It only supports built-in data type like int, float, and str.
344+
Pay attention to check whether the query statement in the execution code block can correctly query the data.
345+
346+
347+
Q: A `stacked` line chart comparing sales and profit over time would be useful. Could you help plot it?
348+
Note: stacked line chart is more fancy in display, while the former is more neat.
349+
<code>
350+
import pymongo
351+
import pandas as pd
352+
from pyecharts.charts import Bar
353+
from pyecharts import options as opts
354+
import json
355+
356+
357+
connectionString = "mongodb://your_host:your_port/your_dbname"
358+
kwargs = {
359+
'username': 'your_username',
360+
'password': 'your_password',
361+
}
362+
363+
db_connection = pymongo.MongoClient(
364+
connectionString, **kwargs
365+
)
366+
conn = db_connection["your_dbname"]
367+
res = list(conn['your_table'].find())
368+
years = [str(_['year']) for _ in res]
369+
sales = [str(_['sales']) for _ in res]
370+
bar = Bar()
371+
bar.add_xaxis(years)
372+
bar.add_yaxis("Sales", sales)
373+
bar.set_global_opts(
374+
xaxis_opts=opts.AxisOpts(
375+
type_="category",
376+
name="Year",
377+
),
378+
yaxis_opts=opts.AxisOpts(
379+
type_="value",
380+
name="Sales",
381+
),
382+
title_opts=opts.TitleOpts(title="Sales over Years"),
383+
)
384+
385+
ret_json = bar.dump_options()
386+
echart_code = json.loads(ret_json)
387+
388+
out_put = [{"echart_name": "Sales over Years", "echart_code": echart_code}]
389+
print(out_put)
390+
</code>
391+
392+
393+
The output should be formatted as a JSON instance that conforms to the JSON schema below, the JSON is a list of dict,
394+
[
395+
{"echart_name": "Sales over Years", "echart_code": ret_json}
396+
{},
397+
{},
398+
].
399+
400+
401+
'''

ai/backend/aidb/analysis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .analysis_csv import AnalysisCsv
33
from .analysis_pg import AnalysisPostgresql
44
from .analysis_sr import AnalysisStarrocks
5+
from .analysis_mongodb import AnalysisMongoDB

ai/backend/aidb/analysis/analysis_mongodb.py

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from .autopilot_mysql import AutopilotMysql
22
from .autopilot import Autopilot
33
from .autopilot_starrocks_api import AutopilotStarrocks
4+
from .autopilot_mongodb import AutopilotMongoDB
5+

ai/backend/aidb/autopilot/autopilot.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from jinja2 import Template
55
from pathlib import Path
66
import time
7+
import os
78

89
class Autopilot(AIDB):
910
def get_agent_user_proxy(self):
@@ -153,23 +154,25 @@ def generate_report_template(self, data):
153154
data['report_thought'].remove(item)
154155

155156
# 获取当前工作目录的路径
156-
current_directory = Path.cwd()
157+
current_directory = CONFIG.up_file_path
157158

158-
if str(current_directory).endswith('/ai'):
159-
html_template_path = str(current_directory) + '/backend/aidb/autopilot/'
160-
else:
161-
html_template_path = str(current_directory) + '/ai/backend/aidb/autopilot/'
162-
163-
print('html_template_path:', html_template_path)
159+
# 构建路径时使用 os.path.join,并使用 os.path.normpath 进行规范化
160+
html_template_path = os.path.join(os.path.normpath(current_directory.replace(r'\user_upload_files', '')), 'ai', 'backend', 'aidb', 'autopilot')
161+
html_template_path = html_template_path.replace('\\', '/')
164162

165163
if CONFIG.web_language == 'CN':
166-
html_template_path = html_template_path + 'html_template'
164+
html_template_path = os.path.join(html_template_path, 'html_template')
167165
else:
168-
html_template_path = html_template_path + 'html_template_en'
166+
html_template_path = os.path.join(html_template_path, 'html_template_en')
169167

170168
# 读取模板文件
171-
with open(html_template_path + '/report_2.html', 'r') as file:
169+
template_file_path = os.path.join(html_template_path, 'report_2.html')
170+
171+
with open(template_file_path, 'r', encoding='utf-8') as file:
172172
template_str = file.read()
173+
174+
print('html_template_path:', html_template_path)
175+
print('template_str:', template_str)
173176
# print('template_str :', template_str)
174177

175178
# 使用Jinja2渲染模板

0 commit comments

Comments
 (0)