Skip to content

Commit

Permalink
feat(editor): ChatExcel
Browse files Browse the repository at this point in the history
🔥ChatExcel Mode Complete
  • Loading branch information
yhjun1026 committed Aug 25, 2023
1 parent 0ba7f00 commit a06e9b2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
49 changes: 24 additions & 25 deletions pilot/scene/base_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def __load_example_messages(self, str_message: bool = True):
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"]
Expand All @@ -364,8 +364,7 @@ def __load_histroy_messages(self, str_message: bool = True):
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"]
Expand All @@ -378,34 +377,34 @@ def __load_histroy_messages(self, str_message: bool = True):
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
for conversation in self.history_message:
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"]
Expand Down
2 changes: 0 additions & 2 deletions pilot/scene/base_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def type(self) -> str:

class ViewMessage(BaseMessage):
"""Type of message that is spoken by the AI."""

example: bool = False

@property
Expand All @@ -74,7 +73,6 @@ def type(self) -> str:

class SystemMessage(BaseMessage):
"""Type of message that is a system message."""

@property
def type(self) -> str:
"""Type of the message, used for serialization."""
Expand Down
2 changes: 1 addition & 1 deletion pilot/scene/chat_data/chat_excel/excel_analyze/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_view_response(self, speak, data) -> str:
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
Expand Down
4 changes: 2 additions & 2 deletions pilot/scene/chat_data/chat_excel/excel_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
# 使用正则表达式匹配中文字符
Expand Down

0 comments on commit a06e9b2

Please sign in to comment.