Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户工作空间操作 #4156

Merged
merged 7 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions libs/chatchat-server/chatchat/config_work_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from chatchat.configs import config_workspace as workspace


def main():
import argparse

parser = argparse.ArgumentParser(description="指令` chatchat-config` 工作空间配置")
# 只能选择true或false
parser.add_argument(
"-v",
"--verbose",
choices=["true", "false"],
help="是否开启详细日志"
)
parser.add_argument(
"-d",
"--data",
help="数据存放路径"
)
parser.add_argument(
"-f",
"--format",
help="日志格式"
)
parser.add_argument(
"--clear",
action="store_true",
help="清除配置"
)
args = parser.parse_args()

if args.verbose:
if args.verbose.lower() == "true":
workspace.set_log_verbose(True)
else:
workspace.set_log_verbose(False)
if args.data:
workspace.set_data_path(args.data)
if args.format:
workspace.set_log_format(args.format)
if args.clear:
workspace.clear()
print(workspace.get_config())


if __name__ == "__main__":
main()
93 changes: 70 additions & 23 deletions libs/chatchat-server/chatchat/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import importlib
import importlib.util
import os
from pathlib import Path
from typing import Dict, Any

import json
import logging

logger = logging.getLogger()
Expand Down Expand Up @@ -38,7 +40,6 @@ def _import_config_mod_load(import_config_mod: str) -> Dict:
)
user_import = False
if user_import:

# Dynamic loading {config}.py file
py_path = os.path.join(user_config_path, import_config_mod + ".py")
spec = importlib.util.spec_from_file_location(
Expand Down Expand Up @@ -69,7 +70,7 @@ def _import_config_mod_load(import_config_mod: str) -> Dict:
)
raise RuntimeError(f"Failed to load user config from {user_config_path}")
# 当前文件路径
py_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), import_config_mod + ".py")
py_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), import_config_mod + ".py")

spec = importlib.util.spec_from_file_location(f"*",
py_path)
Expand All @@ -95,75 +96,108 @@ def _import_config_mod_load(import_config_mod: str) -> Dict:
}


def _import_log_verbose() -> Any:
def _import_ConfigBasic() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
ConfigBasic = load_mod(basic_config_load.get("module"), "ConfigBasic")

return ConfigBasic


def _import_ConfigBasicFactory() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
log_verbose = load_mod(basic_config_load.get("module"), "log_verbose")
ConfigBasicFactory = load_mod(basic_config_load.get("module"), "ConfigBasicFactory")

return log_verbose
return ConfigBasicFactory


def _import_ConfigWorkSpace() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
ConfigWorkSpace = load_mod(basic_config_load.get("module"), "ConfigWorkSpace")

return ConfigWorkSpace


def _import_config_workspace() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")
return config_workspace

def _import_log_verbose() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")
return config_workspace.get_config().log_verbose


def _import_chatchat_root() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
CHATCHAT_ROOT = load_mod(basic_config_load.get("module"), "CHATCHAT_ROOT")
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return CHATCHAT_ROOT
return config_workspace.get_config().CHATCHAT_ROOT


def _import_data_path() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
DATA_PATH = load_mod(basic_config_load.get("module"), "DATA_PATH")

return DATA_PATH
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")
return config_workspace.get_config().DATA_PATH


def _import_img_dir() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
IMG_DIR = load_mod(basic_config_load.get("module"), "IMG_DIR")

return IMG_DIR
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return config_workspace.get_config().IMG_DIR


def _import_nltk_data_path() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
NLTK_DATA_PATH = load_mod(basic_config_load.get("module"), "NLTK_DATA_PATH")
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return NLTK_DATA_PATH
return config_workspace.get_config().NLTK_DATA_PATH


def _import_log_format() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
LOG_FORMAT = load_mod(basic_config_load.get("module"), "LOG_FORMAT")

return LOG_FORMAT
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return config_workspace.get_config().LOG_FORMAT


def _import_log_path() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
LOG_PATH = load_mod(basic_config_load.get("module"), "LOG_PATH")

return LOG_PATH
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return config_workspace.get_config().LOG_PATH


def _import_media_path() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
MEDIA_PATH = load_mod(basic_config_load.get("module"), "MEDIA_PATH")

return MEDIA_PATH
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")

return config_workspace.get_config().MEDIA_PATH


def _import_base_temp_dir() -> Any:
basic_config_load = CONFIG_IMPORTS.get("_basic_config.py")
load_mod = basic_config_load.get("load_mod")
BASE_TEMP_DIR = load_mod(basic_config_load.get("module"), "BASE_TEMP_DIR")

return BASE_TEMP_DIR
config_workspace = load_mod(basic_config_load.get("module"), "config_workspace")
return config_workspace.get_config().BASE_TEMP_DIR


def _import_default_knowledge_base() -> Any:
Expand Down Expand Up @@ -285,6 +319,7 @@ def _import_db_root_path() -> Any:

return DB_ROOT_PATH


def _import_sqlalchemy_database_uri() -> Any:
kb_config_load = CONFIG_IMPORTS.get("_kb_config.py")
load_mod = kb_config_load.get("load_mod")
Expand Down Expand Up @@ -478,7 +513,15 @@ def _import_api_server() -> Any:


def __getattr__(name: str) -> Any:
if name == "log_verbose":
if name == "ConfigBasic":
return _import_ConfigBasic()
elif name == "ConfigBasicFactory":
return _import_ConfigBasicFactory()
elif name == "ConfigWorkSpace":
return _import_ConfigWorkSpace()
elif name == "config_workspace":
return _import_config_workspace()
elif name == "log_verbose":
return _import_log_verbose()
elif name == "CHATCHAT_ROOT":
return _import_chatchat_root()
Expand Down Expand Up @@ -578,6 +621,7 @@ def __getattr__(name: str) -> Any:

__all__ = [
"VERSION",
"config_workspace",
"log_verbose",
"CHATCHAT_ROOT",
"DATA_PATH",
Expand Down Expand Up @@ -626,5 +670,8 @@ def __getattr__(name: str) -> Any:
"WEBUI_SERVER",
"API_SERVER",

"ConfigBasic",
"ConfigBasicFactory",
"ConfigWorkSpace",

]
Loading