feat(editor): ChatExcel

🔥ChatExcel Mode Operation Manual
This commit is contained in:
yhjun1026 2023-08-31 19:54:42 +08:00
parent 9dd23a22f3
commit 502c9df3bf
3 changed files with 36 additions and 30 deletions

View File

@ -16,7 +16,7 @@ Please use the data structure information of the above historical dialogue, make
According to the user goal: {user_input}give the correct duckdb SQL for data analysis.
Use the table name: {table_name}
According to the analysis SQL obtained by the user's goal, select the best one from the following display forms, if it cannot be determined, use Text as the display.
According to the analysis SQL obtained by the user's goal, select the best one from the following display forms, if it cannot be determined, use Text as the display,Just need to return the type name into the result.
Display type:
{disply_type}
@ -31,7 +31,7 @@ _DEFAULT_TEMPLATE_ZH = """
请确保不要使用不在数据结构中的列名
SQL中需要使用的表名是: {table_name}
根据用户目标得到的分析SQL请从以下显示类型中选择最合适的一种用来展示结果数据如果无法确定则使用'Text'作为显示
根据用户目标得到的分析SQL请从以下显示类型中选择最合适的一种用来展示结果数据如果无法确定则使用'Text'作为显示, 只需要将类型名称返回到结果中
显示类型如下:
{disply_type}

View File

@ -27,33 +27,39 @@ class LearningExcelOutputParser(BaseOutputParser):
def parse_prompt_response(self, model_out_text):
clean_str = super().parse_prompt_response(model_out_text)
print("clean prompt response:", clean_str)
response = json.loads(clean_str)
for key in sorted(response):
if key.strip() == "DataAnalysis":
desciption = response[key]
if key.strip() == "ColumnAnalysis":
clounms = response[key]
if key.strip() == "AnalysisProgram":
plans = response[key]
return ExcelResponse(desciption=desciption, clounms=clounms, plans=plans)
try:
response = json.loads(clean_str)
for key in sorted(response):
if key.strip() == "DataAnalysis":
desciption = response[key]
if key.strip() == "ColumnAnalysis":
clounms = response[key]
if key.strip() == "AnalysisProgram":
plans = response[key]
return ExcelResponse(desciption=desciption, clounms=clounms, plans=plans)
except Exception as e:
return model_out_text
def parse_view_response(self, speak, data) -> str:
### tool out data to table view
html_title = f"### **数据简介**\n{data.desciption} "
html_colunms = f"### **数据结构**\n"
column_index = 0
for item in data.clounms:
column_index += 1
keys = item.keys()
for key in keys:
html_colunms = (
html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n"
)
if data:
### tool out data to table view
html_title = f"### **数据简介**\n{data.desciption} "
html_colunms = f"### **数据结构**\n"
column_index = 0
for item in data.clounms:
column_index += 1
keys = item.keys()
for key in keys:
html_colunms = (
html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n"
)
html_plans = f"### **分析计划**\n"
index = 0
for item in data.plans:
index += 1
html_plans = html_plans + f"{item} \n"
html = f"""{html_title}\n{html_colunms}\n{html_plans}"""
return html
html_plans = f"### **分析计划**\n"
index = 0
for item in data.plans:
index += 1
html_plans = html_plans + f"{item} \n"
html = f"""{html_title}\n{html_colunms}\n{html_plans}"""
return html
else:
return speak

View File

@ -68,7 +68,7 @@ app.add_middleware(
app.include_router(api_v1, prefix="/api")
app.include_router(knowledge_router, prefix="/api")
# app.include_router(knowledge_router, prefix="/api")
app.include_router(api_editor_route_v1, prefix="/api")
# app.include_router(api_v1)