mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-21 09:43:11 +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}
|
rc = {"font.sans-serif": "SimHei", "axes.unicode_minus": False}
|
||||||
sns.set_style(rc={'font.sans-serif': "Microsoft Yahei"})
|
sns.set_style(rc={'font.sans-serif': "Microsoft Yahei"})
|
||||||
sns.set(context="notebook", style="ticks", color_codes=True, rc=rc)
|
sns.set(context="notebook", style="ticks", color_codes=True, rc=rc)
|
||||||
plt.subplots(figsize=(8, 5), dpi=100)
|
fig, ax = plt.subplots(figsize=(8, 5), dpi=100)
|
||||||
sns.lineplot(df, x=columns[0], y=columns[1])
|
sns.lineplot(df, x=columns[0], y=columns[1], ax=ax)
|
||||||
plt.title("")
|
plt.title("")
|
||||||
|
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
|
ax.set_facecolor("lightgray")
|
||||||
plt.savefig(buf, format="png", dpi=100)
|
plt.savefig(buf, format="png", dpi=100)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
data = base64.b64encode(buf.getvalue()).decode("ascii")
|
data = base64.b64encode(buf.getvalue()).decode("ascii")
|
||||||
@ -51,13 +52,18 @@ def response_bar_chart(speak: str, df: DataFrame) -> str:
|
|||||||
raise ValueError("No Data!")
|
raise ValueError("No Data!")
|
||||||
plt.rcParams["font.family"] = ["sans-serif"]
|
plt.rcParams["font.family"] = ["sans-serif"]
|
||||||
rc = {'font.sans-serif': "Microsoft Yahei"}
|
rc = {'font.sans-serif': "Microsoft Yahei"}
|
||||||
sns.set(context="notebook", style="whitegrid", color_codes=True, rc=rc)
|
sns.set(context="notebook", color_codes=True, rc=rc)
|
||||||
plt.subplots(figsize=(8, 5), dpi=100)
|
sns.set_style("dark")
|
||||||
sns.barplot(df, x=df[columns[0]], y=df[columns[1]])
|
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("")
|
plt.title("")
|
||||||
|
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
|
ax.set_facecolor("lightgray")
|
||||||
plt.savefig(buf, format="png", dpi=100)
|
plt.savefig(buf, format="png", dpi=100)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
data = base64.b64encode(buf.getvalue()).decode("ascii")
|
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_style(rc={'font.sans-serif': "Microsoft Yahei"})
|
||||||
sns.set(context="notebook", style="ticks", color_codes=True, rc=rc)
|
sns.set(context="notebook", style="ticks", color_codes=True, rc=rc)
|
||||||
sns.set_palette("Set3") # 设置颜色主题
|
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.axis('equal') # 使饼图为正圆形
|
||||||
plt.title(columns[0])
|
plt.title(columns[0])
|
||||||
|
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
|
ax.set_facecolor("lightgray")
|
||||||
plt.savefig(buf, format="png", dpi=100)
|
plt.savefig(buf, format="png", dpi=100)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
data = base64.b64encode(buf.getvalue()).decode("ascii")
|
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()
|
resp = chat.prepare()
|
||||||
|
|
||||||
### refresh messages
|
### refresh messages
|
||||||
return dialogue_history_messages(conv_uid)
|
return Result.succ(get_hist_messages(conv_uid))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Result.faild(code="E000X", msg=f"File Load Error {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()
|
history_mem.delete()
|
||||||
return Result.succ(None)
|
return Result.succ(None)
|
||||||
|
|
||||||
|
def get_hist_messages(conv_uid:str):
|
||||||
@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}")
|
|
||||||
message_vos: List[MessageVo] = []
|
message_vos: List[MessageVo] = []
|
||||||
|
history_mem = DuckdbHistoryMemory(conv_uid)
|
||||||
history_mem = DuckdbHistoryMemory(con_uid)
|
|
||||||
history_messages: List[OnceConversation] = history_mem.get_messages()
|
history_messages: List[OnceConversation] = history_mem.get_messages()
|
||||||
if history_messages:
|
if history_messages:
|
||||||
for once in 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"]
|
message2Vo(element, once["chat_order"]) for element in once["messages"]
|
||||||
]
|
]
|
||||||
message_vos.extend(once_message_vos)
|
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:
|
def get_chat_instance(dialogue: ConversationVo = Body()) -> BaseChat:
|
||||||
|
@ -81,7 +81,7 @@ class ChatExcel(BaseChat):
|
|||||||
return None
|
return None
|
||||||
chat_param = {
|
chat_param = {
|
||||||
"chat_session_id": self.chat_session_id,
|
"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
|
"select_param": self.excel_file_path
|
||||||
}
|
}
|
||||||
learn_chat = ExcelLearning(**chat_param)
|
learn_chat = ExcelLearning(**chat_param)
|
||||||
|
Loading…
Reference in New Issue
Block a user