From abed17896d78277d11a2bbdeb70ae28be590d894 Mon Sep 17 00:00:00 2001 From: glide-the <2533736852@qq.com> Date: Tue, 11 Jun 2024 21:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=BF=83=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E4=BF=A1=E6=81=AF=20=E5=AD=90=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatchat/config_work_space.py | 8 ++++++-- .../chatchat/configs/_kb_config.py | 18 ++++++++++++++++++ .../chatchat/configs/_server_config.py | 5 +++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libs/chatchat-server/chatchat/config_work_space.py b/libs/chatchat-server/chatchat/config_work_space.py index e113956b..0b7b4b62 100644 --- a/libs/chatchat-server/chatchat/config_work_space.py +++ b/libs/chatchat-server/chatchat/config_work_space.py @@ -1,3 +1,5 @@ +import json + from chatchat.configs import ( config_basic_workspace, config_model_workspace, @@ -136,7 +138,8 @@ def server(**kwargs): @click.option('--pdf-ocr-threshold', type=(float, float), help='pdf ocr threshold') @click.option('--set_kb_info', type=str, help='''每个知识库的初始化介绍,用于在初始化知识库时显示和Agent调用, 没写则没有介绍,不会被Agent调用。 - Example: \'{"samples": "关于本项目issue的解答"}\' + as a JSON string. + Example: "{\"samples\": \"关于本项目issue的解答\"}" ''') @click.option("--set_kb_root_path", help="设置知识库根路径") @click.option("--set_db_root_path", help="设置db根路径") @@ -175,7 +178,8 @@ def kb(**kwargs): if kwargs["pdf_ocr_threshold"]: config_kb_workspace.set_pdf_ocr_threshold(pdf_ocr_threshold=kwargs["pdf_ocr_threshold"]) if kwargs["set_kb_info"]: - config_kb_workspace.set_kb_info(kb_info=ast.literal_eval(kwargs["set_kb_info"])) + kb_info_dict = json.loads(kwargs["set_kb_info"]) + config_kb_workspace.set_kb_info(kb_info=kb_info_dict) if kwargs["set_kb_root_path"]: config_kb_workspace.set_kb_root_path(kb_root_path=kwargs["set_kb_root_path"]) if kwargs["set_db_root_path"]: diff --git a/libs/chatchat-server/chatchat/configs/_kb_config.py b/libs/chatchat-server/chatchat/configs/_kb_config.py index 3990f3e3..2f13d40f 100644 --- a/libs/chatchat-server/chatchat/configs/_kb_config.py +++ b/libs/chatchat-server/chatchat/configs/_kb_config.py @@ -262,57 +262,75 @@ class ConfigKbWorkSpace(core_config.ConfigWorkSpace[ConfigKbFactory, ConfigKb]): def set_default_knowledge_base(self, kb_name: str): self._config_factory.DEFAULT_KNOWLEDGE_BASE = kb_name + self.store_config() def set_default_vs_type(self, vs_type: str): self._config_factory.DEFAULT_VS_TYPE = vs_type + self.store_config() def set_cached_vs_num(self, cached_vs_num: int): self._config_factory.CACHED_VS_NUM = cached_vs_num + self.store_config() def set_cached_memo_vs_num(self, cached_memo_vs_num: int): self._config_factory.CACHED_MEMO_VS_NUM = cached_memo_vs_num + self.store_config() def set_chunk_size(self, chunk_size: int): self._config_factory.CHUNK_SIZE = chunk_size + self.store_config() def set_overlap_size(self, overlap_size: int): self._config_factory.OVERLAP_SIZE = overlap_size + self.store_config() def set_vector_search_top_k(self, vector_search_top_k: int): self._config_factory.VECTOR_SEARCH_TOP_K = vector_search_top_k + self.store_config() def set_score_threshold(self, score_threshold: float): self._config_factory.SCORE_THRESHOLD = score_threshold + self.store_config() def set_default_search_engine(self, default_search_engine: str): self._config_factory.DEFAULT_SEARCH_ENGINE = default_search_engine + self.store_config() def set_search_engine_top_k(self, search_engine_top_k: int): self._config_factory.SEARCH_ENGINE_TOP_K = search_engine_top_k + self.store_config() def set_zh_title_enhance(self, zh_title_enhance: bool): self._config_factory.ZH_TITLE_ENHANCE = zh_title_enhance + self.store_config() def set_pdf_ocr_threshold(self, pdf_ocr_threshold: Tuple[float, float]): self._config_factory.PDF_OCR_THRESHOLD = pdf_ocr_threshold + self.store_config() def set_kb_info(self, kb_info: Dict[str, str]): self._config_factory.KB_INFO = kb_info + self.store_config() def set_kb_root_path(self, kb_root_path: str): self._config_factory.KB_ROOT_PATH = kb_root_path + self.store_config() def set_db_root_path(self, db_root_path: str): self._config_factory.DB_ROOT_PATH = db_root_path + self.store_config() def set_sqlalchemy_database_uri(self, sqlalchemy_database_uri: str): self._config_factory.SQLALCHEMY_DATABASE_URI = sqlalchemy_database_uri + self.store_config() def set_text_splitter_name(self, text_splitter_name: str): self._config_factory.TEXT_SPLITTER_NAME = text_splitter_name + self.store_config() def set_embedding_keyword_file(self, embedding_keyword_file: str): self._config_factory.EMBEDDING_KEYWORD_FILE = embedding_keyword_file + self.store_config() config_kb_workspace: ConfigKbWorkSpace = ConfigKbWorkSpace() diff --git a/libs/chatchat-server/chatchat/configs/_server_config.py b/libs/chatchat-server/chatchat/configs/_server_config.py index d07da988..709e5030 100644 --- a/libs/chatchat-server/chatchat/configs/_server_config.py +++ b/libs/chatchat-server/chatchat/configs/_server_config.py @@ -124,18 +124,23 @@ class ConfigServerWorkSpace(core_config.ConfigWorkSpace[ConfigServerFactory, Con def set_httpx_default_timeout(self, timeout: float): self._config_factory.httpx_default_timeout(timeout) + self.store_config() def set_open_cross_domain(self, open_cross_domain: bool): self._config_factory.open_cross_domain(open_cross_domain) + self.store_config() def set_default_bind_host(self, default_bind_host: str): self._config_factory.default_bind_host(default_bind_host) + self.store_config() def set_webui_server_port(self, webui_server_port: int): self._config_factory.webui_server_port(webui_server_port) + self.store_config() def set_api_server_port(self, api_server_port: int): self._config_factory.api_server_port(api_server_port) + self.store_config() config_server_workspace: ConfigServerWorkSpace = ConfigServerWorkSpace() \ No newline at end of file