|
import torch.cuda |
|
import torch.backends |
|
import os |
|
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) |
|
|
|
|
|
|
|
|
|
embedding_model_dict = { |
|
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh", |
|
"ernie-base": "nghuyong/ernie-3.0-base-zh", |
|
"text2vec-base": "shibing624/text2vec-base-chinese", |
|
"text2vec": "/home/wsy/Langchain-chat/embedding/text2vec-large-chinese", |
|
"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", |
|
"m3e-small": "moka-ai/m3e-small", |
|
"m3e-base": "moka-ai/m3e-base", |
|
} |
|
|
|
|
|
EMBEDDING_MODEL = "text2vec" |
|
|
|
|
|
EMBEDDING_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" |
|
|
|
|
|
|
|
|
|
|
|
|
|
llm_model_dict = { |
|
"chatglm-6b-int4-qe": { |
|
"name": "chatglm-6b-int4-qe", |
|
"pretrained_model_name": "THUDM/chatglm-6b-int4-qe", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm-6b-int4": { |
|
"name": "chatglm-6b-int4", |
|
"pretrained_model_name": "THUDM/chatglm-6b-int4", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm-6b-int8": { |
|
"name": "chatglm-6b-int8", |
|
"pretrained_model_name": "THUDM/chatglm-6b-int8", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm-6b": { |
|
"name": "chatglm-6b", |
|
"pretrained_model_name": "THUDM/chatglm-6b", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
|
|
|
|
|
|
"chatglm-fitness-RLHF": { |
|
"name": "chatglm-fitness-RLHF", |
|
"pretrained_model_name": "/home/wsy/chatglm-fitness-RLHF", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm2-6b": { |
|
"name": "chatglm2-6b", |
|
"pretrained_model_name": "/home/xwy/chatglm2-6b", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm2-6b-32k": { |
|
"name": "chatglm2-6b-32k", |
|
"pretrained_model_name": "THUDM/chatglm2-6b-32k", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
|
|
"chatglm2-cpp": { |
|
"name": "chatglm2-cpp", |
|
"pretrained_model_name": "cylee0909/chatglm2cpp", |
|
"local_model_path": None, |
|
"provides": "ChatGLMCppLLMChain" |
|
}, |
|
"chatglm2-6b-int4": { |
|
"name": "chatglm2-6b-int4", |
|
"pretrained_model_name": "THUDM/chatglm2-6b-int4", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatglm2-6b-int8": { |
|
"name": "chatglm2-6b-int8", |
|
"pretrained_model_name": "THUDM/chatglm2-6b-int8", |
|
"local_model_path": None, |
|
"provides": "ChatGLMLLMChain" |
|
}, |
|
"chatyuan": { |
|
"name": "chatyuan", |
|
"pretrained_model_name": "ClueAI/ChatYuan-large-v2", |
|
"local_model_path": None, |
|
"provides": "MOSSLLMChain" |
|
}, |
|
"moss": { |
|
"name": "moss", |
|
"pretrained_model_name": "fnlp/moss-moon-003-sft", |
|
"local_model_path": None, |
|
"provides": "MOSSLLMChain" |
|
}, |
|
"moss-int4": { |
|
"name": "moss", |
|
"pretrained_model_name": "fnlp/moss-moon-003-sft-int4", |
|
"local_model_path": None, |
|
"provides": "MOSSLLM" |
|
}, |
|
"vicuna-13b-hf": { |
|
"name": "vicuna-13b-hf", |
|
"pretrained_model_name": "vicuna-13b-hf", |
|
"local_model_path": None, |
|
"provides": "LLamaLLMChain" |
|
}, |
|
"vicuna-7b-hf": { |
|
"name": "vicuna-13b-hf", |
|
"pretrained_model_name": "vicuna-13b-hf", |
|
"local_model_path": None, |
|
"provides": "LLamaLLMChain" |
|
}, |
|
|
|
|
|
|
|
|
|
"bloomz-7b1": { |
|
"name": "bloomz-7b1", |
|
"pretrained_model_name": "bigscience/bloomz-7b1", |
|
"local_model_path": None, |
|
"provides": "MOSSLLMChain" |
|
|
|
}, |
|
|
|
|
|
"bloom-3b": { |
|
"name": "bloom-3b", |
|
"pretrained_model_name": "bigscience/bloom-3b", |
|
"local_model_path": None, |
|
"provides": "MOSSLLMChain" |
|
|
|
}, |
|
"baichuan-7b": { |
|
"name": "baichuan-7b", |
|
"pretrained_model_name": "/home/wsy/baichuan7b-chat", |
|
"local_model_path": None, |
|
"provides": "MOSSLLMChain" |
|
}, |
|
"Baichuan-13b-Chat": { |
|
"name": "Baichuan-13b-Chat", |
|
"pretrained_model_name": "baichuan-inc/Baichuan-13b-Chat", |
|
"local_model_path": None, |
|
"provides": "BaichuanLLMChain" |
|
}, |
|
|
|
"ggml-vicuna-13b-1.1-q5": { |
|
"name": "ggml-vicuna-13b-1.1-q5", |
|
"pretrained_model_name": "lmsys/vicuna-13b-delta-v1.1", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"local_model_path": f'''{"/".join(os.path.abspath(__file__).split("/")[:3])}/.cache/huggingface/hub/models--vicuna--ggml-vicuna-13b-1.1/blobs/''', |
|
"provides": "LLamaLLMChain" |
|
}, |
|
|
|
|
|
"fastchat-chatglm-6b": { |
|
"name": "chatglm-6b", |
|
"pretrained_model_name": "chatglm-6b", |
|
"local_model_path": None, |
|
"provides": "FastChatOpenAILLMChain", |
|
"api_base_url": "http://localhost:8000/v1", |
|
"api_key": "EMPTY" |
|
}, |
|
|
|
"fastchat-chatglm-6b-int4": { |
|
"name": "chatglm-6b-int4", |
|
"pretrained_model_name": "chatglm-6b-int4", |
|
"local_model_path": None, |
|
"provides": "FastChatOpenAILLMChain", |
|
"api_base_url": "http://localhost:8001/v1", |
|
"api_key": "EMPTY" |
|
}, |
|
"fastchat-chatglm2-6b": { |
|
"name": "chatglm2-6b", |
|
"pretrained_model_name": "chatglm2-6b", |
|
"local_model_path": None, |
|
"provides": "FastChatOpenAILLMChain", |
|
"api_base_url": "http://localhost:8000/v1" |
|
}, |
|
|
|
|
|
"fastchat-vicuna-13b-hf": { |
|
"name": "vicuna-13b-hf", |
|
"pretrained_model_name": "vicuna-13b-hf", |
|
"local_model_path": None, |
|
"provides": "FastChatOpenAILLMChain", |
|
"api_base_url": "http://localhost:8000/v1", |
|
"api_key": "EMPTY" |
|
}, |
|
|
|
"fastchat-baichuan2-7b-chat": { |
|
"name": "Baichuan2-7B-chat", |
|
"pretrained_model_name": "Baichuan2-7B-chat", |
|
"local_model_path": None, |
|
"provides": "FastChatOpenAILLMChain", |
|
"api_base_url": "http://localhost:8000/v1", |
|
"api_key": "EMPTY" |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"openai-chatgpt-3.5": { |
|
"name": "gpt-3.5-turbo", |
|
"pretrained_model_name": "gpt-3.5-turbo", |
|
"provides": "FastChatOpenAILLMChain", |
|
"local_model_path": None, |
|
"api_base_url": "https://openai.api2d.net/v1", |
|
"api_key": "fk216618-f39L8P2msSmhydRuG51oDh1aDG0CklUV" |
|
}, |
|
|
|
} |
|
|
|
|
|
LLM_MODEL = "openai-chatgpt-3.5" |
|
|
|
LOAD_IN_8BIT = False |
|
|
|
BF16 = False |
|
|
|
LORA_DIR = "loras/" |
|
|
|
|
|
|
|
LORA_NAME = "" |
|
USE_LORA = True if LORA_NAME else False |
|
|
|
|
|
STREAMING = True |
|
|
|
|
|
LORA_MODEL_PATH_BAICHUAN="" |
|
|
|
|
|
USE_PTUNING_V2 = False |
|
PTUNING_DIR='./ptuning-v2' |
|
|
|
LLM_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" |
|
|
|
|
|
KB_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "knowledge_base") |
|
|
|
|
|
PROMPT_TEMPLATE = """已知信息: |
|
{context} |
|
|
|
你将作为一个python助教, 服务于大学一年级的python基础课堂, 请你根据上述已知信息,简洁和专业的来回答学生们的问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题” 或 “没有提供足够的相关信息”,不允许在答案中添加编造成分,答案请使用中文,如果不清晰的可以使用带注释的代码解释。 问题是:{question}""" |
|
|
|
|
|
CACHED_VS_NUM = 2 |
|
|
|
|
|
SENTENCE_SIZE = 130 |
|
|
|
|
|
CHUNK_SIZE = 350 |
|
|
|
|
|
LLM_HISTORY_LEN = 3 |
|
|
|
|
|
VECTOR_SEARCH_TOP_K = 2 |
|
|
|
|
|
VECTOR_SEARCH_SCORE_THRESHOLD = 500 |
|
|
|
NLTK_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "nltk_data") |
|
|
|
|
|
FLAG_USER_NAME = "王思源" |
|
|
|
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} |
|
""") |
|
|
|
|
|
|
|
OPEN_CROSS_DOMAIN = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BING_SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search" |
|
|
|
|
|
|
|
|
|
BING_SUBSCRIPTION_KEY = "" |
|
|
|
|
|
|
|
|
|
ZH_TITLE_ENHANCE = True |
|
|