feat(editor): ChatExcel

🔥ChatExcel Mode Complete
This commit is contained in:
yhjun1026 2023-08-25 18:02:50 +08:00
parent 0ba7f00ff5
commit a06e9b29ad
5 changed files with 28 additions and 31 deletions

View File

@ -337,8 +337,8 @@ class BaseChat(ABC):
for round_conv in self.prompt_template.example_selector.examples(): for round_conv in self.prompt_template.example_selector.examples():
for round_message in round_conv["messages"]: for round_message in round_conv["messages"]:
if not round_message["type"] in [ if not round_message["type"] in [
SystemMessage.type, ModelMessageRoleType.VIEW,
ViewMessage.type, ModelMessageRoleType.SYSTEM,
]: ]:
message_type = round_message["type"] message_type = round_message["type"]
message_content = round_message["data"]["content"] message_content = round_message["data"]["content"]
@ -364,8 +364,7 @@ class BaseChat(ABC):
if len(self.history_message) > self.chat_retention_rounds: if len(self.history_message) > self.chat_retention_rounds:
for first_message in self.history_message[0]["messages"]: for first_message in self.history_message[0]["messages"]:
if not first_message["type"] in [ if not first_message["type"] in [
ViewMessage.type, ModelMessageRoleType.VIEW
SystemMessage.type,
]: ]:
message_type = first_message["type"] message_type = first_message["type"]
message_content = first_message["data"]["content"] message_content = first_message["data"]["content"]
@ -378,13 +377,13 @@ class BaseChat(ABC):
history_messages.append( history_messages.append(
ModelMessage(role=message_type, content=message_content) ModelMessage(role=message_type, content=message_content)
) )
if self.chat_retention_rounds > 1:
index = self.chat_retention_rounds - 1 index = self.chat_retention_rounds - 1
for round_conv in self.history_message[-index:]: for round_conv in self.history_message[-index:]:
for round_message in round_conv["messages"]: for round_message in round_conv["messages"]:
if not round_message["type"] in [ if not round_message["type"] in [
SystemMessage.type, ModelMessageRoleType.VIEW,
ViewMessage.type, ModelMessageRoleType.SYSTEM,
]: ]:
message_type = round_message["type"] message_type = round_message["type"]
message_content = round_message["data"]["content"] message_content = round_message["data"]["content"]
@ -404,8 +403,8 @@ class BaseChat(ABC):
for message in conversation["messages"]: for message in conversation["messages"]:
### histroy message not have promot and view info ### histroy message not have promot and view info
if not message["type"] in [ if not message["type"] in [
SystemMessage.type, ModelMessageRoleType.VIEW,
ViewMessage.type, ModelMessageRoleType.SYSTEM,
]: ]:
message_type = message["type"] message_type = message["type"]
message_content = message["data"]["content"] message_content = message["data"]["content"]

View File

@ -63,7 +63,6 @@ class AIMessage(BaseMessage):
class ViewMessage(BaseMessage): class ViewMessage(BaseMessage):
"""Type of message that is spoken by the AI.""" """Type of message that is spoken by the AI."""
example: bool = False example: bool = False
@property @property
@ -74,7 +73,6 @@ class ViewMessage(BaseMessage):
class SystemMessage(BaseMessage): class SystemMessage(BaseMessage):
"""Type of message that is a system message.""" """Type of message that is a system message."""
@property @property
def type(self) -> str: def type(self) -> str:
"""Type of the message, used for serialization.""" """Type of the message, used for serialization."""

View File

@ -26,7 +26,7 @@ CFG = Config()
class ChatExcel(BaseChat): class ChatExcel(BaseChat):
chat_scene: str = ChatScene.ChatExcel.value() 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 = ""): def __init__(self, chat_session_id, user_input, select_param: str = ""):
chat_mode = ChatScene.ChatExcel chat_mode = ChatScene.ChatExcel

View File

@ -48,7 +48,7 @@ class LearningExcelOutputParser(BaseOutputParser):
column_index +=1 column_index +=1
keys = item.keys() keys = item.keys()
for key in 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" html_plans = f"### **分析计划**\n"
index = 0 index = 0

View File

@ -27,9 +27,9 @@ def deep_quotes(token, column_names=[]):
if token.ttype == sqlparse.tokens.Name: if token.ttype == sqlparse.tokens.Name:
if len(column_names) >0: if len(column_names) >0:
if token.value in column_names: if token.value in column_names:
token.value = f'"{token.value}"' token.value = f'"{token.value.replace("`", "")}"'
else: else:
token.value = f'"{token.value}"' token.value = f'"{token.value.replace("`", "")}"'
def is_chinese(string): def is_chinese(string):
# 使用正则表达式匹配中文字符 # 使用正则表达式匹配中文字符