From 20fc743cd3847ab87acd9b497f5714b67a5c64e9 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Tue, 22 Aug 2023 18:45:23 +0800 Subject: [PATCH] feat(editor): ChatExcel ChatExcel devlop part 4 --- pilot/commands/disply_type/show_chart_gen.py | 19 +++++++++++++------ pilot/openapi/api_v1/api_v1.py | 19 ++++++++++--------- .../chat_excel/excel_analyze/chat.py | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pilot/commands/disply_type/show_chart_gen.py b/pilot/commands/disply_type/show_chart_gen.py index fe974be86..dd3ddc963 100644 --- a/pilot/commands/disply_type/show_chart_gen.py +++ b/pilot/commands/disply_type/show_chart_gen.py @@ -29,11 +29,12 @@ def response_line_chart(speak: str, df: DataFrame) -> str: rc = {"font.sans-serif": "SimHei", "axes.unicode_minus": False} sns.set_style(rc={'font.sans-serif': "Microsoft Yahei"}) sns.set(context="notebook", style="ticks", color_codes=True, rc=rc) - plt.subplots(figsize=(8, 5), dpi=100) - sns.lineplot(df, x=columns[0], y=columns[1]) + fig, ax = plt.subplots(figsize=(8, 5), dpi=100) + sns.lineplot(df, x=columns[0], y=columns[1], ax=ax) plt.title("") buf = io.BytesIO() + ax.set_facecolor("lightgray") plt.savefig(buf, format="png", dpi=100) buf.seek(0) data = base64.b64encode(buf.getvalue()).decode("ascii") @@ -51,13 +52,18 @@ def response_bar_chart(speak: str, df: DataFrame) -> str: raise ValueError("No Data!") plt.rcParams["font.family"] = ["sans-serif"] rc = {'font.sans-serif': "Microsoft Yahei"} - sns.set(context="notebook", style="whitegrid", color_codes=True, rc=rc) - plt.subplots(figsize=(8, 5), dpi=100) - sns.barplot(df, x=df[columns[0]], y=df[columns[1]]) + sns.set(context="notebook", color_codes=True, rc=rc) + sns.set_style("dark") + sns.color_palette("hls", 10) + sns.hls_palette(8, l=.5, s=.7) + fig, ax = plt.subplots(figsize=(8, 5), dpi=100) + plt.ticklabel_format(style='plain') + sns.barplot(df, x=df[columns[0]], y=df[columns[1]], ax=ax) plt.title("") buf = io.BytesIO() + ax.set_facecolor("lightgray") plt.savefig(buf, format="png", dpi=100) buf.seek(0) data = base64.b64encode(buf.getvalue()).decode("ascii") @@ -78,11 +84,12 @@ def response_pie_chart(speak: str, df: DataFrame) -> str: sns.set_style(rc={'font.sans-serif': "Microsoft Yahei"}) sns.set(context="notebook", style="ticks", color_codes=True, rc=rc) sns.set_palette("Set3") # 设置颜色主题 - plt.pie(columns[1], labels=columns[0], autopct='%1.1f%%', startangle=90) + fig, ax = plt.pie(columns[1], labels=columns[0], autopct='%1.1f%%', startangle=90) plt.axis('equal') # 使饼图为正圆形 plt.title(columns[0]) buf = io.BytesIO() + ax.set_facecolor("lightgray") plt.savefig(buf, format="png", dpi=100) buf.seek(0) data = base64.b64encode(buf.getvalue()).decode("ascii") diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index f994d4c75..0d19c3838 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -210,8 +210,7 @@ async def params_load(conv_uid: str, chat_mode: str, doc_file: UploadFile = File resp = chat.prepare() ### refresh messages - return dialogue_history_messages(conv_uid) - + return Result.succ(get_hist_messages(conv_uid)) except Exception as e: return Result.faild(code="E000X", msg=f"File Load Error {e}") @@ -222,13 +221,9 @@ async def dialogue_delete(con_uid: str): history_mem.delete() return Result.succ(None) - -@router.get("/v1/chat/dialogue/messages/history", response_model=Result[MessageVo]) -async def dialogue_history_messages(con_uid: str): - print(f"dialogue_history_messages:{con_uid}") +def get_hist_messages(conv_uid:str): message_vos: List[MessageVo] = [] - - history_mem = DuckdbHistoryMemory(con_uid) + history_mem = DuckdbHistoryMemory(conv_uid) history_messages: List[OnceConversation] = history_mem.get_messages() if history_messages: for once in history_messages: @@ -236,7 +231,13 @@ async def dialogue_history_messages(con_uid: str): message2Vo(element, once["chat_order"]) for element in once["messages"] ] message_vos.extend(once_message_vos) - return Result.succ(message_vos) + return message_vos + + +@router.get("/v1/chat/dialogue/messages/history", response_model=Result[MessageVo]) +async def dialogue_history_messages(con_uid: str): + print(f"dialogue_history_messages:{con_uid}") + return Result.succ(get_hist_messages(con_uid)) def get_chat_instance(dialogue: ConversationVo = Body()) -> BaseChat: diff --git a/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py b/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py index 83991f4f2..8d1bd0a04 100644 --- a/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py @@ -81,7 +81,7 @@ class ChatExcel(BaseChat): return None chat_param = { "chat_session_id": self.chat_session_id, - "user_input": "[" + self.excel_reader.excel_file_name +"]" + self.excel_reader.extension + " analysis!", + "user_input": "[" + self.excel_reader.excel_file_name + self.excel_reader.extension +"]" + " analysis!", "select_param": self.excel_file_path } learn_chat = ExcelLearning(**chat_param)