mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-17 15:58:25 +00:00
feat(editor): ChatExcel
🔥ChatExcel Mode Complete
This commit is contained in:
parent
0ba7f00ff5
commit
a06e9b29ad
@ -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"]
|
||||
|
@ -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."""
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
# 使用正则表达式匹配中文字符
|
||||
|
Loading…
Reference in New Issue
Block a user