diff --git a/README.md b/README.md index bf3a5ae..c5c2d68 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ 🚩 本项目未涉及微调、训练过程,但可利用微调或训练对本项目效果进行优化。 -🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/imClumsyPanda/langchain-ChatGLM/Langchain-Chatchat) 中 `v5` 版本所使用代码已更新至本项目 `0.2.0` 版本。 +🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/imClumsyPanda/langchain-ChatGLM/Langchain-Chatchat) 中 `v6` 版本所使用代码已更新至本项目 `0.2.2` 版本。 🐳 [Docker 镜像](registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.0) @@ -208,7 +208,8 @@ embedding_model_dict = { "m3e-base": "/Users/xxx/Downloads/m3e-base", } ``` -如果你选择使用OpenAI的Embedding模型,请将模型的```key```写入`embedding_model_dict`中。使用该模型,你需要鞥能够访问OpenAI官的API,或设置代理。 + +如果你选择使用OpenAI的Embedding模型,请将模型的 ``key``写入 `embedding_model_dict`中。使用该模型,你需要鞥能够访问OpenAI官的API,或设置代理。 ### 4. 知识库初始化与迁移 @@ -219,7 +220,7 @@ embedding_model_dict = { ```shell $ python init_database.py ``` -- 如果您是第一次运行本项目,知识库尚未建立,或者配置文件中的知识库类型、嵌入模型发生变化,或者之前的向量库没有开启`normalize_L2`,需要以下命令初始化或重建知识库: +- 如果您是第一次运行本项目,知识库尚未建立,或者配置文件中的知识库类型、嵌入模型发生变化,或者之前的向量库没有开启 `normalize_L2`,需要以下命令初始化或重建知识库: ```shell $ python init_database.py --recreate-vs @@ -308,7 +309,6 @@ $ python server/llm_api_shutdown.py --serve all ![image](https://github.com/chatchat-space/Langchain-Chatchat/assets/22924096/4e056c1c-5c4b-4865-a1af-859cd58a625d) - #### 5.2 启动 API 服务 本地部署情况下,按照 [5.1 节](README.md#5.1-启动-LLM-服务)**启动 LLM 服务后**,再执行 [server/api.py](server/api.py) 脚本启动 **API** 服务; @@ -366,17 +366,13 @@ $ python startup.py -a 并可使用 `Ctrl + C` 直接关闭所有运行服务。如果一次结束不了,可以多按几次。 -可选参数包括 `-a (或--all-webui)`, `--all-api`, `--llm-api`, `-c (或--controller)`, `--openai-api`, +可选参数包括 `-a (或--all-webui)`, `--all-api`, `--llm-api`, `-c (或--controller)`, `--openai-api`, `-m (或--model-worker)`, `--api`, `--webui`,其中: - `--all-webui` 为一键启动 WebUI 所有依赖服务; - - `--all-api` 为一键启动 API 所有依赖服务; - - `--llm-api` 为一键启动 Fastchat 所有依赖的 LLM 服务; - - `--openai-api` 为仅启动 FastChat 的 controller 和 openai-api-server 服务; - - 其他为单独服务启动选项。 若想指定非默认模型,需要用 `--model-name` 选项,示例: @@ -385,7 +381,7 @@ $ python startup.py -a $ python startup.py --all-webui --model-name Qwen-7B-Chat ``` -更多信息可通过`python startup.py -h`查看。 +更多信息可通过 `python startup.py -h`查看。 **注意:** @@ -393,6 +389,8 @@ $ python startup.py --all-webui --model-name Qwen-7B-Chat **2.服务启动时间示设备不同而不同,约 3-10 分钟,如长时间没有启动请前往 `./logs`目录下监控日志,定位问题。** +**3. 在Linux上使用ctrl+C退出可能会由于linux的多进程机制导致multiprocessing遗留孤儿进程,可通过shutdown_all.sh进行退出** + ## 常见问题 参见 [常见问题](docs/FAQ.md)。 diff --git a/configs/__init__.py b/configs/__init__.py index dc9dd40..b42f0b5 100644 --- a/configs/__init__.py +++ b/configs/__init__.py @@ -1,4 +1,4 @@ from .model_config import * from .server_config import * -VERSION = "v0.2.2-preview" +VERSION = "v0.2.3-preview" diff --git a/configs/server_config.py.example b/configs/server_config.py.example index 5f37779..b0f37bf 100644 --- a/configs/server_config.py.example +++ b/configs/server_config.py.example @@ -34,11 +34,11 @@ FSCHAT_MODEL_WORKERS = { "port": 20002, "device": LLM_DEVICE, # todo: 多卡加载需要配置的参数 - "gpus": None, - "numgpus": 1, + "gpus": None, # 使用的GPU,以str的格式指定,如"0,1" + "num_gpus": 1, # 使用GPU的数量 # 以下为非常用参数,可根据需要配置 - # "max_gpu_memory": "20GiB", - # "load_8bit": False, + # "max_gpu_memory": "20GiB", # 每个GPU占用的最大显存 + # "load_8bit": False, # 开启8bit量化 # "cpu_offloading": None, # "gptq_ckpt": None, # "gptq_wbits": 16, diff --git a/requirements.txt b/requirements.txt index 93908dd..a72c760 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,8 @@ python-magic-bin; sys_platform == 'win32' SQLAlchemy==2.0.19 faiss-cpu nltk +accelerate +spacy # uncomment libs if you want to use corresponding vector store # pymilvus==2.1.3 # requires milvus==2.1.3 @@ -22,9 +24,10 @@ nltk numpy~=1.24.4 pandas~=2.0.3 -streamlit>=1.25.0 +streamlit>=1.26.0 streamlit-option-menu>=0.3.6 streamlit-antd-components>=0.1.11 streamlit-chatbox>=1.1.6 streamlit-aggrid>=0.3.4.post3 httpx~=0.24.1 +watchdog \ No newline at end of file diff --git a/requirements_api.txt b/requirements_api.txt index f567f9f..58dbc0c 100644 --- a/requirements_api.txt +++ b/requirements_api.txt @@ -14,6 +14,8 @@ python-magic-bin; sys_platform == 'win32' SQLAlchemy==2.0.19 faiss-cpu nltk +accelerate +spacy # uncomment libs if you want to use corresponding vector store # pymilvus==2.1.3 # requires milvus==2.1.3 diff --git a/requirements_webui.txt b/requirements_webui.txt index a832550..da66c30 100644 --- a/requirements_webui.txt +++ b/requirements_webui.txt @@ -1,9 +1,10 @@ numpy~=1.24.4 pandas~=2.0.3 -streamlit>=1.25.0 +streamlit>=1.26.0 streamlit-option-menu>=0.3.6 streamlit-antd-components>=0.1.11 streamlit-chatbox>=1.1.6 streamlit-aggrid>=0.3.4.post3 httpx~=0.24.1 -nltk \ No newline at end of file +nltk +watchdog \ No newline at end of file diff --git a/server/knowledge_base/utils.py b/server/knowledge_base/utils.py index da53049..34f2083 100644 --- a/server/knowledge_base/utils.py +++ b/server/knowledge_base/utils.py @@ -104,32 +104,35 @@ class KnowledgeFile: else: loader = DocumentLoader(self.filepath) - try: - if self.text_splitter_name is None: + if self.ext in ".csv": + docs = loader.load() + else: + try: + if self.text_splitter_name is None: + text_splitter_module = importlib.import_module('langchain.text_splitter') + TextSplitter = getattr(text_splitter_module, "SpacyTextSplitter") + text_splitter = TextSplitter( + pipeline="zh_core_web_sm", + chunk_size=CHUNK_SIZE, + chunk_overlap=OVERLAP_SIZE, + ) + self.text_splitter_name = "SpacyTextSplitter" + else: + text_splitter_module = importlib.import_module('langchain.text_splitter') + TextSplitter = getattr(text_splitter_module, self.text_splitter_name) + text_splitter = TextSplitter( + chunk_size=CHUNK_SIZE, + chunk_overlap=OVERLAP_SIZE) + except Exception as e: + print(e) text_splitter_module = importlib.import_module('langchain.text_splitter') - TextSplitter = getattr(text_splitter_module, "SpacyTextSplitter") + TextSplitter = getattr(text_splitter_module, "RecursiveCharacterTextSplitter") text_splitter = TextSplitter( - pipeline="zh_core_web_sm", chunk_size=CHUNK_SIZE, chunk_overlap=OVERLAP_SIZE, ) - self.text_splitter_name = "SpacyTextSplitter" - else: - text_splitter_module = importlib.import_module('langchain.text_splitter') - TextSplitter = getattr(text_splitter_module, self.text_splitter_name) - text_splitter = TextSplitter( - chunk_size=CHUNK_SIZE, - chunk_overlap=OVERLAP_SIZE) - except Exception as e: - print(e) - text_splitter_module = importlib.import_module('langchain.text_splitter') - TextSplitter = getattr(text_splitter_module, "RecursiveCharacterTextSplitter") - text_splitter = TextSplitter( - chunk_size=CHUNK_SIZE, - chunk_overlap=OVERLAP_SIZE, - ) - docs = loader.load_and_split(text_splitter) + docs = loader.load_and_split(text_splitter) print(docs[0]) if using_zh_title_enhance: docs = zh_title_enhance(docs) diff --git a/shutdown_all.sh b/shutdown_all.sh index 961260d..8c64806 100644 --- a/shutdown_all.sh +++ b/shutdown_all.sh @@ -1 +1,2 @@ -ps -eo pid,user,cmd|grep -P 'server/api.py|webui.py|fastchat.serve'|grep -v grep|awk '{print $1}'|xargs kill -9 \ No newline at end of file +# mac设备上的grep命令可能不支持grep -P选项,请使用Homebrew安装;或使用ggrep命令 +ps -eo pid,user,cmd|grep -P 'server/api.py|webui.py|fastchat.serve|multiprocessing'|grep -v grep|awk '{print $1}'|xargs kill -9 \ No newline at end of file diff --git a/webui_pages/dialogue/dialogue.py b/webui_pages/dialogue/dialogue.py index a317aba..04ece7d 100644 --- a/webui_pages/dialogue/dialogue.py +++ b/webui_pages/dialogue/dialogue.py @@ -80,8 +80,13 @@ def dialogue_page(api: ApiRequest): # chunk_content = st.checkbox("关联上下文", False, disabled=True) # chunk_size = st.slider("关联长度:", 0, 500, 250, disabled=True) elif dialogue_mode == "搜索引擎问答": + search_engine_list = list(SEARCH_ENGINES.keys()) with st.expander("搜索引擎配置", True): - search_engine = st.selectbox("请选择搜索引擎", SEARCH_ENGINES.keys(), 0) + search_engine = st.selectbox( + label="请选择搜索引擎", + options=search_engine_list, + index=search_engine_list.index("duckduckgo") if "duckduckgo" in search_engine_list else 0, + ) se_top_k = st.number_input("匹配搜索结果条数:", 1, 20, 3) # Display chat messages from history on app rerun @@ -125,11 +130,12 @@ def dialogue_page(api: ApiRequest): ]) text = "" for d in api.search_engine_chat(prompt, search_engine, se_top_k): - if error_msg := check_error_msg(d): # check whether error occured + if error_msg := check_error_msg(d): # check whether error occured st.error(error_msg) - text += d["answer"] - chat_box.update_msg(text, 0) - chat_box.update_msg("\n\n".join(d["docs"]), 1, streaming=False) + else: + text += d["answer"] + chat_box.update_msg(text, 0) + chat_box.update_msg("\n\n".join(d["docs"]), 1, streaming=False) chat_box.update_msg(text, 0, streaming=False) now = datetime.now()