merge from master

This commit is contained in:
liunux4odoo 2023-12-29 09:10:01 +08:00
commit 5cccd5e7aa
15 changed files with 73 additions and 69 deletions

View File

@ -59,7 +59,7 @@ docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/ch
该项目是一个可以实现 __完全本地化__推理的知识库增强方案, 重点解决数据安全保护,私域化部署的企业痛点。 该项目是一个可以实现 __完全本地化__推理的知识库增强方案, 重点解决数据安全保护,私域化部署的企业痛点。
本开源方案采用```Apache License```,可以免费商用,无需付费。 本开源方案采用```Apache License```,可以免费商用,无需付费。
我们支持市面上主流的本地大言模型和Embedding模型支持开源的本地向量数据库。 我们支持市面上主流的本地大言模型和Embedding模型支持开源的本地向量数据库。
支持列表详见[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) 支持列表详见[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
@ -92,14 +92,14 @@ $ pip install -r requirements_webui.txt
如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 [HuggingFace](https://huggingface.co/models) 下载。 如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 [HuggingFace](https://huggingface.co/models) 下载。
以本项目中默认使用的 LLM 模型 [THUDM/ChatGLM2-6B](https://huggingface.co/THUDM/chatglm2-6b) 与 Embedding 模型 [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) 为例: 以本项目中默认使用的 LLM 模型 [THUDM/ChatGLM3-6B](https://huggingface.co/THUDM/chatglm3-6b) 与 Embedding 模型 [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) 为例:
下载模型需要先[安装 Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage),然后运行 下载模型需要先[安装 Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage),然后运行
```Shell ```Shell
$ git lfs install $ git lfs install
$ git clone https://huggingface.co/THUDM/chatglm2-6b $ git clone https://huggingface.co/THUDM/chatglm3-6b
$ git clone https://huggingface.co/moka-ai/m3e-base $ git clone https://huggingface.co/BAAI/bge-large-zh
``` ```
### 3. 初始化知识库和配置文件 ### 3. 初始化知识库和配置文件
@ -148,7 +148,7 @@ $ python startup.py -a
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatglm")](https://t.me/+RjliQ3jnJ1YyN2E9) [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatglm")](https://t.me/+RjliQ3jnJ1YyN2E9)
### 项目交流群 ### 项目交流群
<img src="img/qr_code_76.jpg" alt="二维码" width="300" /> <img src="img/qr_code_82.jpg" alt="二维码" width="300" />
🎉 Langchain-Chatchat 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。 🎉 Langchain-Chatchat 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。

View File

@ -105,6 +105,7 @@ ONLINE_LLM_MODEL = {
"version": "qwen-turbo", # 可选包括 "qwen-turbo", "qwen-plus" "version": "qwen-turbo", # 可选包括 "qwen-turbo", "qwen-plus"
"api_key": "", # 请在阿里云控制台模型服务灵积API-KEY管理页面创建 "api_key": "", # 请在阿里云控制台模型服务灵积API-KEY管理页面创建
"provider": "QwenWorker", "provider": "QwenWorker",
"embed_model": "text-embedding-v1" # embedding 模型名称
}, },
# 百川 API申请方式请参考 https://www.baichuan-ai.com/home#api-enter # 百川 API申请方式请参考 https://www.baichuan-ai.com/home#api-enter
@ -241,7 +242,7 @@ MODEL_PATH = {
"agentlm-13b": "THUDM/agentlm-13b", "agentlm-13b": "THUDM/agentlm-13b",
"agentlm-70b": "THUDM/agentlm-70b", "agentlm-70b": "THUDM/agentlm-70b",
"Yi-34B-Chat": "https://huggingface.co/01-ai/Yi-34B-Chat", "Yi-34B-Chat": "01-ai/Yi-34B-Chat",
}, },
"reranker":{ "reranker":{
"bge-reranker-large":"BAAI/bge-reranker-large", "bge-reranker-large":"BAAI/bge-reranker-large",

BIN
img/qr_code_77.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
img/qr_code_78.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
img/qr_code_79.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

BIN
img/qr_code_80.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

BIN
img/qr_code_81.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

BIN
img/qr_code_82.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

@ -1 +1 @@
Subproject commit 4c6f1a9748563b5d3ae81a628ff8a71f3e5686d1 Subproject commit 2f24adb218f23eab00d7fcd7ccf5072f2f35cb3c

View File

@ -1,18 +1,18 @@
# API requirements # API requirements
# On Windows system, install the cuda version manually from https://pytorch.org/ # On Windows system, install the cuda version manually from https://pytorch.org/
torch>=2.1.2 torch~=2.1.2
torchvision>=0.16.2 torchvision~=0.16.2
torchaudio>=2.1.2 torchaudio~=2.1.2
langchain>=0.0.352 langchain==0.0.352
langchain-experimental>=0.0.47 langchain-experimental==0.0.47
pydantic==1.10.13 pydantic==1.10.13
fschat>=0.2.33 fschat==0.2.34
xformers>=0.0.23.post1 xformers==0.0.23.post1
openai>=1.6.0 openai~=1.6.0
sentence_transformers>=2.2.2 sentence_transformers==2.2.2
transformers>=4.36.2 transformers==4.36.2
fastapi>=0.105 fastapi>=0.105
nltk>=3.8.1 nltk>=3.8.1
uvicorn>=0.24.0.post1 uvicorn>=0.24.0.post1
@ -20,11 +20,11 @@ starlette~=0.27.0
unstructured[all-docs]==0.11.0 unstructured[all-docs]==0.11.0
python-magic-bin; sys_platform == 'win32' python-magic-bin; sys_platform == 'win32'
SQLAlchemy==2.0.19 SQLAlchemy==2.0.19
faiss-cpu>=1.7.4 faiss-cpu~=1.7.4
accelerate>=0.24.1 accelerate==0.24.1
spacy>=3.7.2 spacy~=3.7.2
PyMuPDF>=1.23.8 PyMuPDF~=1.23.8
rapidocr_onnxruntime>=1.3.8 rapidocr_onnxruntime~=1.3.8
requests>=2.31.0 requests>=2.31.0
pathlib>=1.0.1 pathlib>=1.0.1
pytest>=7.4.3 pytest>=7.4.3
@ -37,20 +37,20 @@ websockets>=12.0
numpy~=1.26.2 numpy~=1.26.2
pandas~=2.1.4 pandas~=2.1.4
einops>=0.7.0 einops>=0.7.0
transformers_stream_generator>=0.0.4 transformers_stream_generator==0.0.4
vllm>=0.2.6; sys_platform == "linux" vllm==0.2.6; sys_platform == "linux"
# optional document loaders # optional document loaders
rapidocr_paddle[gpu]>=1.3.0.post5 rapidocr_paddle[gpu]>=1.3.0.post5
jq>=1.6.0 jq>=1.6.0
html2text html2text
beautifulsoup4>=4.12.2 beautifulsoup4~=4.12.2
pysrt>=1.1.2 pysrt~=1.1.2
# Online api libs dependencies # Online api libs dependencies
zhipuai>=1.0.7 zhipuai>=1.0.7<=2.0.0
dashscope>=1.13.6 dashscope>=1.13.6
volcengine>=1.0.119 volcengine>=1.0.119
pymilvus>=2.3.4 pymilvus>=2.3.4
@ -61,17 +61,15 @@ pymilvus>=2.3.4
arxiv>=2.0.0 arxiv>=2.0.0
youtube-search>=2.1.2 youtube-search>=2.1.2
duckduckgo-search>=4.1.0 duckduckgo-search>=3.9.9
metaphor-python>=0.1.23 metaphor-python>=0.1.23
# WebUI requirements # WebUI requirements
streamlit>=1.29.0 streamlit~=1.29.0
streamlit-option-menu>=0.3.6 streamlit-option-menu>=0.3.6
streamlit-antd-components>=0.2.4 streamlit-chatbox==1.1.11
streamlit-chatbox>=1.1.11
streamlit-modal>=0.1.0 streamlit-modal>=0.1.0
streamlit-aggrid>=0.3.4.post3 streamlit-aggrid>=0.3.4.post3
httpx[brotli,http2,socks]>=0.25.2 httpx[brotli,http2,socks]>=0.25.2
watchdog>=3.0.0 watchdog>=3.0.0

View File

@ -1,17 +1,18 @@
# API requirements # API requirements
torch>=2.1.2 # On Windows system, install the cuda version manually from https://pytorch.org/
torchvision>=0.16.2 torch~=2.1.2
torchaudio>=2.1.2 torchvision~=0.16.2
torchaudio~=2.1.2
langchain>=0.0.352 langchain==0.0.352
langchain-experimental>=0.0.47 langchain-experimental==0.0.47
pydantic==1.10.13 pydantic==1.10.13
fschat>=0.2.34 fschat==0.2.34
xformers>=0.0.23.post1 xformers==0.0.23.post1
openai>=1.6.0 openai~=1.6.0
sentence_transformers>=2.2.2 sentence_transformers==2.2.2
transformers>=4.36.2 transformers==4.36.2
fastapi>=0.105 fastapi>=0.105
nltk>=3.8.1 nltk>=3.8.1
uvicorn>=0.24.0.post1 uvicorn>=0.24.0.post1
@ -19,11 +20,11 @@ starlette~=0.27.0
unstructured[all-docs]==0.11.0 unstructured[all-docs]==0.11.0
python-magic-bin; sys_platform == 'win32' python-magic-bin; sys_platform == 'win32'
SQLAlchemy==2.0.19 SQLAlchemy==2.0.19
faiss-cpu>=1.7.4 faiss-cpu~=1.7.4
accelerate>=0.24.1 accelerate==0.24.1
spacy>=3.7.2 spacy~=3.7.2
PyMuPDF>=1.23.8 PyMuPDF~=1.23.8
rapidocr_onnxruntime>=1.3.8 rapidocr_onnxruntime~=1.3.8
requests>=2.31.0 requests>=2.31.0
pathlib>=1.0.1 pathlib>=1.0.1
pytest>=7.4.3 pytest>=7.4.3
@ -36,16 +37,16 @@ websockets>=12.0
numpy~=1.26.2 numpy~=1.26.2
pandas~=2.1.4 pandas~=2.1.4
einops>=0.7.0 einops>=0.7.0
transformers_stream_generator>=0.0.4 transformers_stream_generator==0.0.4
vllm>=0.2.6; sys_platform == "linux" vllm==0.2.6; sys_platform == "linux"
# optional document loaders # optional document loaders
rapidocr_paddle[gpu]>=1.3.0.post5 rapidocr_paddle[gpu]>=1.3.0.post5
jq>=1.6.0 jq>=1.6.0
html2text html2text
beautifulsoup4>=4.12.2 beautifulsoup4~=4.12.2
pysrt>=1.1.2 pysrt~=1.1.2
# Online api libs dependencies # Online api libs dependencies
@ -60,5 +61,5 @@ pymilvus>=2.3.4
arxiv>=2.0.0 arxiv>=2.0.0
youtube-search>=2.1.2 youtube-search>=2.1.2
duckduckgo-search>=4.1.0 duckduckgo-search>=3.9.9
metaphor-python>=0.1.23 metaphor-python>=0.1.23

View File

@ -1,9 +1,9 @@
# WebUI requirements # WebUI requirements
streamlit>=1.29.0 # do remember to add streamlit to environment variables if you use windows streamlit~=1.29.0
streamlit-option-menu>=0.3.6 streamlit-option-menu>=0.3.6
streamlit-chatbox>=1.1.11 streamlit-chatbox==1.1.11
streamlit-modal>=0.1.0 streamlit-modal>=0.1.0
streamlit-aggrid>=0.3.4.post3 streamlit-aggrid>=0.3.4.post3
httpx[brotli,http2,socks]>=0.25.2
watchdog>=3.0.0 watchdog>=3.0.0

View File

@ -132,7 +132,7 @@ async def file_chat(query: str = Body(..., description="用户输入", examples=
context = "\n".join([doc.page_content for doc in docs]) context = "\n".join([doc.page_content for doc in docs])
if len(docs) == 0: ## 如果没有找到相关文档使用Empty模板 if len(docs) == 0: ## 如果没有找到相关文档使用Empty模板
prompt_template = get_prompt_template("knowledge_base_chat", "Empty") prompt_template = get_prompt_template("knowledge_base_chat", "empty")
else: else:
prompt_template = get_prompt_template("knowledge_base_chat", prompt_name) prompt_template = get_prompt_template("knowledge_base_chat", prompt_name)
input_msg = History(role="user", content=prompt_template).to_msg_template(False) input_msg = History(role="user", content=prompt_template).to_msg_template(False)

View File

@ -6,7 +6,6 @@ from fastapi import Body
from fastapi.concurrency import run_in_threadpool from fastapi.concurrency import run_in_threadpool
from typing import Dict, List from typing import Dict, List
online_embed_models = list_online_embed_models() online_embed_models = list_online_embed_models()
@ -29,9 +28,10 @@ def embed_texts(
if embed_model in list_online_embed_models(): # 使用在线API if embed_model in list_online_embed_models(): # 使用在线API
config = get_model_worker_config(embed_model) config = get_model_worker_config(embed_model)
worker_class = config.get("worker_class") worker_class = config.get("worker_class")
embed_model = config.get("embed_model")
worker = worker_class() worker = worker_class()
if worker_class.can_embedding(): if worker_class.can_embedding():
params = ApiEmbeddingsParams(texts=texts, to_query=to_query) params = ApiEmbeddingsParams(texts=texts, to_query=to_query, embed_model=embed_model)
resp = worker.do_embeddings(params) resp = worker.do_embeddings(params)
return BaseResponse(**resp) return BaseResponse(**resp)
@ -68,7 +68,8 @@ async def aembed_texts(
def embed_texts_endpoint( def embed_texts_endpoint(
texts: List[str] = Body(..., description="要嵌入的文本列表", examples=[["hello", "world"]]), texts: List[str] = Body(..., description="要嵌入的文本列表", examples=[["hello", "world"]]),
embed_model: str = Body(EMBEDDING_MODEL, description=f"使用的嵌入模型除了本地部署的Embedding模型也支持在线API({online_embed_models})提供的嵌入服务。"), embed_model: str = Body(EMBEDDING_MODEL,
description=f"使用的嵌入模型除了本地部署的Embedding模型也支持在线API({online_embed_models})提供的嵌入服务。"),
to_query: bool = Body(False, description="向量是否用于查询。有些模型如Minimax对存储/查询的向量进行了区分优化。"), to_query: bool = Body(False, description="向量是否用于查询。有些模型如Minimax对存储/查询的向量进行了区分优化。"),
) -> BaseResponse: ) -> BaseResponse:
''' '''

View File

@ -113,6 +113,9 @@ class ApiModelWorker(BaseModelWorker):
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
self.context_len = context_len self.context_len = context_len
self.semaphore = asyncio.Semaphore(self.limit_worker_concurrency) self.semaphore = asyncio.Semaphore(self.limit_worker_concurrency)
self.version = None self.version = None