diff --git a/pilot/common/path_utils.py b/pilot/common/path_utils.py new file mode 100644 index 000000000..698c04e44 --- /dev/null +++ b/pilot/common/path_utils.py @@ -0,0 +1,6 @@ +import os + + +def has_path(filename): + directory = os.path.dirname(filename) + return bool(directory) diff --git a/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py b/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py index 8d1bd0a04..0e7c3f9ac 100644 --- a/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_analyze/chat.py @@ -17,6 +17,10 @@ from pilot.common.markdown_text import ( from pilot.scene.chat_data.chat_excel.excel_analyze.prompt import prompt from pilot.scene.chat_data.chat_excel.excel_reader import ExcelReader from pilot.scene.chat_data.chat_excel.excel_learning.chat import ExcelLearning +from pilot.common.path_utils import has_path +from pilot.configs.model_config import LLM_MODEL_CONFIG, KNOWLEDGE_UPLOAD_ROOT_PATH + + CFG = Config() @@ -25,11 +29,14 @@ class ChatExcel(BaseChat): chat_retention_rounds = 2 def __init__(self, chat_session_id, user_input, select_param: str = ""): chat_mode = ChatScene.ChatExcel - ## TODO TEST - select_param = "/Users/tuyang.yhj/Downloads/example.xlsx" - self.excel_file_path = select_param - self.excel_reader = ExcelReader(select_param) + self.select_param = select_param + if has_path(select_param): + self.excel_reader = ExcelReader(select_param) + else: + self.excel_reader = ExcelReader(os.path.join( + KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode.value(), select_param + )) super().__init__( chat_mode=chat_mode, @@ -38,7 +45,6 @@ class ChatExcel(BaseChat): select_param=select_param, ) - def _generate_command_string(self, command: Dict[str, Any]) -> str: """ Generate a formatted string representation of a command. @@ -82,7 +88,9 @@ class ChatExcel(BaseChat): chat_param = { "chat_session_id": self.chat_session_id, "user_input": "[" + self.excel_reader.excel_file_name + self.excel_reader.extension +"]" + " analysis!", - "select_param": self.excel_file_path + "parent_mode": self.chat_mode, + "select_param": self.select_param, + "excel_reader": self.excel_reader } learn_chat = ExcelLearning(**chat_param) result = learn_chat.nostream_call() 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 5217c2da1..8e5028f79 100644 --- a/pilot/scene/chat_data/chat_excel/excel_learning/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_learning/chat.py @@ -1,5 +1,6 @@ import json import os +from typing import Any from pilot.scene.base_message import ( HumanMessage, @@ -22,18 +23,19 @@ CFG = Config() class ExcelLearning(BaseChat): chat_scene: str = ChatScene.ExcelLearning.value() - def __init__(self, chat_session_id, user_input, select_param:str=None): + def __init__(self, chat_session_id, user_input, parent_mode: Any=None, select_param:str=None, excel_reader:Any=None): chat_mode = ChatScene.ExcelLearning """ """ self.excel_file_path = select_param - self.excel_reader = ExcelReader(select_param) + self.excel_reader = excel_reader super().__init__( chat_mode=chat_mode, chat_session_id=chat_session_id, current_user_input = user_input, select_param=select_param, ) - + if parent_mode: + self.current_message.chat_mode = parent_mode.value() def generate_input_values(self):