diff --git a/datacenter/next.config.js b/datacenter/next.config.js index ca4a6f7d0..8376cdd5b 100644 --- a/datacenter/next.config.js +++ b/datacenter/next.config.js @@ -2,7 +2,10 @@ const nextConfig = { experimental: { esmExternals: 'loose' - } + }, + images: { + unoptimized: true + }, } module.exports = nextConfig diff --git a/datacenter/package.json b/datacenter/package.json index c17a0586b..038b415ab 100644 --- a/datacenter/package.json +++ b/datacenter/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "export": "next export", + "compile": "next build && next export" }, "dependencies": { "@ant-design/pro-components": "^2.6.2", diff --git a/pilot/connections/rdbms/py_study/study_data.py b/pilot/connections/rdbms/py_study/study_data.py index c19c39f33..c83c52acc 100644 --- a/pilot/connections/rdbms/py_study/study_data.py +++ b/pilot/connections/rdbms/py_study/study_data.py @@ -7,4 +7,4 @@ if __name__ == "__main__": connect = CFG.local_db.get_session("gpt-user") datas = CFG.local_db.run(connect, "SELECT * FROM users; ") - print(datas) \ No newline at end of file + print(datas) diff --git a/pilot/connections/rdbms/py_study/study_duckdb.py b/pilot/connections/rdbms/py_study/study_duckdb.py index 6e41aa480..20e75f38c 100644 --- a/pilot/connections/rdbms/py_study/study_duckdb.py +++ b/pilot/connections/rdbms/py_study/study_duckdb.py @@ -9,6 +9,8 @@ if __name__ == "__main__": if os.path.isfile("../../../message/chat_history.db"): cursor = duckdb.connect("../../../message/chat_history.db").cursor() # cursor.execute("SELECT * FROM chat_history limit 20") - cursor.execute("SELECT * FROM chat_history where conv_uid ='b54ae5fe-1624-11ee-a271-b26789cc3e58'") + cursor.execute( + "SELECT * FROM chat_history where conv_uid ='b54ae5fe-1624-11ee-a271-b26789cc3e58'" + ) data = cursor.fetchall() print(data) diff --git a/pilot/memory/chat_history/base.py b/pilot/memory/chat_history/base.py index ec4af1a14..0f79fb19e 100644 --- a/pilot/memory/chat_history/base.py +++ b/pilot/memory/chat_history/base.py @@ -26,10 +26,9 @@ class BaseChatHistoryMemory(ABC): """Retrieve the messages from the local file""" @abstractmethod - def create(self, user_name:str) -> None: + def create(self, user_name: str) -> None: """Append the message to the record in the local file""" - @abstractmethod def append(self, message: OnceConversation) -> None: """Append the message to the record in the local file""" diff --git a/pilot/memory/chat_history/duckdb_history.py b/pilot/memory/chat_history/duckdb_history.py index 6ccba5c4f..e3cf01efc 100644 --- a/pilot/memory/chat_history/duckdb_history.py +++ b/pilot/memory/chat_history/duckdb_history.py @@ -36,7 +36,8 @@ class DuckdbHistoryMemory(BaseChatHistoryMemory): if not result: # 如果表不存在,则创建新表 self.connect.execute( - "CREATE TABLE chat_history (conv_uid VARCHAR(100) PRIMARY KEY, chat_mode VARCHAR(50), summary VARCHAR(255), user_name VARCHAR(100), messages TEXT)") + "CREATE TABLE chat_history (conv_uid VARCHAR(100) PRIMARY KEY, chat_mode VARCHAR(50), summary VARCHAR(255), user_name VARCHAR(100), messages TEXT)" + ) def __get_messages_by_conv_uid(self, conv_uid: str): cursor = self.connect.cursor() @@ -59,7 +60,8 @@ class DuckdbHistoryMemory(BaseChatHistoryMemory): cursor = self.connect.cursor() cursor.execute( "INSERT INTO chat_history(conv_uid, chat_mode summary, user_name, messages)VALUES(?,?,?,?,?)", - [self.chat_seesion_id, chat_mode, summary, user_name, ""]) + [self.chat_seesion_id, chat_mode, summary, user_name, ""], + ) cursor.commit() self.connect.commit() except Exception as e: @@ -80,7 +82,14 @@ class DuckdbHistoryMemory(BaseChatHistoryMemory): else: cursor.execute( "INSERT INTO chat_history(conv_uid, chat_mode, summary, user_name, messages)VALUES(?,?,?,?,?)", - [self.chat_seesion_id, once_message.chat_mode, once_message.get_user_conv().content, "",json.dumps(conversations, ensure_ascii=False)]) + [ + self.chat_seesion_id, + once_message.chat_mode, + once_message.get_user_conv().content, + "", + json.dumps(conversations, ensure_ascii=False), + ], + ) cursor.commit() self.connect.commit() diff --git a/pilot/mock_datas/chat_history.db b/pilot/mock_datas/chat_history.db deleted file mode 100644 index 929805035..000000000 Binary files a/pilot/mock_datas/chat_history.db and /dev/null differ diff --git a/pilot/mock_datas/chat_history.db.wal b/pilot/mock_datas/chat_history.db.wal deleted file mode 100644 index e69de29bb..000000000 diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index 1eebe2cea..de1cf0f14 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -2,6 +2,7 @@ import uuid import json import asyncio import time +import os from fastapi import ( APIRouter, Request, @@ -12,11 +13,11 @@ from fastapi import ( BackgroundTasks, ) -from fastapi.responses import JSONResponse -from fastapi.responses import StreamingResponse +from fastapi.responses import JSONResponse, HTMLResponse +from fastapi.responses import StreamingResponse, FileResponse from fastapi.encoders import jsonable_encoder from fastapi.exceptions import RequestValidationError -from fastapi.responses import JSONResponse +from sse_starlette.sse import EventSourceResponse from typing import List from pilot.openapi.api_v1.api_view_model import ( @@ -46,6 +47,7 @@ knowledge_service = KnowledgeService() model_semaphore = None global_counter = 0 +static_file_path = os.path.join(os.getcwd(), "server/static") async def validation_exception_handler(request: Request, exc: RequestValidationError): @@ -95,6 +97,10 @@ def knowledge_list(): return params +@router.get("/") +async def read_main(): + return FileResponse(f"{static_file_path}/test.html") + @router.get("/v1/chat/dialogue/list", response_model=Result[ConversationVo]) async def dialogue_list(response: Response, user_id: str = None): @@ -111,8 +117,6 @@ async def dialogue_list(response: Response, user_id: str = None): summary = item.get("summary") chat_mode = item.get("chat_mode") - - conv_vo: ConversationVo = ConversationVo( conv_uid=conv_uid, user_input=summary, @@ -147,7 +151,6 @@ async def dialogue_scenes(): return Result.succ(scene_vos) - @router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo]) async def dialogue_new( chat_mode: str = ChatScene.ChatNormal.value, user_id: str = None @@ -155,6 +158,7 @@ async def dialogue_new( conv_vo = __new_conversation(chat_mode, user_id) return Result.succ(conv_vo) + @router.post("/v1/chat/mode/params/list", response_model=Result[dict]) async def params_list(chat_mode: str = ChatScene.ChatNormal.value): if ChatScene.ChatWithDbQA.value == chat_mode: @@ -274,15 +278,15 @@ async def stream_generator(chat): msg = chat.prompt_template.output_parser.parse_model_stream_resp_ex( chunk, chat.skip_echo_len ) - chat.current_message.add_ai_message(msg) msg = msg.replace("\n", "\\n") yield f"data:{msg}\n\n" await asyncio.sleep(0.1) else: for chunk in model_response: if chunk: - msg = chat.prompt_template.output_parser.parse_model_stream_resp_ex(chunk, chat.skip_echo_len) - chat.current_message.add_ai_message(msg) + msg = chat.prompt_template.output_parser.parse_model_stream_resp_ex( + chunk, chat.skip_echo_len + ) msg = msg.replace("\n", "\\n") yield f"data:{msg}\n\n" diff --git a/pilot/openapi/knowledge/knowledge_document_dao.py b/pilot/openapi/knowledge/knowledge_document_dao.py index bfd7a8cb7..a4f3ba978 100644 --- a/pilot/openapi/knowledge/knowledge_document_dao.py +++ b/pilot/openapi/knowledge/knowledge_document_dao.py @@ -124,6 +124,7 @@ class KnowledgeDocumentDao: updated_space = session.merge(document) session.commit() return updated_space.id + # # def delete_knowledge_document(self, document_id: int): # cursor = self.conn.cursor() diff --git a/pilot/openapi/knowledge/knowledge_service.py b/pilot/openapi/knowledge/knowledge_service.py index 54dcd5a88..b6308a81a 100644 --- a/pilot/openapi/knowledge/knowledge_service.py +++ b/pilot/openapi/knowledge/knowledge_service.py @@ -114,8 +114,13 @@ class KnowledgeService: space=space_name, ) doc = knowledge_document_dao.get_knowledge_documents(query)[0] - if doc.status == SyncStatus.RUNNING.name or doc.status == SyncStatus.FINISHED.name: - raise Exception(f" doc:{doc.doc_name} status is {doc.status}, can not sync") + if ( + doc.status == SyncStatus.RUNNING.name + or doc.status == SyncStatus.FINISHED.name + ): + raise Exception( + f" doc:{doc.doc_name} status is {doc.status}, can not sync" + ) client = KnowledgeEmbedding( knowledge_source=doc.content, knowledge_type=doc.doc_type.upper(), diff --git a/pilot/scene/base_chat.py b/pilot/scene/base_chat.py index dff8528ac..fc1eaaa39 100644 --- a/pilot/scene/base_chat.py +++ b/pilot/scene/base_chat.py @@ -107,7 +107,9 @@ class BaseChat(ABC): ### Chat sequence advance self.current_message.chat_order = len(self.history_message) + 1 self.current_message.add_user_message(self.current_user_input) - self.current_message.start_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + self.current_message.start_date = datetime.datetime.now().strftime( + "%Y-%m-%d %H:%M:%S" + ) self.current_message.tokens = 0 if self.prompt_template.template: diff --git a/pilot/scene/chat_dashboard/chat.py b/pilot/scene/chat_dashboard/chat.py index dd614399c..805f13eaf 100644 --- a/pilot/scene/chat_dashboard/chat.py +++ b/pilot/scene/chat_dashboard/chat.py @@ -65,12 +65,12 @@ class ChatDashboard(BaseChat): try: datas = self.database.run(self.db_connect, chart_item.sql) chart_data: ChartData = ChartData() - chart_data.chart_sql = chart_item['sql'] - chart_data.chart_type = chart_item['showcase'] - chart_data.chart_name = chart_item['title'] - chart_data.chart_desc = chart_item['thoughts'] + chart_data.chart_sql = chart_item["sql"] + chart_data.chart_type = chart_item["showcase"] + chart_data.chart_name = chart_item["title"] + chart_data.chart_desc = chart_item["thoughts"] chart_data.column_name = datas[0] - chart_data.values =datas + chart_data.values = datas except Exception as e: # TODO 修复流程 print(str(e)) diff --git a/pilot/scene/chat_db/auto_execute/example.py b/pilot/scene/chat_db/auto_execute/example.py index b4c248d65..73fea6f51 100644 --- a/pilot/scene/chat_db/auto_execute/example.py +++ b/pilot/scene/chat_db/auto_execute/example.py @@ -1,5 +1,6 @@ from pilot.prompts.example_base import ExampleSelector from pilot.common.schema import ExampleType + ## Two examples are defined by default EXAMPLES = [ { @@ -34,4 +35,6 @@ EXAMPLES = [ }, ] -sql_data_example = ExampleSelector(examples_record=EXAMPLES, use_example=True, type=ExampleType.ONE_SHOT.value) +sql_data_example = ExampleSelector( + examples_record=EXAMPLES, use_example=True, type=ExampleType.ONE_SHOT.value +) diff --git a/pilot/scene/chat_db/auto_execute/out_parser.py b/pilot/scene/chat_db/auto_execute/out_parser.py index eaa45498c..fe490fb8d 100644 --- a/pilot/scene/chat_db/auto_execute/out_parser.py +++ b/pilot/scene/chat_db/auto_execute/out_parser.py @@ -9,6 +9,8 @@ from pilot.configs.model_config import LOGDIR from pilot.configs.config import Config CFG = Config() + + class SqlAction(NamedTuple): sql: str thoughts: Dict @@ -35,7 +37,7 @@ class DbChatOutputParser(BaseOutputParser): df = pd.DataFrame(data[1:], columns=data[0]) if CFG.NEW_SERVER_MODE: html = df.to_html(index=False, escape=False, sparsify=False) - html = ''.join(html.split()) + html = "".join(html.split()) else: table_style = """