From f19551a7cd2a58ac2ac18655a22a62c287d12fe8 Mon Sep 17 00:00:00 2001 From: FangYin Cheng Date: Fri, 1 Sep 2023 10:40:18 +0800 Subject: [PATCH] feat: Optimize code import time --- .env.template | 6 +++ pilot/__init__.py | 14 ++++-- pilot/agent/json_fix_llm.py | 4 +- pilot/commands/command.py | 3 +- pilot/common/markdown_text.py | 3 +- pilot/common/schema.py | 1 - pilot/common/sql_database.py | 4 +- pilot/configs/config.py | 12 ++--- pilot/configs/model_config.py | 25 ++++++----- pilot/connections/base.py | 1 - .../manages/connect_storage_duckdb.py | 1 - pilot/conversation.py | 1 - pilot/log/json_handler.py | 3 -- pilot/logs.py | 8 +++- pilot/memory/chat_history/base.py | 13 +----- pilot/memory/chat_history/duckdb_history.py | 2 - pilot/memory/chat_history/mem_history.py | 12 +---- pilot/model/adapter.py | 7 +-- pilot/model/cache/base.py | 3 -- pilot/model/cli.py | 45 ++++++++++--------- pilot/model/conversation.py | 2 +- pilot/model/inference.py | 2 - pilot/model/llm/llama_cpp/llama_cpp.py | 2 +- pilot/model/llm/llm_utils.py | 8 +--- pilot/model/llm_out/chatglm_llm.py | 2 - pilot/model/llm_out/falcon_llm.py | 1 - pilot/model/loader.py | 16 ++++--- pilot/model/parameter.py | 4 +- pilot/model/worker/default_worker.py | 9 ++-- pilot/model/worker/embedding_worker.py | 4 +- pilot/model/worker/manager.py | 16 +++---- pilot/model/worker/remote_worker.py | 15 ++++--- pilot/openapi/api_view_model.py | 2 +- pilot/openapi/base.py | 22 +-------- pilot/openapi/editor_view_model.py | 2 +- pilot/out_parser/base.py | 3 +- pilot/prompts/base.py | 7 +-- pilot/prompts/example_base.py | 3 +- pilot/prompts/prompt_new.py | 6 +-- pilot/prompts/prompt_registry.py | 1 - pilot/prompts/prompt_template.py | 2 +- pilot/scene/base_chat.py | 44 +++++------------- pilot/scene/base_message.py | 15 +------ pilot/scene/chat_dashboard/chat.py | 2 +- .../data_preparation/report_schma.py | 6 +-- pilot/scene/chat_dashboard/out_parser.py | 6 +-- .../chat_excel/excel_analyze/chat.py | 8 +--- pilot/scene/chat_db/auto_execute/chat.py | 9 ---- .../scene/chat_db/auto_execute/out_parser.py | 5 +-- pilot/scene/chat_db/auto_execute/prompt.py | 2 +- .../chat_db/auto_execute/prompt_baichuan.py | 2 +- pilot/scene/chat_db/data_loader.py | 5 +-- pilot/scene/chat_db/professional_qa/chat.py | 7 --- .../chat_db/professional_qa/out_parser.py | 10 +---- pilot/scene/chat_db/professional_qa/prompt.py | 2 - pilot/scene/chat_execution/chat.py | 7 +-- pilot/scene/chat_execution/out_parser.py | 3 -- pilot/scene/chat_factory.py | 20 ++++----- .../inner_db_summary/out_parser.py | 5 --- .../chat_knowledge/inner_db_summary/prompt.py | 2 - pilot/scene/chat_knowledge/v1/chat.py | 14 ++---- pilot/scene/chat_knowledge/v1/out_parser.py | 5 --- pilot/scene/chat_knowledge/v1/prompt.py | 3 -- .../scene/chat_knowledge/v1/prompt_chatglm.py | 3 -- pilot/scene/chat_normal/chat.py | 8 +--- pilot/scene/chat_normal/out_parser.py | 5 --- pilot/scene/chat_normal/prompt.py | 3 -- pilot/scene/message.py | 11 +---- pilot/server/base.py | 12 +---- pilot/server/chat_adapter.py | 3 +- pilot/server/dbgpt_server.py | 15 ++----- pilot/server/knowledge/api.py | 1 - pilot/server/knowledge/chunk_db.py | 4 +- pilot/server/knowledge/document_db.py | 4 +- pilot/server/knowledge/service.py | 10 ++++- pilot/server/knowledge/space_db.py | 3 +- pilot/server/llmserver.py | 12 ----- pilot/speech/__init__.py | 3 -- pilot/summary/db_summary_client.py | 24 ++++++---- pilot/utils/api_utils.py | 6 ++- pilot/utils/utils.py | 22 +++++++-- pilot/vector_store/chroma_store.py | 3 +- pilot/vector_store/milvus_store.py | 7 ++- 83 files changed, 244 insertions(+), 394 deletions(-) diff --git a/.env.template b/.env.template index 64d3b2f67..77c94ad66 100644 --- a/.env.template +++ b/.env.template @@ -143,3 +143,9 @@ SUMMARY_CONFIG=FAST # CUDA_VISIBLE_DEVICES=0 ## You can configure the maximum memory used by each GPU. # MAX_GPU_MEMORY=16Gib + +#*******************************************************************# +#** LOG **# +#*******************************************************************# +# FATAL, ERROR, WARNING, WARNING, INFO, DEBUG, NOTSET +DBGPT_LOG_LEVEL=INFO \ No newline at end of file diff --git a/pilot/__init__.py b/pilot/__init__.py index d207a5bc3..d72238c1d 100644 --- a/pilot/__init__.py +++ b/pilot/__init__.py @@ -1,4 +1,12 @@ -from pilot.embedding_engine import SourceEmbedding, register -from pilot.embedding_engine import EmbeddingEngine, KnowledgeType +# Old packages +# __all__ = ["SourceEmbedding", "register", "EmbeddingEngine", "KnowledgeType"] -__all__ = ["SourceEmbedding", "register", "EmbeddingEngine", "KnowledgeType"] +__all__ = ["embedding_engine"] + + +def __getattr__(name: str): + import importlib + + if name in ["embedding_engine"]: + return importlib.import_module("." + name, __name__) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/pilot/agent/json_fix_llm.py b/pilot/agent/json_fix_llm.py index 800c2858a..aa7c4cec8 100644 --- a/pilot/agent/json_fix_llm.py +++ b/pilot/agent/json_fix_llm.py @@ -12,7 +12,7 @@ from pilot.json_utils.json_fix_general import ( fix_invalid_escape, ) from pilot.logs import logger -from pilot.speech import say_text + CFG = Config() @@ -87,6 +87,8 @@ def correct_json(json_to_load: str) -> str: def attempt_to_fix_json_by_finding_outermost_brackets(json_string: str): + from pilot.speech.say import say_text + if CFG.speak_mode and CFG.debug_mode: say_text( "I have received an invalid JSON response from the OpenAI API. " diff --git a/pilot/commands/command.py b/pilot/commands/command.py index 8838efff1..add82d292 100644 --- a/pilot/commands/command.py +++ b/pilot/commands/command.py @@ -7,7 +7,6 @@ from typing import Dict from pilot.commands.exception_not_commands import NotCommands from pilot.configs.config import Config from pilot.prompts.generator import PluginPromptGenerator -from pilot.speech import say_text def _resolve_pathlike_command_args(command_args): @@ -37,6 +36,8 @@ def execute_ai_response_json( Returns: """ + from pilot.speech.say import say_text + cfg = Config() command_name, arguments = get_command(ai_response) diff --git a/pilot/common/markdown_text.py b/pilot/common/markdown_text.py index 1244160fd..8c2130cab 100644 --- a/pilot/common/markdown_text.py +++ b/pilot/common/markdown_text.py @@ -1,8 +1,9 @@ import markdown2 -import pandas as pd def datas_to_table_html(data): + import pandas as pd + df = pd.DataFrame(data[1:], columns=data[0]) table_style = """