From bf75af520ca07a05cfb39d9c40c157dda942e278 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Mon, 23 Oct 2023 15:40:40 +0800 Subject: [PATCH] feat(ChatData): ChatData Strean response 1.ChatData Stream response --- pilot/memory/chat_history/chat_history_db.py | 2 +- pilot/openapi/api_v1/editor/api_editor_v1.py | 5 +++-- pilot/scene/chat_db/auto_execute/prompt.py | 10 ++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pilot/memory/chat_history/chat_history_db.py b/pilot/memory/chat_history/chat_history_db.py index 2f9b2999c..4b9299eef 100644 --- a/pilot/memory/chat_history/chat_history_db.py +++ b/pilot/memory/chat_history/chat_history_db.py @@ -23,7 +23,7 @@ class ChatHistoryEntity(Base): chat_mode = Column(String(255), nullable=False, comment="Conversation scene mode") summary = Column(String(255), nullable=False, comment="Conversation record summary") user_name = Column(String(255), nullable=True, comment="interlocutor") - messages = Column(Text, nullable=True, comment="Conversation details") + messages = Column(Text(length=2**31-1), nullable=True, comment="Conversation details") UniqueConstraint("conv_uid", name="uk_conversation") Index("idx_q_user", "user_name") diff --git a/pilot/openapi/api_v1/editor/api_editor_v1.py b/pilot/openapi/api_v1/editor/api_editor_v1.py index 3fb985e91..e491a01b6 100644 --- a/pilot/openapi/api_v1/editor/api_editor_v1.py +++ b/pilot/openapi/api_v1/editor/api_editor_v1.py @@ -104,10 +104,11 @@ async def get_editor_sql(con_uid: str, round: int): f'history ai json resp:{element["data"]["content"]}' ) api_call = ApiCall() + api_call.update_from_context(element["data"]["content"]) result = {} - result['thoughts'] = element["data"]["content"] + result['thoughts'] = element["data"]["content"].replace("\n", " ").replace("\\n", " ") if api_call.check_last_plugin_call_ready(element["data"]["content"]): - api_call.update_from_context(element["data"]["content"]) + if len(api_call.plugin_status_map) > 0: first_item = next(iter(api_call.plugin_status_map.items()))[1] result['sql'] = first_item.args["sql"] diff --git a/pilot/scene/chat_db/auto_execute/prompt.py b/pilot/scene/chat_db/auto_execute/prompt.py index d9b67af39..b96899160 100644 --- a/pilot/scene/chat_db/auto_execute/prompt.py +++ b/pilot/scene/chat_db/auto_execute/prompt.py @@ -19,10 +19,8 @@ Table structure information: Constraint: 1. You can only use the table provided in the table structure information to generate sql. If you cannot generate sql based on the provided table structure, please say: "The table structure information provided is not enough to generate sql query." It is prohibited to fabricate information at will. 2. Do not query columns that do not exist. Pay attention to which column is in which table. -3. Replace the corresponding sql into the sql field in the returned result -4. Unless the user specifies in the question a specific number of examples he wishes to obtain, always limit the query to a maximum of {top_k} results. -5. Please output the Sql content in the following format to execute the corresponding SQL to display the data:response_tableSQL Query to run -Please make sure to respond as following format: +3. Unless the user specifies in the question a specific number of examples he wishes to obtain, always limit the query to a maximum of {top_k} results. +4. Please ensure that the output result contains: response_tableSQL Query to run,and replace the generated sql into the parameter sql.Please make sure to respond as following format: thoughts summary to say to user.response_tableSQL Query to run Question: {input} @@ -36,8 +34,8 @@ _DEFAULT_TEMPLATE_ZH = """ 约束: 1. 只能使用表结构信息中提供的表来生成 sql,如果无法根据提供的表结构中生成 sql ,请说:“提供的表结构信息不足以生成 sql 查询。” 禁止随意捏造信息。 2. 不要查询不存在的列,注意哪一列位于哪张表中。 -3.将对应的sql替换到返回结果中的sql字段中 -4.除非用户在问题中指定了他希望获得的具体示例数量,否则始终将查询限制为最多 {top_k} 个结果。 +3. 请确保输出结果包含response_table要运行的SQL, 并将对应的sql替换到sql参数中 +4. 除非用户在问题中指定了他希望获得的具体示例数量,否则始终将查询限制为最多 {top_k} 个结果。 请务必按照以下格式回复: 对用户说的想法摘要。response_table要运行的 SQL