From e70f05aea1596863658983cca4b0f47d5a65fbe4 Mon Sep 17 00:00:00 2001 From: aries_ckt <916701291@qq.com> Date: Tue, 29 Aug 2023 20:28:16 +0800 Subject: [PATCH] style:fmt --- pilot/openapi/api_v1/api_v1.py | 4 +- pilot/openapi/api_v1/editor/api_editor_v1.py | 4 +- pilot/out_parser/base.py | 12 +++--- pilot/scene/base_chat.py | 38 +++++++++---------- pilot/scene/base_message.py | 2 +- pilot/scene/chat_dashboard/chat.py | 10 ++--- .../chat_excel/excel_learning/chat.py | 12 +++--- .../chat_excel/excel_learning/out_parser.py | 2 +- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index 7b7f0d4dd..5930c464d 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -170,7 +170,7 @@ async def dialogue_scenes(): @router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo]) async def dialogue_new( - chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None + chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None ): conv_vo = __new_conversation(chat_mode, user_id) return Result.succ(conv_vo) @@ -201,7 +201,7 @@ async def params_load(conv_uid: str, chat_mode: str, doc_file: UploadFile = File if not os.path.exists(os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode)): os.makedirs(os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode)) with NamedTemporaryFile( - dir=os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode), delete=False + dir=os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode), delete=False ) as tmp: tmp.write(await doc_file.read()) tmp_path = tmp.name diff --git a/pilot/openapi/api_v1/editor/api_editor_v1.py b/pilot/openapi/api_v1/editor/api_editor_v1.py index 896c91877..e1b313664 100644 --- a/pilot/openapi/api_v1/editor/api_editor_v1.py +++ b/pilot/openapi/api_v1/editor/api_editor_v1.py @@ -39,7 +39,7 @@ logger = build_logger("api_editor_v1", LOGDIR + "api_editor_v1.log") @router.get("/v1/editor/db/tables", response_model=Result[DbTable]) async def get_editor_tables( - db_name: str, page_index: int, page_size: int, search_str: str = "" + db_name: str, page_index: int, page_size: int, search_str: str = "" ): logger.info(f"get_editor_tables:{db_name},{page_index},{page_size},{search_str}") db_conn = CFG.LOCAL_DB_MANAGE.get_connect(db_name) @@ -285,7 +285,7 @@ async def chart_editor_submit(chart_edit_context: ChatChartEditContext = Body()) find_chart = list( filter( lambda x: x["chart_name"] - == chart_edit_context.chart_title, + == chart_edit_context.chart_title, charts, ) )[0] diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 5fe06916b..1ae14b506 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -155,7 +155,7 @@ class BaseOutputParser(ABC): if i < 0: return None count = 1 - for j, c in enumerate(s[i + 1:], start=i + 1): + for j, c in enumerate(s[i + 1 :], start=i + 1): if c == "]": count -= 1 elif c == "[": @@ -163,13 +163,13 @@ class BaseOutputParser(ABC): if count == 0: break assert count == 0 - return s[i: j + 1] + return s[i : j + 1] else: i = s.find("{") if i < 0: return None count = 1 - for j, c in enumerate(s[i + 1:], start=i + 1): + for j, c in enumerate(s[i + 1 :], start=i + 1): if c == "}": count -= 1 elif c == "{": @@ -177,7 +177,7 @@ class BaseOutputParser(ABC): if count == 0: break assert count == 0 - return s[i: j + 1] + return s[i : j + 1] def parse_prompt_response(self, model_out_text) -> T: """ @@ -194,9 +194,9 @@ class BaseOutputParser(ABC): # if "```" in cleaned_output: # cleaned_output, _ = cleaned_output.split("```") if cleaned_output.startswith("```json"): - cleaned_output = cleaned_output[len("```json"):] + cleaned_output = cleaned_output[len("```json") :] if cleaned_output.startswith("```"): - cleaned_output = cleaned_output[len("```"):] + cleaned_output = cleaned_output[len("```") :] if cleaned_output.endswith("```"): cleaned_output = cleaned_output[: -len("```")] cleaned_output = cleaned_output.strip() diff --git a/pilot/scene/base_chat.py b/pilot/scene/base_chat.py index fe515afb5..9bb5ddc9b 100644 --- a/pilot/scene/base_chat.py +++ b/pilot/scene/base_chat.py @@ -60,7 +60,7 @@ class BaseChat(ABC): arbitrary_types_allowed = True def __init__( - self, chat_mode, chat_session_id, current_user_input, select_param: Any = None + self, chat_mode, chat_session_id, current_user_input, select_param: Any = None ): self.chat_session_id = chat_session_id self.chat_mode = chat_mode @@ -305,7 +305,7 @@ class BaseChat(ABC): system_messages = [] for system_conv in system_convs: system_text += ( - system_conv.type + ":" + system_conv.content + self.prompt_template.sep + system_conv.type + ":" + system_conv.content + self.prompt_template.sep ) system_messages.append( ModelMessage(role=system_conv.type, content=system_conv.content) @@ -317,7 +317,7 @@ class BaseChat(ABC): user_messages = [] if user_conv: user_text = ( - user_conv.type + ":" + user_conv.content + self.prompt_template.sep + user_conv.type + ":" + user_conv.content + self.prompt_template.sep ) user_messages.append( ModelMessage(role=user_conv.type, content=user_conv.content) @@ -339,10 +339,10 @@ class BaseChat(ABC): message_type = round_message["type"] message_content = round_message["data"]["content"] example_text += ( - message_type - + ":" - + message_content - + self.prompt_template.sep + message_type + + ":" + + message_content + + self.prompt_template.sep ) example_messages.append( ModelMessage(role=message_type, content=message_content) @@ -363,10 +363,10 @@ class BaseChat(ABC): message_type = first_message["type"] message_content = first_message["data"]["content"] history_text += ( - message_type - + ":" - + message_content - + self.prompt_template.sep + message_type + + ":" + + message_content + + self.prompt_template.sep ) history_messages.append( ModelMessage(role=message_type, content=message_content) @@ -382,10 +382,10 @@ class BaseChat(ABC): message_type = round_message["type"] message_content = round_message["data"]["content"] history_text += ( - message_type - + ":" - + message_content - + self.prompt_template.sep + message_type + + ":" + + message_content + + self.prompt_template.sep ) history_messages.append( ModelMessage( @@ -405,10 +405,10 @@ class BaseChat(ABC): message_type = message["type"] message_content = message["data"]["content"] history_text += ( - message_type - + ":" - + message_content - + self.prompt_template.sep + message_type + + ":" + + message_content + + self.prompt_template.sep ) history_messages.append( ModelMessage(role=message_type, content=message_content) diff --git a/pilot/scene/base_message.py b/pilot/scene/base_message.py index 75c0aad97..ea39cb09c 100644 --- a/pilot/scene/base_message.py +++ b/pilot/scene/base_message.py @@ -167,7 +167,7 @@ def messages_from_dict(messages: List[dict]) -> List[BaseMessage]: def _parse_model_messages( - messages: List[ModelMessage], + messages: List[ModelMessage], ) -> Tuple[str, List[str], List[List[str, str]]]: """ " Parameters: diff --git a/pilot/scene/chat_dashboard/chat.py b/pilot/scene/chat_dashboard/chat.py index faa255887..2769d123a 100644 --- a/pilot/scene/chat_dashboard/chat.py +++ b/pilot/scene/chat_dashboard/chat.py @@ -22,11 +22,11 @@ class ChatDashboard(BaseChat): """Number of results to return from the query""" def __init__( - self, - chat_session_id, - user_input, - select_param: str = "", - report_name: str = "report", + self, + chat_session_id, + user_input, + select_param: str = "", + report_name: str = "report", ): """ """ self.db_name = select_param diff --git a/pilot/scene/chat_data/chat_excel/excel_learning/chat.py b/pilot/scene/chat_data/chat_excel/excel_learning/chat.py index e49b2f47d..adb556209 100644 --- a/pilot/scene/chat_data/chat_excel/excel_learning/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_learning/chat.py @@ -24,12 +24,12 @@ class ExcelLearning(BaseChat): chat_scene: str = ChatScene.ExcelLearning.value() def __init__( - self, - chat_session_id, - user_input, - parent_mode: Any = None, - select_param: str = None, - excel_reader: Any = None, + self, + chat_session_id, + user_input, + parent_mode: Any = None, + select_param: str = None, + excel_reader: Any = None, ): chat_mode = ChatScene.ExcelLearning """ """ 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 3ded0c792..ff63aa362 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 @@ -47,7 +47,7 @@ class LearningExcelOutputParser(BaseOutputParser): keys = item.keys() for key in keys: html_colunms = ( - html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n" + html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n" ) html_plans = f"### **分析计划**\n"