mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-20 09:14:44 +00:00
feat(editor): ChatExcel
ChatExcel devlop part 4
This commit is contained in:
parent
7e22d0d1b7
commit
20fc743cd3
@ -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")
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user