From 409927ef8e8a407077b13b4052604cde85d980f0 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 22:26:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BB=9F=E4=B8=80=20transformers=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request_llm/requirements_chatglm.txt | 1 - request_llm/requirements_chatglm_onnx.txt | 1 - request_llm/requirements_jittorllms.txt | 1 - request_llm/requirements_moss.txt | 1 - requirements.txt | 2 +- 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/request_llm/requirements_chatglm.txt b/request_llm/requirements_chatglm.txt index b2629f8..cd53cd7 100644 --- a/request_llm/requirements_chatglm.txt +++ b/request_llm/requirements_chatglm.txt @@ -1,5 +1,4 @@ protobuf -transformers>=4.27.1 cpm_kernels torch>=1.10 mdtex2html diff --git a/request_llm/requirements_chatglm_onnx.txt b/request_llm/requirements_chatglm_onnx.txt index 70ab668..5481147 100644 --- a/request_llm/requirements_chatglm_onnx.txt +++ b/request_llm/requirements_chatglm_onnx.txt @@ -1,5 +1,4 @@ protobuf -transformers>=4.27.1 cpm_kernels torch>=1.10 mdtex2html diff --git a/request_llm/requirements_jittorllms.txt b/request_llm/requirements_jittorllms.txt index 1d86ff8..ddb6195 100644 --- a/request_llm/requirements_jittorllms.txt +++ b/request_llm/requirements_jittorllms.txt @@ -2,6 +2,5 @@ jittor >= 1.3.7.9 jtorch >= 0.1.3 torch torchvision -transformers==4.26.1 pandas jieba \ No newline at end of file diff --git a/request_llm/requirements_moss.txt b/request_llm/requirements_moss.txt index 8dd75bf..c27907c 100644 --- a/request_llm/requirements_moss.txt +++ b/request_llm/requirements_moss.txt @@ -1,5 +1,4 @@ torch -transformers==4.25.1 sentencepiece datasets accelerate diff --git a/requirements.txt b/requirements.txt index 5ff40cc..1958963 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ pydantic==1.10.11 tiktoken>=0.3.3 requests[socks] -transformers +transformers>=4.27.1 python-markdown-math beautifulsoup4 prompt_toolkit From 2d8f37baba454b6884dd9fa84cbae38220f5f5e5 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 22:43:15 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=BB=86=E5=88=86=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 3 +++ crazy_functions/Langchain知识库.py | 4 ++-- crazy_functions/crazy_utils.py | 2 +- request_llm/bridge_chatglm.py | 21 +++++++++++---------- request_llm/bridge_llama2.py | 2 +- themes/gradios.py | 4 ++-- toolbox.py | 12 ++++++++++++ 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/config.py b/config.py index 4b77bf9..a3bb74c 100644 --- a/config.py +++ b/config.py @@ -183,6 +183,9 @@ ALLOW_RESET_CONFIG = False PATH_PRIVATE_UPLOAD = "private_upload" # 日志文件夹的位置,请勿修改 PATH_LOGGING = "gpt_log" +# 除了连接OpenAI之外,还有哪些场合允许使用代理,请勿修改 +WHEN_TO_USE_PROXY = ["Download_LLM", "Download_Gradio_Theme"] + """ 在线大模型配置关联关系示意图 diff --git a/crazy_functions/Langchain知识库.py b/crazy_functions/Langchain知识库.py index 741a3d0..8433895 100644 --- a/crazy_functions/Langchain知识库.py +++ b/crazy_functions/Langchain知识库.py @@ -53,14 +53,14 @@ def 知识库问答(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 print('Checking Text2vec ...') from langchain.embeddings.huggingface import HuggingFaceEmbeddings - with ProxyNetworkActivate(): # 临时地激活代理网络 + with ProxyNetworkActivate('Download_LLM'): # 临时地激活代理网络 HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese") # < -------------------构建知识库--------------- > chatbot.append(['
'.join(file_manifest), "正在构建知识库..."]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 print('Establishing knowledge archive ...') - with ProxyNetworkActivate(): # 临时地激活代理网络 + with ProxyNetworkActivate('Download_LLM'): # 临时地激活代理网络 kai = knowledge_archive_interface() kai.feed_archive(file_manifest=file_manifest, id=kai_id) kai_files = kai.get_loaded_file() diff --git a/crazy_functions/crazy_utils.py b/crazy_functions/crazy_utils.py index 4bdd1fd..b7a1819 100644 --- a/crazy_functions/crazy_utils.py +++ b/crazy_functions/crazy_utils.py @@ -651,7 +651,7 @@ class knowledge_archive_interface(): from toolbox import ProxyNetworkActivate print('Checking Text2vec ...') from langchain.embeddings.huggingface import HuggingFaceEmbeddings - with ProxyNetworkActivate(): # 临时地激活代理网络 + with ProxyNetworkActivate('Download_LLM'): # 临时地激活代理网络 self.text2vec_large_chinese = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese") return self.text2vec_large_chinese diff --git a/request_llm/bridge_chatglm.py b/request_llm/bridge_chatglm.py index 6dac863..387b3e2 100644 --- a/request_llm/bridge_chatglm.py +++ b/request_llm/bridge_chatglm.py @@ -3,7 +3,7 @@ from transformers import AutoModel, AutoTokenizer import time import threading import importlib -from toolbox import update_ui, get_conf +from toolbox import update_ui, get_conf, ProxyNetworkActivate from multiprocessing import Process, Pipe load_message = "ChatGLM尚未加载,加载需要一段时间。注意,取决于`config.py`的配置,ChatGLM消耗大量的内存(CPU)或显存(GPU),也许会导致低配计算机卡死 ……" @@ -48,16 +48,17 @@ class GetGLMHandle(Process): while True: try: - if self.chatglm_model is None: - self.chatglm_tokenizer = AutoTokenizer.from_pretrained(_model_name_, trust_remote_code=True) - if device=='cpu': - self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).float() + with ProxyNetworkActivate('Download_LLM'): + if self.chatglm_model is None: + self.chatglm_tokenizer = AutoTokenizer.from_pretrained(_model_name_, trust_remote_code=True) + if device=='cpu': + self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).float() + else: + self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).half().cuda() + self.chatglm_model = self.chatglm_model.eval() + break else: - self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).half().cuda() - self.chatglm_model = self.chatglm_model.eval() - break - else: - break + break except: retry += 1 if retry > 3: diff --git a/request_llm/bridge_llama2.py b/request_llm/bridge_llama2.py index e236c94..d1be446 100644 --- a/request_llm/bridge_llama2.py +++ b/request_llm/bridge_llama2.py @@ -30,7 +30,7 @@ class GetONNXGLMHandle(LocalLLMHandle): with open(os.path.expanduser('~/.cache/huggingface/token'), 'w') as f: f.write(huggingface_token) model_id = 'meta-llama/Llama-2-7b-chat-hf' - with ProxyNetworkActivate(): + with ProxyNetworkActivate('Download_LLM'): self._tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=huggingface_token) # use fp16 model = AutoModelForCausalLM.from_pretrained(model_id, use_auth_token=huggingface_token).eval() diff --git a/themes/gradios.py b/themes/gradios.py index acabf75..6a34e88 100644 --- a/themes/gradios.py +++ b/themes/gradios.py @@ -5,7 +5,7 @@ CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAY def dynamic_set_theme(THEME): set_theme = gr.themes.ThemeClass() - with ProxyNetworkActivate(): + with ProxyNetworkActivate('Download_Gradio_Theme'): logging.info('正在下载Gradio主题,请稍等。') if THEME.startswith('Huggingface-'): THEME = THEME.lstrip('Huggingface-') if THEME.startswith('huggingface-'): THEME = THEME.lstrip('huggingface-') @@ -16,7 +16,7 @@ def adjust_theme(): try: set_theme = gr.themes.ThemeClass() - with ProxyNetworkActivate(): + with ProxyNetworkActivate('Download_Gradio_Theme'): logging.info('正在下载Gradio主题,请稍等。') THEME, = get_conf('THEME') if THEME.startswith('Huggingface-'): THEME = THEME.lstrip('Huggingface-') diff --git a/toolbox.py b/toolbox.py index 2ac1ef6..04853bc 100644 --- a/toolbox.py +++ b/toolbox.py @@ -956,7 +956,19 @@ class ProxyNetworkActivate(): """ 这段代码定义了一个名为TempProxy的空上下文管理器, 用于给一小段代码上代理 """ + def __init__(self, task=None) -> None: + self.task = task + if not task: + # 不给定task, 那么我们默认代理生效 + self.valid = True + else: + # 给定了task, 我们检查一下 + from toolbox import get_conf + WHEN_TO_USE_PROXY, = get_conf('WHEN_TO_USE_PROXY') + self.valid = (task in WHEN_TO_USE_PROXY) + def __enter__(self): + if not self.valid: return self from toolbox import get_conf proxies, = get_conf('proxies') if 'no_proxy' in os.environ: os.environ.pop('no_proxy') From b383b451914c46042727d7602308317cce1b3a97 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 22:44:18 +0800 Subject: [PATCH 3/6] version 3.54 beta --- version | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version b/version index 5562088..a0f58c8 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { - "version": 3.53, + "version": 3.54, "show_feature": true, - "new_feature": "支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" + "new_feature": "增加文本回答复制按钮 <-> 细分代理场合 <-> 支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" } From dc5bb9741ac8d590aac8593eee3729c3393873b2 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 22:45:07 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index a0f58c8..3bb18a4 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { "version": 3.54, "show_feature": true, - "new_feature": "增加文本回答复制按钮 <-> 细分代理场合 <-> 支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" + "new_feature": "新增动态代码解释器(CodeInterpreter) <-> 增加文本回答复制按钮 <-> 细分代理场合 <-> 支持动态选择不同界面主题 <-> 提高稳定性&解决多用户冲突问题 <-> 支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" } From e24f077b68e38b679e5ca25853ea2c402f074ea3 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 23:06:58 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=98=BE=E5=BC=8F=E5=A2=9E=E5=8A=A0azure-g?= =?UTF-8?q?pt-4=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- request_llm/bridge_all.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index a3bb74c..88e0df2 100644 --- a/config.py +++ b/config.py @@ -80,7 +80,7 @@ DEFAULT_FN_GROUPS = ['对话', '编程', '学术', '智能体'] # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓ AVAIL_LLM_MODELS = ["gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5", "api2d-gpt-3.5-turbo", - "gpt-4", "gpt-4-32k", "api2d-gpt-4", "chatglm", "moss", "newbing", "stack-claude"] + "gpt-4", "gpt-4-32k", "azure-gpt-4", "api2d-gpt-4", "chatglm", "moss", "newbing", "stack-claude"] # P.S. 其他可用的模型还包括 ["qianfan", "llama2", "qwen", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", # "spark", "sparkv2", "chatglm_onnx", "claude-1-100k", "claude-2", "internlm", "jittorllms_pangualpha", "jittorllms_llama"] diff --git a/request_llm/bridge_all.py b/request_llm/bridge_all.py index 15ce7b4..44e0ae4 100644 --- a/request_llm/bridge_all.py +++ b/request_llm/bridge_all.py @@ -145,6 +145,15 @@ model_info = { "token_cnt": get_token_num_gpt35, }, + "azure-gpt-4":{ + "fn_with_ui": chatgpt_ui, + "fn_without_ui": chatgpt_noui, + "endpoint": azure_endpoint, + "max_token": 8192, + "tokenizer": tokenizer_gpt35, + "token_cnt": get_token_num_gpt35, + }, + # api_2d "api2d-gpt-3.5-turbo": { "fn_with_ui": chatgpt_ui, From d6eaaad9621ff8d61b2ad9ba385b6f59ea73157f Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 23 Sep 2023 23:23:23 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=A6=81=E6=AD=A2gradio=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=AF=AF=E5=AF=BC=E6=80=A7=E7=9A=84share=3DTrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index c848a16..f50cdb0 100644 --- a/main.py +++ b/main.py @@ -285,6 +285,7 @@ def main(): auto_opentab_delay() demo.queue(concurrency_count=CONCURRENT_COUNT).launch( + quiet=True, server_name="0.0.0.0", server_port=PORT, favicon_path="docs/logo.png",