2023-04-13 23:01:52 +08:00
|
|
|
|
import torch.cuda
|
|
|
|
|
|
import torch.backends
|
2023-04-25 20:14:33 +08:00
|
|
|
|
import os
|
2023-05-08 18:29:09 +08:00
|
|
|
|
import logging
|
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
LOG_FORMAT = "%(levelname) -5s %(asctime)s" "-1d: %(message)s"
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
logging.basicConfig(format=LOG_FORMAT)
|
2023-04-13 23:01:52 +08:00
|
|
|
|
|
2023-06-12 00:10:47 +08:00
|
|
|
|
# 在以下字典中修改属性值,以指定本地embedding模型存储位置
|
|
|
|
|
|
# 如将 "text2vec": "GanymedeNil/text2vec-large-chinese" 修改为 "text2vec": "User/Downloads/text2vec-large-chinese"
|
|
|
|
|
|
# 此处请写绝对路径
|
2023-04-13 23:01:52 +08:00
|
|
|
|
embedding_model_dict = {
|
|
|
|
|
|
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
|
|
|
|
|
|
"ernie-base": "nghuyong/ernie-3.0-base-zh",
|
2023-04-27 07:40:57 +08:00
|
|
|
|
"text2vec-base": "shibing624/text2vec-base-chinese",
|
2023-04-13 23:01:52 +08:00
|
|
|
|
"text2vec": "GanymedeNil/text2vec-large-chinese",
|
2023-08-01 10:58:05 +08:00
|
|
|
|
"text2vec-base-multilingual": "shibing624/text2vec-base-multilingual",
|
|
|
|
|
|
"text2vec-base-chinese-sentence": "shibing624/text2vec-base-chinese-sentence",
|
|
|
|
|
|
"text2vec-base-chinese-paraphrase": "shibing624/text2vec-base-chinese-paraphrase",
|
2023-06-09 19:04:34 +08:00
|
|
|
|
"m3e-small": "moka-ai/m3e-small",
|
|
|
|
|
|
"m3e-base": "moka-ai/m3e-base",
|
2023-04-13 23:01:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Embedding model name
|
2023-04-13 23:20:45 +08:00
|
|
|
|
EMBEDDING_MODEL = "text2vec"
|
2023-04-13 23:01:52 +08:00
|
|
|
|
|
|
|
|
|
|
# Embedding running device
|
|
|
|
|
|
EMBEDDING_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
|
|
# supported LLM models
|
2023-05-22 00:15:29 +08:00
|
|
|
|
# llm_model_dict 处理了loader的一些预设行为,如加载位置,模型名称,模型处理器实例
|
2023-06-12 00:10:47 +08:00
|
|
|
|
# 在以下字典中修改属性值,以指定本地 LLM 模型存储位置
|
|
|
|
|
|
# 如将 "chatglm-6b" 的 "local_model_path" 由 None 修改为 "User/Downloads/chatglm-6b"
|
2023-07-26 18:04:35 +08:00
|
|
|
|
# 此处请写绝对路径,且路径中必须包含repo-id的模型名称,因为FastChat是以模型名匹配的
|
2023-04-13 23:01:52 +08:00
|
|
|
|
llm_model_dict = {
|
2023-05-18 22:54:41 +08:00
|
|
|
|
"chatglm-6b-int4-qe": {
|
|
|
|
|
|
"name": "chatglm-6b-int4-qe",
|
2023-05-19 23:12:39 +08:00
|
|
|
|
"pretrained_model_name": "THUDM/chatglm-6b-int4-qe",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-05-18 22:54:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
"chatglm-6b-int4": {
|
|
|
|
|
|
"name": "chatglm-6b-int4",
|
2023-05-19 23:12:39 +08:00
|
|
|
|
"pretrained_model_name": "THUDM/chatglm-6b-int4",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-05-18 22:54:41 +08:00
|
|
|
|
},
|
2023-05-19 23:16:39 +08:00
|
|
|
|
"chatglm-6b-int8": {
|
|
|
|
|
|
"name": "chatglm-6b-int8",
|
|
|
|
|
|
"pretrained_model_name": "THUDM/chatglm-6b-int8",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-05-19 23:16:39 +08:00
|
|
|
|
},
|
2023-05-18 22:54:41 +08:00
|
|
|
|
"chatglm-6b": {
|
|
|
|
|
|
"name": "chatglm-6b",
|
2023-05-19 23:16:39 +08:00
|
|
|
|
"pretrained_model_name": "THUDM/chatglm-6b",
|
2023-06-12 00:10:47 +08:00
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-05-18 22:54:41 +08:00
|
|
|
|
},
|
2023-07-26 21:41:27 +08:00
|
|
|
|
# langchain-ChatGLM 用户“帛凡” @BoFan-tunning 基于ChatGLM-6B 训练并提供的权重合并模型和 lora 权重文件 chatglm-fitness-RLHF
|
|
|
|
|
|
# 详细信息见 HuggingFace 模型介绍页 https://huggingface.co/fb700/chatglm-fitness-RLHF
|
|
|
|
|
|
# 使用该模型或者lora权重文件,对比chatglm-6b、chatglm2-6b、百川7b,甚至其它未经过微调的更高参数的模型,在本项目中,总结能力可获得显著提升。
|
|
|
|
|
|
"chatglm-fitness-RLHF": {
|
|
|
|
|
|
"name": "chatglm-fitness-RLHF",
|
|
|
|
|
|
"pretrained_model_name": "fb700/chatglm-fitness-RLHF",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "ChatGLMLLMChain"
|
|
|
|
|
|
},
|
2023-06-25 17:04:16 +08:00
|
|
|
|
"chatglm2-6b": {
|
|
|
|
|
|
"name": "chatglm2-6b",
|
|
|
|
|
|
"pretrained_model_name": "THUDM/chatglm2-6b",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-06-25 17:04:16 +08:00
|
|
|
|
},
|
2023-08-01 10:58:05 +08:00
|
|
|
|
"chatglm2-6b-32k": {
|
|
|
|
|
|
"name": "chatglm2-6b-32k",
|
|
|
|
|
|
"pretrained_model_name": "THUDM/chatglm2-6b-32k",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "ChatGLMLLMChain"
|
|
|
|
|
|
},
|
2023-07-16 17:24:46 +08:00
|
|
|
|
# 注:chatglm2-cpp已在mac上测试通过,其他系统暂不支持
|
|
|
|
|
|
"chatglm2-cpp": {
|
|
|
|
|
|
"name": "chatglm2-cpp",
|
|
|
|
|
|
"pretrained_model_name": "cylee0909/chatglm2cpp",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "ChatGLMCppLLMChain"
|
|
|
|
|
|
},
|
2023-07-04 19:04:57 +08:00
|
|
|
|
"chatglm2-6b-int4": {
|
|
|
|
|
|
"name": "chatglm2-6b-int4",
|
|
|
|
|
|
"pretrained_model_name": "THUDM/chatglm2-6b-int4",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-07-04 19:04:57 +08:00
|
|
|
|
},
|
|
|
|
|
|
"chatglm2-6b-int8": {
|
|
|
|
|
|
"name": "chatglm2-6b-int8",
|
|
|
|
|
|
"pretrained_model_name": "THUDM/chatglm2-6b-int8",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "ChatGLMLLMChain"
|
2023-07-04 19:04:57 +08:00
|
|
|
|
},
|
2023-05-18 22:54:41 +08:00
|
|
|
|
"chatyuan": {
|
|
|
|
|
|
"name": "chatyuan",
|
2023-05-19 23:12:39 +08:00
|
|
|
|
"pretrained_model_name": "ClueAI/ChatYuan-large-v2",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "MOSSLLMChain"
|
2023-05-18 22:54:41 +08:00
|
|
|
|
},
|
2023-05-19 23:16:39 +08:00
|
|
|
|
"moss": {
|
|
|
|
|
|
"name": "moss",
|
|
|
|
|
|
"pretrained_model_name": "fnlp/moss-moon-003-sft",
|
2023-05-19 23:12:39 +08:00
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "MOSSLLMChain"
|
2023-05-23 23:10:31 +08:00
|
|
|
|
},
|
2023-07-13 21:22:35 +08:00
|
|
|
|
"moss-int4": {
|
|
|
|
|
|
"name": "moss",
|
|
|
|
|
|
"pretrained_model_name": "fnlp/moss-moon-003-sft-int4",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "MOSSLLM"
|
|
|
|
|
|
},
|
2023-05-23 23:10:31 +08:00
|
|
|
|
"vicuna-13b-hf": {
|
|
|
|
|
|
"name": "vicuna-13b-hf",
|
|
|
|
|
|
"pretrained_model_name": "vicuna-13b-hf",
|
2023-06-13 18:36:07 +08:00
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "LLamaLLMChain"
|
|
|
|
|
|
},
|
|
|
|
|
|
"vicuna-7b-hf": {
|
|
|
|
|
|
"name": "vicuna-13b-hf",
|
|
|
|
|
|
"pretrained_model_name": "vicuna-13b-hf",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "LLamaLLMChain"
|
2023-07-11 20:19:50 +08:00
|
|
|
|
},
|
2023-07-11 19:36:50 +08:00
|
|
|
|
# 直接调用返回requests.exceptions.ConnectionError错误,需要通过huggingface_hub包里的snapshot_download函数
|
|
|
|
|
|
# 下载模型,如果snapshot_download还是返回网络错误,多试几次,一般是可以的,
|
|
|
|
|
|
# 如果仍然不行,则应该是网络加了防火墙(在服务器上这种情况比较常见),基本只能从别的设备上下载,
|
|
|
|
|
|
# 然后转移到目标设备了.
|
2023-07-11 20:19:50 +08:00
|
|
|
|
"bloomz-7b1": {
|
|
|
|
|
|
"name": "bloomz-7b1",
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"pretrained_model_name": "bigscience/bloomz-7b1",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "MOSSLLMChain"
|
2023-07-11 19:36:50 +08:00
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
# 实测加载bigscience/bloom-3b需要170秒左右,暂不清楚为什么这么慢
|
|
|
|
|
|
# 应与它要加载专有token有关
|
2023-07-11 20:19:50 +08:00
|
|
|
|
"bloom-3b": {
|
|
|
|
|
|
"name": "bloom-3b",
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"pretrained_model_name": "bigscience/bloom-3b",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "MOSSLLMChain"
|
2023-07-11 19:36:50 +08:00
|
|
|
|
|
2023-07-11 20:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
"baichuan-7b": {
|
|
|
|
|
|
"name": "baichuan-7b",
|
|
|
|
|
|
"pretrained_model_name": "baichuan-inc/baichuan-7B",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "MOSSLLMChain"
|
2023-07-11 20:19:50 +08:00
|
|
|
|
},
|
2023-07-11 19:36:50 +08:00
|
|
|
|
# llama-cpp模型的兼容性问题参考https://github.com/abetlen/llama-cpp-python/issues/204
|
2023-07-11 20:19:50 +08:00
|
|
|
|
"ggml-vicuna-13b-1.1-q5": {
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"name": "ggml-vicuna-13b-1.1-q5",
|
|
|
|
|
|
"pretrained_model_name": "lmsys/vicuna-13b-delta-v1.1",
|
|
|
|
|
|
# 这里需要下载好模型的路径,如果下载模型是默认路径则它会下载到用户工作区的
|
|
|
|
|
|
# /.cache/huggingface/hub/models--vicuna--ggml-vicuna-13b-1.1/
|
|
|
|
|
|
# 还有就是由于本项目加载模型的方式设置的比较严格,下载完成后仍需手动修改模型的文件名
|
|
|
|
|
|
# 将其设置为与Huggface Hub一致的文件名
|
|
|
|
|
|
# 此外不同时期的ggml格式并不兼容,因此不同时期的ggml需要安装不同的llama-cpp-python库,且实测pip install 不好使
|
|
|
|
|
|
# 需要手动从https://github.com/abetlen/llama-cpp-python/releases/tag/下载对应的wheel安装
|
|
|
|
|
|
# 实测v0.1.63与本模型的vicuna/ggml-vicuna-13b-1.1/ggml-vic13b-q5_1.bin可以兼容
|
2023-07-11 20:19:50 +08:00
|
|
|
|
"local_model_path": f'''{"/".join(os.path.abspath(__file__).split("/")[:3])}/.cache/huggingface/hub/models--vicuna--ggml-vicuna-13b-1.1/blobs/''',
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "LLamaLLMChain"
|
2023-05-23 23:10:31 +08:00
|
|
|
|
},
|
2023-05-31 22:50:35 +08:00
|
|
|
|
|
|
|
|
|
|
# 通过 fastchat 调用的模型请参考如下格式
|
|
|
|
|
|
"fastchat-chatglm-6b": {
|
|
|
|
|
|
"name": "chatglm-6b", # "name"修改为fastchat服务中的"model_name"
|
|
|
|
|
|
"pretrained_model_name": "chatglm-6b",
|
2023-05-23 23:10:31 +08:00
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "FastChatOpenAILLMChain", # 使用fastchat api时,需保证"provides"为"FastChatOpenAILLMChain"
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"api_base_url": "http://localhost:8000/v1", # "name"修改为fastchat服务中的"api_base_url"
|
|
|
|
|
|
"api_key": "EMPTY"
|
2023-07-19 10:00:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
# 通过 fastchat 调用的模型请参考如下格式
|
|
|
|
|
|
"fastchat-chatglm-6b-int4": {
|
|
|
|
|
|
"name": "chatglm-6b-int4", # "name"修改为fastchat服务中的"model_name"
|
|
|
|
|
|
"pretrained_model_name": "chatglm-6b-int4",
|
|
|
|
|
|
"local_model_path": None,
|
|
|
|
|
|
"provides": "FastChatOpenAILLMChain", # 使用fastchat api时,需保证"provides"为"FastChatOpenAILLMChain"
|
|
|
|
|
|
"api_base_url": "http://localhost:8001/v1", # "name"修改为fastchat服务中的"api_base_url"
|
|
|
|
|
|
"api_key": "EMPTY"
|
2023-05-31 22:11:28 +08:00
|
|
|
|
},
|
2023-06-25 17:04:16 +08:00
|
|
|
|
"fastchat-chatglm2-6b": {
|
|
|
|
|
|
"name": "chatglm2-6b", # "name"修改为fastchat服务中的"model_name"
|
|
|
|
|
|
"pretrained_model_name": "chatglm2-6b",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "FastChatOpenAILLMChain", # 使用fastchat api时,需保证"provides"为"FastChatOpenAILLMChain"
|
2023-06-25 17:04:16 +08:00
|
|
|
|
"api_base_url": "http://localhost:8000/v1" # "name"修改为fastchat服务中的"api_base_url"
|
|
|
|
|
|
},
|
2023-05-31 22:11:28 +08:00
|
|
|
|
|
2023-05-31 22:50:35 +08:00
|
|
|
|
# 通过 fastchat 调用的模型请参考如下格式
|
|
|
|
|
|
"fastchat-vicuna-13b-hf": {
|
|
|
|
|
|
"name": "vicuna-13b-hf", # "name"修改为fastchat服务中的"model_name"
|
2023-05-31 22:11:28 +08:00
|
|
|
|
"pretrained_model_name": "vicuna-13b-hf",
|
|
|
|
|
|
"local_model_path": None,
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "FastChatOpenAILLMChain", # 使用fastchat api时,需保证"provides"为"FastChatOpenAILLMChain"
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"api_base_url": "http://localhost:8000/v1", # "name"修改为fastchat服务中的"api_base_url"
|
|
|
|
|
|
"api_key": "EMPTY"
|
2023-05-31 22:11:28 +08:00
|
|
|
|
},
|
2023-07-11 23:40:49 +08:00
|
|
|
|
# 调用chatgpt时如果报出: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.openai.com', port=443):
|
|
|
|
|
|
# Max retries exceeded with url: /v1/chat/completions
|
|
|
|
|
|
# 则需要将urllib3版本修改为1.25.11
|
2023-07-21 09:29:43 +08:00
|
|
|
|
# 如果依然报urllib3.exceptions.MaxRetryError: HTTPSConnectionPool,则将https改为http
|
|
|
|
|
|
# 参考https://zhuanlan.zhihu.com/p/350015032
|
2023-07-11 23:40:49 +08:00
|
|
|
|
|
|
|
|
|
|
# 如果报出:raise NewConnectionError(
|
2023-07-12 23:09:28 +08:00
|
|
|
|
# urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000001FE4BDB85E0>:
|
2023-07-11 23:40:49 +08:00
|
|
|
|
# Failed to establish a new connection: [WinError 10060]
|
2023-07-19 10:57:09 +08:00
|
|
|
|
# 则是因为内地和香港的IP都被OPENAI封了,需要切换为日本、新加坡等地
|
2023-07-11 20:19:50 +08:00
|
|
|
|
"openai-chatgpt-3.5": {
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"name": "gpt-3.5-turbo",
|
|
|
|
|
|
"pretrained_model_name": "gpt-3.5-turbo",
|
2023-07-12 23:09:28 +08:00
|
|
|
|
"provides": "FastChatOpenAILLMChain",
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"local_model_path": None,
|
2023-07-25 11:16:02 +08:00
|
|
|
|
"api_base_url": "https://api.openai.com/v1",
|
2023-07-11 19:36:50 +08:00
|
|
|
|
"api_key": ""
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2023-04-13 23:01:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-23 23:10:31 +08:00
|
|
|
|
# LLM 名称
|
2023-08-01 10:58:05 +08:00
|
|
|
|
LLM_MODEL = "chatglm2-6b-32k"
|
2023-05-23 23:10:31 +08:00
|
|
|
|
# 量化加载8bit 模型
|
|
|
|
|
|
LOAD_IN_8BIT = False
|
|
|
|
|
|
# Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU.
|
|
|
|
|
|
BF16 = False
|
|
|
|
|
|
# 本地lora存放的位置
|
|
|
|
|
|
LORA_DIR = "loras/"
|
2023-04-13 23:01:52 +08:00
|
|
|
|
|
2023-07-26 17:46:02 +08:00
|
|
|
|
# LORA的名称,如有请指定为列表
|
|
|
|
|
|
|
|
|
|
|
|
LORA_NAME = ""
|
|
|
|
|
|
USE_LORA = True if LORA_NAME else False
|
2023-05-04 21:01:55 +08:00
|
|
|
|
|
2023-05-01 17:50:16 +08:00
|
|
|
|
# LLM streaming reponse
|
|
|
|
|
|
STREAMING = True
|
|
|
|
|
|
|
2023-04-15 14:43:12 +08:00
|
|
|
|
# Use p-tuning-v2 PrefixEncoder
|
|
|
|
|
|
USE_PTUNING_V2 = False
|
2023-07-21 15:09:33 +08:00
|
|
|
|
PTUNING_DIR='./ptuning-v2'
|
2023-04-13 23:01:52 +08:00
|
|
|
|
# LLM running device
|
|
|
|
|
|
LLM_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
|
|
|
|
|
|
2023-06-13 23:54:29 +08:00
|
|
|
|
# 知识库默认存储路径
|
|
|
|
|
|
KB_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "knowledge_base")
|
2023-04-19 23:02:47 +08:00
|
|
|
|
|
2023-04-26 23:20:08 +08:00
|
|
|
|
# 基于上下文的prompt模版,请务必保留"{question}"和"{context}"
|
2023-05-02 00:28:09 +08:00
|
|
|
|
PROMPT_TEMPLATE = """已知信息:
|
2023-05-01 23:55:37 +08:00
|
|
|
|
{context}
|
|
|
|
|
|
|
2023-05-02 00:28:09 +08:00
|
|
|
|
根据上述已知信息,简洁和专业的来回答用户的问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题” 或 “没有提供足够的相关信息”,不允许在答案中添加编造成分,答案请使用中文。 问题是:{question}"""
|
2023-04-28 00:02:42 +08:00
|
|
|
|
|
2023-07-04 19:04:57 +08:00
|
|
|
|
# 缓存知识库数量,如果是ChatGLM2,ChatGLM2-int4,ChatGLM2-int8模型若检索效果不好可以调成’10’
|
2023-05-30 23:05:39 +08:00
|
|
|
|
CACHED_VS_NUM = 1
|
|
|
|
|
|
|
2023-05-06 23:26:49 +08:00
|
|
|
|
# 文本分句长度
|
|
|
|
|
|
SENTENCE_SIZE = 100
|
|
|
|
|
|
|
2023-04-28 00:02:42 +08:00
|
|
|
|
# 匹配后单段上下文长度
|
2023-05-04 20:48:36 +08:00
|
|
|
|
CHUNK_SIZE = 250
|
|
|
|
|
|
|
2023-06-13 23:54:29 +08:00
|
|
|
|
# 传入LLM的历史记录长度
|
2023-05-04 20:48:36 +08:00
|
|
|
|
LLM_HISTORY_LEN = 3
|
|
|
|
|
|
|
2023-06-13 23:54:29 +08:00
|
|
|
|
# 知识库检索时返回的匹配内容条数
|
2023-05-04 20:48:36 +08:00
|
|
|
|
VECTOR_SEARCH_TOP_K = 5
|
|
|
|
|
|
|
2023-07-17 21:49:05 +08:00
|
|
|
|
# 知识检索内容相关度 Score, 数值范围约为0-1100,如果为0,则不生效,建议设置为500左右,经测试设置为小于500时,匹配结果更精准
|
|
|
|
|
|
VECTOR_SEARCH_SCORE_THRESHOLD = 500
|
2023-05-10 17:18:20 +08:00
|
|
|
|
|
2023-05-05 18:44:37 +08:00
|
|
|
|
NLTK_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "nltk_data")
|
2023-05-08 18:29:09 +08:00
|
|
|
|
|
|
|
|
|
|
FLAG_USER_NAME = uuid.uuid4().hex
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"""
|
|
|
|
|
|
loading model config
|
|
|
|
|
|
llm device: {LLM_DEVICE}
|
|
|
|
|
|
embedding device: {EMBEDDING_DEVICE}
|
|
|
|
|
|
dir: {os.path.dirname(os.path.dirname(__file__))}
|
|
|
|
|
|
flagging username: {FLAG_USER_NAME}
|
2023-05-10 17:18:20 +08:00
|
|
|
|
""")
|
2023-05-11 09:32:58 +08:00
|
|
|
|
|
|
|
|
|
|
# 是否开启跨域,默认为False,如果需要开启,请设置为True
|
|
|
|
|
|
# is open cross domain
|
|
|
|
|
|
OPEN_CROSS_DOMAIN = False
|
2023-05-21 22:30:28 +08:00
|
|
|
|
|
|
|
|
|
|
# Bing 搜索必备变量
|
2023-06-14 21:31:26 +08:00
|
|
|
|
# 使用 Bing 搜索需要使用 Bing Subscription Key,需要在azure port中申请试用bing search
|
|
|
|
|
|
# 具体申请方式请见
|
|
|
|
|
|
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/create-bing-search-service-resource
|
|
|
|
|
|
# 使用python创建bing api 搜索实例详见:
|
|
|
|
|
|
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/quickstarts/rest/python
|
2023-05-21 22:30:28 +08:00
|
|
|
|
BING_SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search"
|
2023-06-14 21:31:26 +08:00
|
|
|
|
# 注意不是bing Webmaster Tools的api key,
|
|
|
|
|
|
|
|
|
|
|
|
# 此外,如果是在服务器上,报Failed to establish a new connection: [Errno 110] Connection timed out
|
|
|
|
|
|
# 是因为服务器加了防火墙,需要联系管理员加白名单,如果公司的服务器的话,就别想了GG
|
2023-06-18 21:45:06 +08:00
|
|
|
|
BING_SUBSCRIPTION_KEY = ""
|
|
|
|
|
|
|
|
|
|
|
|
# 是否开启中文标题加强,以及标题增强的相关配置
|
|
|
|
|
|
# 通过增加标题判断,判断哪些文本为标题,并在metadata中进行标记;
|
|
|
|
|
|
# 然后将文本与往上一级的标题进行拼合,实现文本信息的增强。
|
2023-06-18 21:52:56 +08:00
|
|
|
|
ZH_TITLE_ENHANCE = False
|