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

release 0.2.6 #1815

Merged
merged 37 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
61c4000
更新上agent提示词代码 (#1626)
zRzRzRzRzRzRzR Sep 29, 2023
77d38db
修改部分错误的文档,加长了历史记录(for 32k Models) (#1629)
zRzRzRzRzRzRzR Sep 29, 2023
332f8be
fix: windows下bind_host设为0.0.0.0时,将fschat_xx_address指向127.0.0.1,避免请求错误…
liunux4odoo Oct 3, 2023
fc6a3b0
Dev (#1652)
zRzRzRzRzRzRzR Oct 4, 2023
4833820
修复代理为空的问题
glide-the Oct 4, 2023
37500b8
指定transformers==4.33.3版本
glide-the Oct 4, 2023
038f2eb
修复代理为空的问题
glide-the Oct 4, 2023
0304279
fix #1656: rename kb_config.py.exmaple to kb_config.py.example
liunux4odoo Oct 5, 2023
387b4cb
fix #1638: baichuan-api未正确配置
liunux4odoo Oct 5, 2023
2c8fc95
Agent大更新合并 (#1666)
zRzRzRzRzRzRzR Oct 7, 2023
7475205
Agent提示词更改,增加图片 (#1667)
zRzRzRzRzRzRzR Oct 7, 2023
111bc45
Wiki完善和Agent完善计划 (#1680)
zRzRzRzRzRzRzR Oct 7, 2023
01577d6
只启动在server_config中配置的在线API模型
liunux4odoo Oct 12, 2023
1ac1739
fix #1737: MakeFastAPIOffline函数内代码编写错误
liunux4odoo Oct 12, 2023
cd74812
add paramter `max_tokens` to 4 chat api with default value 1024 (#1744)
liunux4odoo Oct 12, 2023
94977c7
修复:切换embed_model时,FAISS向量库未正确释放,导致`d == self.d assert (#1766)
liunux4odoo Oct 16, 2023
9ce328f
实现Api和WEBUI的前后端分离 (#1772)
liunux4odoo Oct 17, 2023
69e5da4
北京黑客松更新 (#1785)
zRzRzRzRzRzRzR Oct 18, 2023
b9b4299
- 支持metaphor搜索引擎(无需代理,key申请简单,目前不支持中文)
liunux4odoo Oct 18, 2023
7e28291
Merge pull request #1792 from liunux4odoo/fix
liunux4odoo Oct 18, 2023
d053950
新功能: (#1801)
liunux4odoo Oct 19, 2023
1b3bd44
update model_config.py.example (#1784)
liunux4odoo Oct 19, 2023
0b25d7b
fix: correct model_worker's logger and semaphor
liunux4odoo Oct 20, 2023
83e25f8
remove xformers from requirements*.txt; check llm_model before change…
liunux4odoo Oct 20, 2023
e920cd0
合并分支,支持 (#1808)
zRzRzRzRzRzRzR Oct 20, 2023
1d9d9df
update baichuan-api: 修正messages参数;支持流式;添加测试用例
liunux4odoo Oct 20, 2023
195929b
支持加载p-tuning,详细步骤见docs/chatchat加载ptuing.md
hzg0601 Oct 20, 2023
6e9acfc
Merge branch 'dev' of https://github.com/chatchat-space/Langchain-Cha…
hzg0601 Oct 20, 2023
a81bd82
根据系统指定binding_host
hzg0601 Oct 20, 2023
109bb7f
Merge pull request #1810 from hzg0601/dev
hzg0601 Oct 20, 2023
46225ad
Dev (#1811)
zRzRzRzRzRzRzR Oct 20, 2023
86ee6fe
更新readme (#1813)
zRzRzRzRzRzRzR Oct 20, 2023
dd7223b
merge master to dev
liunux4odoo Oct 20, 2023
ce54414
update readme: remove partners
liunux4odoo Oct 20, 2023
df0ee99
update readme: remove milestone
liunux4odoo Oct 20, 2023
c41d7ad
Dev (#1814)
zRzRzRzRzRzRzR Oct 20, 2023
0e7f0e1
update readme: remove milestone
liunux4odoo Oct 20, 2023
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
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/ch
- [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh)
- [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh)
- [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh)
- [BAAI/bge-base-zh-v1.5](https://huggingface.co/BAAI/bge-base-zh-v1.5)
- [BAAI/bge-large-zh-v1.5](https://huggingface.co/BAAI/bge-large-zh-v1.5)
- [BAAI/bge-base-zh-v1.5](https://huggingface.co/BAAI/bge-base-zh-v1.5)
- [BAAI/bge-large-zh-v1.5](https://huggingface.co/BAAI/bge-large-zh-v1.5)
- [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct)
- [sensenova/piccolo-base-zh](https://huggingface.co/sensenova/piccolo-base-zh)
- [sensenova/piccolo-large-zh](https://huggingface.co/sensenova/piccolo-large-zh)
Expand Down Expand Up @@ -274,28 +278,20 @@ $ git clone https://huggingface.co/moka-ai/m3e-base
在开始执行 Web UI 或命令行交互前,请先检查 [configs/model_config.py](configs/model_config.py) 和 [configs/server_config.py](configs/server_config.py) 中的各项模型参数设计是否符合需求:

- 请确认已下载至本地的 LLM 模型本地存储路径写在 `llm_model_dict` 对应模型的 `local_model_path` 属性中,如:
```
"chatglm2-6b": "/Users/xxx/Downloads/chatglm2-6b",

```python
llm_model_dict={
"chatglm2-6b": {
"local_model_path": "/Users/xxx/Downloads/chatglm2-6b",
"api_base_url": "http://localhost:8888/v1", # "name"修改为 FastChat 服务中的"api_base_url"
"api_key": "EMPTY"
},
}
```

- 请确认已下载至本地的 Embedding 模型本地存储路径写在 `embedding_model_dict` 对应模型位置,如:

```python
embedding_model_dict = {
"m3e-base": "/Users/xxx/Downloads/m3e-base",
}
```
"m3e-base": "/Users/xxx/Downloads/m3e-base",
```

- 请确认本地分词器路径是否已经填写,如:

```python
```
text_splitter_dict = {
"ChineseRecursiveTextSplitter": {
"source": "huggingface", ## 选择tiktoken则使用openai的方法,不填写则默认为字符长度切割方法。
Expand Down Expand Up @@ -358,7 +354,7 @@ $ python startup.py --all-webui --model-name Qwen-7B-Chat

```python
gpus=None,
num_gpus=1,
num_gpus= 1,
max_gpu_memory="20GiB"
```

Expand Down
39 changes: 22 additions & 17 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Following models are tested by developers with Embedding class of [HuggingFace](
- [moka-ai/m3e-large](https://huggingface.co/moka-ai/m3e-large)
- [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh)
- [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh)
- [BAAI/bge-base-zh-v1.5](https://huggingface.co/BAAI/bge-base-zh-v1.5)
- [BAAI/bge-large-zh-v1.5](https://huggingface.co/BAAI/bge-large-zh-v1.5)
- [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh)
- [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct)
- [sensenova/piccolo-base-zh](https://huggingface.co/sensenova/piccolo-base-zh)
Expand Down Expand Up @@ -228,30 +230,33 @@ $ git clone https://huggingface.co/moka-ai/m3e-base
```

### 3. Setting Configuration
Copy the model-related parameter configuration template file [configs/model_config.py.example](configs/model_config.py.example) and store it under the project path `. /configs` path and rename it `model_config.py`.

Copy the model-related parameter configuration template file [configs/model_config.py.example](configs/model_config.py.example) and save it in the `./configs` path under the project path, and rename it to `model_config.py`.
Copy the service-related parameter configuration template file [configs/server_config.py.example](configs/server_config.py.example) and store it under the project path `. /configs` path and rename it `server_config.py`.

Copy the service-related parameter configuration template file [configs/server_config.py.example](configs/server_config.py.example) to save in the `./configs` path under the project path, and rename it to `server_config.py`.
Before you start executing the Web UI or command line interactions, check that each of the items in [configs/model_config.py](configs/model_config.py) and [configs/server_config.py](configs/server_config.py) The model parameters are designed to meet the requirements:

Before starting to execute Web UI or command line interaction, please check whether each model parameter in `configs/model_config.py` and `configs/server_config.py` meets the requirements.
- Please make sure that the local storage path of the downloaded LLM model is written in the `local_model_path` attribute of the corresponding model in `llm_model_dict`, e.g..
```
"chatglm2-6b":"/Users/xxx/Downloads/chatglm2-6b",

```

* Please confirm that the path to local LLM model and embedding model have been written in `llm_dict` of `configs/model_config.py`, here is an example:
* If you choose to use OpenAI's Embedding model, please write the model's ``key`` into `embedding_model_dict`. To use this model, you need to be able to access the OpenAI official API, or set up a proxy.
- Please make sure that the local storage path of the downloaded Embedding model is written in `embedding_model_dict` corresponding to the model location, e.g.:

```python
llm_model_dict={
"chatglm2-6b": {
"local_model_path": "/Users/xxx/Downloads/chatglm2-6b",
"api_base_url": "http://localhost:8888/v1", # "name"修改为 FastChat 服务中的"api_base_url"
"api_key": "EMPTY"
},
}
```
"m3e-base":"/Users/xxx/Downloads/m3e-base", ``` Please make sure that the local storage path of the downloaded Embedding model is written in the location of the corresponding model, e.g.
```

```python
embedding_model_dict = {
"m3e-base": "/Users/xxx/Downloads/m3e-base",
}
- Please make sure that the local participle path is filled in, e.g.:

```
text_splitter_dict = {
"ChineseRecursiveTextSplitter": {
"source": "huggingface", ## Select tiktoken to use openai's method, don't fill it in then it defaults to character length cutting method.
"tokenizer_name_or_path": "", ## Leave blank to use the big model of the tokeniser.
}
}
```

### 4. Knowledge Base Migration
Expand Down
2 changes: 1 addition & 1 deletion configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .prompt_config import *


VERSION = "v0.2.5-preview"
VERSION = "v0.2.6-preview"
21 changes: 16 additions & 5 deletions configs/kb_config.py.exmaple → configs/kb_config.py.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os


# 默认向量库类型。可选:faiss, milvus, pg.
# 默认向量库类型。可选:faiss, milvus(离线) & zilliz(在线), pg.
DEFAULT_VS_TYPE = "faiss"

# 缓存向量库数量(针对FAISS)
Expand Down Expand Up @@ -42,13 +42,17 @@ BING_SUBSCRIPTION_KEY = ""
ZH_TITLE_ENHANCE = False


# 通常情况下不需要更改以下内容
# 每个知识库的初始化介绍,用于在初始化知识库时显示和Agent调用,没写则没有介绍,不会被Agent调用。
KB_INFO = {
"知识库名称": "知识库介绍",
"samples": "关于本项目issue的解答",
}

# 通常情况下不需要更改以下内容
# 知识库默认存储路径
KB_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "knowledge_base")
if not os.path.exists(KB_ROOT_PATH):
os.mkdir(KB_ROOT_PATH)

# 数据库默认存储路径。
# 如果使用sqlite,可以直接修改DB_ROOT_PATH;如果使用其它数据库,请直接修改SQLALCHEMY_DATABASE_URI。
DB_ROOT_PATH = os.path.join(KB_ROOT_PATH, "info.db")
Expand All @@ -65,6 +69,13 @@ kbs_config = {
"password": "",
"secure": False,
},
"zilliz": {
"host": "in01-a7ce524e41e3935.ali-cn-hangzhou.vectordb.zilliz.com.cn",
"port": "19530",
"user": "",
"password": "",
"secure": True,
},
"pg": {
"connection_uri": "postgresql://postgres:postgres@127.0.0.1:5432/langchain_chatchat",
}
Expand All @@ -74,11 +85,11 @@ kbs_config = {
text_splitter_dict = {
"ChineseRecursiveTextSplitter": {
"source": "huggingface", ## 选择tiktoken则使用openai的方法
"tokenizer_name_or_path": "gpt2",
"tokenizer_name_or_path": "",
},
"SpacyTextSplitter": {
"source": "huggingface",
"tokenizer_name_or_path": "",
"tokenizer_name_or_path": "gpt2",
},
"RecursiveCharacterTextSplitter": {
"source": "tiktoken",
Expand Down
2 changes: 2 additions & 0 deletions configs/model_config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ MODEL_PATH = {
"bge-base-zh": "BAAI/bge-base-zh",
"bge-large-zh": "BAAI/bge-large-zh",
"bge-large-zh-noinstruct": "BAAI/bge-large-zh-noinstruct",
"bge-base-zh-v1.5": "BAAI/bge-base-zh-v1.5",
"bge-large-zh-v1.5": "BAAI/bge-large-zh-v1.5",
"piccolo-base-zh": "sensenova/piccolo-base-zh",
"piccolo-large-zh": "sensenova/piccolo-large-zh",
"text-embedding-ada-002": "your OPENAI_API_KEY",
Expand Down
105 changes: 98 additions & 7 deletions configs/prompt_config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,106 @@
# - context: 从检索结果拼接的知识文本
# - question: 用户提出的问题

# Agent对话支持的变量:

PROMPT_TEMPLATES = {
# LLM对话模板
"llm_chat": "{{ input }}",
# - tools: 可用的工具列表
# - tool_names: 可用的工具名称列表
# - history: 用户和Agent的对话历史
# - input: 用户输入内容
# - agent_scratchpad: Agent的思维记录

PROMPT_TEMPLATES = {}

PROMPT_TEMPLATES["llm_chat"] = {
"default": "{{ input }}",

"py":
"""
你是一个聪明的代码助手,请你给我写出简单的py代码。 \n
{{ input }}
"""
,
}

PROMPT_TEMPLATES["knowledge_base_chat"] = {
"default":
"""
<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。 </指令>
<已知信息>{{ context }}</已知信息>、
<问题>{{ question }}</问题>
""",
"text":
"""
<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,答案请使用中文。 </指令>
<已知信息>{{ context }}</已知信息>、
<问题>{{ question }}</问题>
""",
}
PROMPT_TEMPLATES["search_engine_chat"] = {
"default":
"""
<指令>这是我搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题。如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。 </指令>
<已知信息>{{ context }}</已知信息>、
<问题>{{ question }}</问题>
""",

"search":
"""
<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,答案请使用中文。 </指令>
<已知信息>{{ context }}</已知信息>、
<问题>{{ question }}</问题>
""",
}
PROMPT_TEMPLATES["agent_chat"] = {
"default":
"""
Answer the following questions as best you can. If it is in order, you can use some tools appropriately.You have access to the following tools:

{tools}

Please note that the "知识库查询工具" is information about the "西交利物浦大学" ,and if a question is asked about it, you must answer with the knowledge base,
Please note that the "天气查询工具" can only be used once since Question begin.

Use the following format:
Question: the input question you must answer1
Thought: you should always think about what to do and what tools to use.
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question


Begin!
history:
{history}
Question: {input}
Thought: {agent_scratchpad}
""",
"ChatGLM":
"""
请请严格按照提供的思维方式来思考。你的知识不一定正确,所以你一定要用提供的工具来思考,并给出用户答案。
你有以下工具可以使用:
{tools}
```
Question: 用户的提问或者观察到的信息,
Thought: 你应该思考该做什么,是根据工具的结果来回答问题,还是决定使用什么工具。
Action: 需要使用的工具,应该是在[{tool_names}]中的一个。
Action Input: 传入工具的内容
Observation: 工具给出的答案(不是你生成的)
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: 通过工具给出的答案,你是否能回答Question。
Final Answer是你的答案

# 基于本地知识问答的提示词模
"knowledge_base_chat": """<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。 </指令>
现在,我们开始!
你和用户的历史记录:
History:
{history}

<已知信息>{{ context }}</已知信息>
用户开始以提问:
Question: {input}
Thought: {agent_scratchpad}

<问题>{{ question }}</问题>""",
""",
}
37 changes: 21 additions & 16 deletions configs/server_config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ FSCHAT_OPENAI_API = {
# fastchat model_worker server
# 这些模型必须是在model_config.MODEL_PATH或ONLINE_MODEL中正确配置的。
# 在启动startup.py时,可用通过`--model-worker --model-name xxxx`指定模型,不指定则为LLM_MODEL
# 必须在这里添加的模型才会出现在WEBUI中可选模型列表里(LLM_MODEL会自动添加)
FSCHAT_MODEL_WORKERS = {
# 所有模型共用的默认配置,可在模型专项配置中进行覆盖。
"default": {
"host": DEFAULT_BIND_HOST,
"port": 20002,
"device": LLM_DEVICE,
# False,'vllm',使用的推理加速框架,使用vllm如果出现HuggingFace通信问题,参见doc/FAQ
"infer_turbo": "vllm" if sys.platform.startswith("linux") else False,
# vllm对一些模型支持还不成熟,暂时默认关闭
"infer_turbo": False,

# model_worker多卡加载需要配置的参数
# "gpus": None, # 使用的GPU,以str的格式指定,如"0,1",如失效请使用CUDA_VISIBLE_DEVICES="0,1"等形式指定
Expand Down Expand Up @@ -97,21 +99,24 @@ FSCHAT_MODEL_WORKERS = {
"zhipu-api": { # 请为每个要运行的在线API设置不同的端口
"port": 21001,
},
"minimax-api": {
"port": 21002,
},
"xinghuo-api": {
"port": 21003,
},
"qianfan-api": {
"port": 21004,
},
"fangzhou-api": {
"port": 21005,
},
"qwen-api": {
"port": 21006,
},
# "minimax-api": {
# "port": 21002,
# },
# "xinghuo-api": {
# "port": 21003,
# },
# "qianfan-api": {
# "port": 21004,
# },
# "fangzhou-api": {
# "port": 21005,
# },
# "qwen-api": {
# "port": 21006,
# },
# "baichuan-api": {
# "port": 21007,
# },
}

# fastchat multi model worker server
Expand Down
Binary file added img/LLM_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/agent_continue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/agent_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/init_knowledge_base.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/knowledge_base_success.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/webui_0915_0.png
Binary file not shown.
Binary file removed img/webui_0915_1.png
Binary file not shown.
Binary file removed knowledge_base/samples/vector_store/index.faiss
Binary file not shown.
Binary file removed knowledge_base/samples/vector_store/index.pkl
Binary file not shown.
19 changes: 10 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
langchain>=0.0.302
fschat[model_worker]==0.2.29
langchain>=0.0.314
langchain-experimental>=0.0.30
fschat[model_worker]==0.2.30
openai
sentence_transformers
transformers>=4.33.0
torch>=2.0.1
transformers>=4.34
torch>=2.0.1 # 推荐2.1
torchvision
torchaudio
fastapi>=0.103.1
fastapi>=0.103.2
nltk~=3.8.1
uvicorn~=0.23.1
starlette~=0.27.0
pydantic~=1.10.11
unstructured[all-docs]>=0.10.4
unstructured[all-docs]>=0.10.12
python-magic-bin; sys_platform == 'win32'
SQLAlchemy==2.0.19
faiss-cpu
accelerate
spacy
PyMuPDF==1.22.5
rapidocr_onnxruntime>=1.3.2
PyMuPDF
rapidocr_onnxruntime

requests
pathlib
pytest
scikit-learn
numexpr
vllm==0.1.7; sys_platform == "linux"
vllm>=0.2.0; sys_platform == "linux"
# online api libs
# zhipuai
# dashscope>=1.10.0 # qwen
Expand Down
Loading