feat(editor): ChatExcel

ChatExcel devlop part 4
This commit is contained in:
yhjun1026 2023-08-23 09:54:19 +08:00
parent 20fc743cd3
commit c67e6d1a65
3 changed files with 25 additions and 9 deletions

View File

@ -0,0 +1,6 @@
import os
def has_path(filename):
directory = os.path.dirname(filename)
return bool(directory)

View File

@ -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()

View File

@ -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):