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. According to the user goal: {user_input}give the correct duckdb SQL for data analysis.
Use the table name: {table_name} 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: Display type:
{disply_type} {disply_type}
@ -31,7 +31,7 @@ _DEFAULT_TEMPLATE_ZH = """
请确保不要使用不在数据结构中的列名 请确保不要使用不在数据结构中的列名
SQL中需要使用的表名是: {table_name} SQL中需要使用的表名是: {table_name}
根据用户目标得到的分析SQL请从以下显示类型中选择最合适的一种用来展示结果数据如果无法确定则使用'Text'作为显示 根据用户目标得到的分析SQL请从以下显示类型中选择最合适的一种用来展示结果数据如果无法确定则使用'Text'作为显示, 只需要将类型名称返回到结果中
显示类型如下: 显示类型如下:
{disply_type} {disply_type}

View File

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

View File

@ -68,7 +68,7 @@ app.add_middleware(
app.include_router(api_v1, prefix="/api") 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_editor_route_v1, prefix="/api")
# app.include_router(api_v1) # app.include_router(api_v1)