From 8a6e96c369d87bd89f3d94d3d9097b68120ead84 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Tue, 5 Dec 2023 22:56:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 +++++------ crazy_functions/vector_fns/vector_database.py | 2 -- crazy_functions/知识库问答.py | 21 +++++++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index f51befa..fe9579b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,13 +23,11 @@ RUN pip3 install -r requirements.txt # 装载项目文件,安装剩余依赖(必要) +RUN pip3 install torch --index-url https://download.pytorch.org/whl/cpu +RUN pip3 install langchain sentence-transformers unstructured[local-inference] faiss-cpu nltk beautifulsoup4 bitsandbytes tabulate icetk + +COPY .cache /root/.cache COPY . . RUN pip3 install -r requirements.txt - - -# 非必要步骤,用于预热模块(可以删除) -RUN python3 -c 'from check_proxy import warm_up_modules; warm_up_modules()' - - # 启动(必要) -CMD ["python3", "-u", "main.py"] +CMD ["python3", "-u", "tests/test_vector_plugins.py"] diff --git a/crazy_functions/vector_fns/vector_database.py b/crazy_functions/vector_fns/vector_database.py index 2fa2cee..098eb22 100644 --- a/crazy_functions/vector_fns/vector_database.py +++ b/crazy_functions/vector_fns/vector_database.py @@ -301,7 +301,6 @@ class knowledge_archive_interface(): self.threadLock.acquire() # import uuid self.current_id = id - from zh_langchain import construct_vector_store self.qa_handle, self.kai_path = construct_vector_store( vs_id=self.current_id, files=file_manifest, @@ -323,7 +322,6 @@ class knowledge_archive_interface(): self.threadLock.acquire() if not self.current_id == id: self.current_id = id - from zh_langchain import construct_vector_store self.qa_handle, self.kai_path = construct_vector_store( vs_id=self.current_id, files=[], diff --git a/crazy_functions/知识库问答.py b/crazy_functions/知识库问答.py index 8521ca1..3015328 100644 --- a/crazy_functions/知识库问答.py +++ b/crazy_functions/知识库问答.py @@ -1,7 +1,10 @@ from toolbox import CatchException, update_ui, ProxyNetworkActivate, update_ui_lastest_msg from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, get_files_from_everything - +install_msg =""" +pip3 install torch --index-url https://download.pytorch.org/whl/cpu +pip3 install langchain sentence-transformers unstructured[local-inference] faiss-cpu nltk beautifulsoup4 bitsandbytes tabulate icetk +""" @CatchException def 知识库文件注入(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): @@ -29,11 +32,11 @@ def 知识库文件注入(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst # from langchain.embeddings.huggingface import HuggingFaceEmbeddings from crazy_functions.vector_fns.vector_database import knowledge_archive_interface except Exception as e: - chatbot.append(["依赖不足", "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..."]) + chatbot.append(["依赖不足", f"{str(e)}\n\n导入依赖失败。请用以下命令安装" + install_msg]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - from .crazy_utils import try_install_deps - try_install_deps(['zh_langchain==0.2.1', 'pypinyin'], reload_m=['pypinyin', 'zh_langchain']) - yield from update_ui_lastest_msg("安装完成,您可以再次重试。", chatbot, history) + # from .crazy_utils import try_install_deps + # try_install_deps(['zh_langchain==0.2.1', 'pypinyin'], reload_m=['pypinyin', 'zh_langchain']) + # yield from update_ui_lastest_msg("安装完成,您可以再次重试。", chatbot, history) return # < --------------------读取文件--------------- > @@ -81,11 +84,11 @@ def 读取知识库作答(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst # from langchain.embeddings.huggingface import HuggingFaceEmbeddings from crazy_functions.vector_fns.vector_database import knowledge_archive_interface except Exception as e: - chatbot.append(["依赖不足", "导入依赖失败。正在尝试自动安装,请查看终端的输出或耐心等待..."]) + chatbot.append(["依赖不足", f"{str(e)}\n\n导入依赖失败。请用以下命令安装" + install_msg]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - from .crazy_utils import try_install_deps - try_install_deps(['zh_langchain==0.2.1', 'pypinyin'], reload_m=['pypinyin', 'zh_langchain']) - yield from update_ui_lastest_msg("安装完成,您可以再次重试。", chatbot, history) + # from .crazy_utils import try_install_deps + # try_install_deps(['zh_langchain==0.2.1', 'pypinyin'], reload_m=['pypinyin', 'zh_langchain']) + # yield from update_ui_lastest_msg("安装完成,您可以再次重试。", chatbot, history) return # < ------------------- --------------- >