From a06e9b29ad9d196781a45cfcf56c7c15b7813559 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Fri, 25 Aug 2023 18:02:50 +0800 Subject: [PATCH] feat(editor): ChatExcel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔥ChatExcel Mode Complete --- pilot/scene/base_chat.py | 49 +++++++++---------- pilot/scene/base_message.py | 2 - .../chat_excel/excel_analyze/chat.py | 2 +- .../chat_excel/excel_learning/out_parser.py | 2 +- .../chat_data/chat_excel/excel_reader.py | 4 +- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/pilot/scene/base_chat.py b/pilot/scene/base_chat.py index 0ead2f293..6a845154e 100644 --- a/pilot/scene/base_chat.py +++ b/pilot/scene/base_chat.py @@ -337,8 +337,8 @@ class BaseChat(ABC): for round_conv in self.prompt_template.example_selector.examples(): for round_message in round_conv["messages"]: if not round_message["type"] in [ - SystemMessage.type, - ViewMessage.type, + ModelMessageRoleType.VIEW, + ModelMessageRoleType.SYSTEM, ]: message_type = round_message["type"] message_content = round_message["data"]["content"] @@ -364,8 +364,7 @@ class BaseChat(ABC): if len(self.history_message) > self.chat_retention_rounds: for first_message in self.history_message[0]["messages"]: if not first_message["type"] in [ - ViewMessage.type, - SystemMessage.type, + ModelMessageRoleType.VIEW ]: message_type = first_message["type"] message_content = first_message["data"]["content"] @@ -378,25 +377,25 @@ class BaseChat(ABC): history_messages.append( ModelMessage(role=message_type, content=message_content) ) - - index = self.chat_retention_rounds - 1 - for round_conv in self.history_message[-index:]: - for round_message in round_conv["messages"]: - if not round_message["type"] in [ - SystemMessage.type, - ViewMessage.type, - ]: - message_type = round_message["type"] - message_content = round_message["data"]["content"] - history_text += ( - message_type - + ":" - + message_content - + self.prompt_template.sep - ) - history_messages.append( - ModelMessage(role=message_type, content=message_content) - ) + if self.chat_retention_rounds > 1: + index = self.chat_retention_rounds - 1 + for round_conv in self.history_message[-index:]: + for round_message in round_conv["messages"]: + if not round_message["type"] in [ + ModelMessageRoleType.VIEW, + ModelMessageRoleType.SYSTEM, + ]: + message_type = round_message["type"] + message_content = round_message["data"]["content"] + history_text += ( + message_type + + ":" + + message_content + + self.prompt_template.sep + ) + history_messages.append( + ModelMessage(role=message_type, content=message_content) + ) else: ### user all history @@ -404,8 +403,8 @@ class BaseChat(ABC): for message in conversation["messages"]: ### histroy message not have promot and view info if not message["type"] in [ - SystemMessage.type, - ViewMessage.type, + ModelMessageRoleType.VIEW, + ModelMessageRoleType.SYSTEM, ]: message_type = message["type"] message_content = message["data"]["content"] diff --git a/pilot/scene/base_message.py b/pilot/scene/base_message.py index 75c0aad97..168fb2bb9 100644 --- a/pilot/scene/base_message.py +++ b/pilot/scene/base_message.py @@ -63,7 +63,6 @@ class AIMessage(BaseMessage): class ViewMessage(BaseMessage): """Type of message that is spoken by the AI.""" - example: bool = False @property @@ -74,7 +73,6 @@ class ViewMessage(BaseMessage): class SystemMessage(BaseMessage): """Type of message that is a system message.""" - @property def type(self) -> str: """Type of the message, used for serialization.""" 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 cb8e8137c..ca23d3914 100644 --- a/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py @@ -26,7 +26,7 @@ CFG = Config() class ChatExcel(BaseChat): chat_scene: str = ChatScene.ChatExcel.value() - chat_retention_rounds = 2 + chat_retention_rounds = 1 def __init__(self, chat_session_id, user_input, select_param: str = ""): chat_mode = ChatScene.ChatExcel diff --git a/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py b/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py index dca1fa3ae..5bb9ba2d3 100644 --- a/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py +++ b/pilot/scene/chat_data/chat_excel/excel_learning/out_parser.py @@ -48,7 +48,7 @@ class LearningExcelOutputParser(BaseOutputParser): column_index +=1 keys = item.keys() for key in keys: - html_colunms = html_colunms + f"- **[{key}]** _{item[key]}_\n" + html_colunms = html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n" html_plans = f"### **分析计划**\n" index = 0 diff --git a/pilot/scene/chat_data/chat_excel/excel_reader.py b/pilot/scene/chat_data/chat_excel/excel_reader.py index 1af45e66b..aaa9bb733 100644 --- a/pilot/scene/chat_data/chat_excel/excel_reader.py +++ b/pilot/scene/chat_data/chat_excel/excel_reader.py @@ -27,9 +27,9 @@ def deep_quotes(token, column_names=[]): if token.ttype == sqlparse.tokens.Name: if len(column_names) >0: if token.value in column_names: - token.value = f'"{token.value}"' + token.value = f'"{token.value.replace("`", "")}"' else: - token.value = f'"{token.value}"' + token.value = f'"{token.value.replace("`", "")}"' def is_chinese(string): # 使用正则表达式匹配中文字符