From 6f18d1716edaf6611ddc01185c202638c466dc9d Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 28 May 2023 21:21:12 +0800 Subject: [PATCH 1/4] Merge branch 'master' into huggingface --- Dockerfile | 8 +++++-- README.md | 8 +++---- crazy_functions/Latex全文润色.py | 4 +--- crazy_functions/Latex全文翻译.py | 2 +- docker-compose.yml | 1 + main.py | 6 +++-- request_llm/bridge_all.py | 29 ++++++++++++----------- request_llm/edge_gpt_free.py | 40 ++++++++++++++++---------------- requirements.txt | 2 +- toolbox.py | 21 ++++++++++++++++- version | 4 ++-- 11 files changed, 75 insertions(+), 50 deletions(-) diff --git a/Dockerfile b/Dockerfile index da5053db..19d988f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,16 @@ RUN echo '[global]' > /etc/pip.conf && \ WORKDIR /gpt -COPY requirements.txt . + +# 装载项目文件 +COPY . . + +# 安装依赖 RUN pip3 install -r requirements.txt -COPY . . # 可选步骤,用于预热模块 RUN python3 -c 'from check_proxy import warm_up_modules; warm_up_modules()' +# 启动 CMD ["python3", "-u", "main.py"] diff --git a/README.md b/README.md index 0f8ef179..264b4b5b 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ title: academic-chatgpt emoji: 😻 colorFrom: blue colorTo: blue -sdk: gradio -sdk_version: 3.28.3 python_version: 3.11 app_file: main.py pinned: false @@ -13,9 +11,9 @@ pinned: false # ChatGPT 学术优化 > **Note** > -> 安装依赖时,请严格选择requirements.txt中**指定的版本**。 +> 5月27日对gradio依赖进行了较大的修复和调整,fork并解决了官方Gradio的一系列bug。但如果27日当天进行了更新,可能会导致代码报错(依赖缺失,卡在loading界面等),请及时更新到**最新版代码**并重新安装pip依赖即可。若给您带来困扰还请谅解。安装依赖时,请严格选择requirements.txt中**指定的版本**: > -> `pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/` +> `pip install -r requirements.txt -i https://pypi.org/simple` > # GPT 学术优化 (GPT Academic) @@ -315,7 +313,7 @@ gpt_academic开发者QQ群-2:610599535 - 已知问题 - 某些浏览器翻译插件干扰此软件前端的运行 - - gradio版本过高或过低,都会导致多种异常 + - 官方Gradio目前有很多兼容性Bug,请务必使用requirement.txt安装Gradio ## 参考与学习 diff --git a/crazy_functions/Latex全文润色.py b/crazy_functions/Latex全文润色.py index 1175e866..8d3f97b5 100644 --- a/crazy_functions/Latex全文润色.py +++ b/crazy_functions/Latex全文润色.py @@ -66,7 +66,7 @@ def 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch with open(fp, 'r', encoding='utf-8', errors='replace') as f: file_content = f.read() # 定义注释的正则表达式 - comment_pattern = r'%.*' + comment_pattern = r'(? bash -c " echo '[gpt-academic] 正在从github拉取最新代码...' && git pull && + pip install -r requirements.txt && echo '[jittorllms] 正在从github拉取最新代码...' && git --git-dir=request_llm/jittorllms/.git --work-tree=request_llm/jittorllms pull --force && python3 -u main.py" diff --git a/main.py b/main.py index 88319d3f..7b974bf8 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 def main(): import gradio as gr + if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "请用 pip install -r requirements.txt 安装依赖" from request_llm.bridge_all import predict from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 @@ -197,7 +198,7 @@ def main(): threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start() auto_opentab_delay() - demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=False, favicon_path="docs/logo.png") + demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=False, favicon_path="docs/logo.png", blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile"]) # 如果需要在二级路径下运行 # CUSTOM_PATH, = get_conf('CUSTOM_PATH') @@ -205,7 +206,8 @@ def main(): # from toolbox import run_gradio_in_subpath # run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH) # else: - # demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png") + # demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png", + # blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile"]) if __name__ == "__main__": main() diff --git a/request_llm/bridge_all.py b/request_llm/bridge_all.py index 5c0c8d53..b6efe21a 100644 --- a/request_llm/bridge_all.py +++ b/request_llm/bridge_all.py @@ -202,19 +202,22 @@ if "stack-claude" in AVAIL_LLM_MODELS: } }) if "newbing-free" in AVAIL_LLM_MODELS: - from .bridge_newbingfree import predict_no_ui_long_connection as newbingfree_noui - from .bridge_newbingfree import predict as newbingfree_ui - # claude - model_info.update({ - "newbing-free": { - "fn_with_ui": newbingfree_ui, - "fn_without_ui": newbingfree_noui, - "endpoint": newbing_endpoint, - "max_token": 4096, - "tokenizer": tokenizer_gpt35, - "token_cnt": get_token_num_gpt35, - } - }) + try: + from .bridge_newbingfree import predict_no_ui_long_connection as newbingfree_noui + from .bridge_newbingfree import predict as newbingfree_ui + # claude + model_info.update({ + "newbing-free": { + "fn_with_ui": newbingfree_ui, + "fn_without_ui": newbingfree_noui, + "endpoint": newbing_endpoint, + "max_token": 4096, + "tokenizer": tokenizer_gpt35, + "token_cnt": get_token_num_gpt35, + } + }) + except: + print(trimmed_format_exc()) def LLM_CATCH_EXCEPTION(f): """ diff --git a/request_llm/edge_gpt_free.py b/request_llm/edge_gpt_free.py index 7e893d40..ef618737 100644 --- a/request_llm/edge_gpt_free.py +++ b/request_llm/edge_gpt_free.py @@ -196,9 +196,9 @@ class _ChatHubRequest: self, prompt: str, conversation_style: CONVERSATION_STYLE_TYPE, - options: list | None = None, - webpage_context: str | None = None, - search_result: bool = False, + options = None, + webpage_context = None, + search_result = False, ) -> None: """ Updates request object @@ -294,9 +294,9 @@ class _Conversation: def __init__( self, - proxy: str | None = None, - async_mode: bool = False, - cookies: list[dict] | None = None, + proxy = None, + async_mode = False, + cookies = None, ) -> None: if async_mode: return @@ -350,8 +350,8 @@ class _Conversation: @staticmethod async def create( - proxy: str | None = None, - cookies: list[dict] | None = None, + proxy = None, + cookies = None, ): self = _Conversation(async_mode=True) self.struct = { @@ -418,11 +418,11 @@ class _ChatHub: def __init__( self, conversation: _Conversation, - proxy: str = None, - cookies: list[dict] | None = None, + proxy = None, + cookies = None, ) -> None: - self.session: aiohttp.ClientSession | None = None - self.wss: aiohttp.ClientWebSocketResponse | None = None + self.session = None + self.wss = None self.request: _ChatHubRequest self.loop: bool self.task: asyncio.Task @@ -441,7 +441,7 @@ class _ChatHub: conversation_style: CONVERSATION_STYLE_TYPE = None, raw: bool = False, options: dict = None, - webpage_context: str | None = None, + webpage_context = None, search_result: bool = False, ) -> Generator[str, None, None]: """ @@ -611,10 +611,10 @@ class Chatbot: def __init__( self, - proxy: str | None = None, - cookies: list[dict] | None = None, + proxy = None, + cookies = None, ) -> None: - self.proxy: str | None = proxy + self.proxy = proxy self.chat_hub: _ChatHub = _ChatHub( _Conversation(self.proxy, cookies=cookies), proxy=self.proxy, @@ -623,8 +623,8 @@ class Chatbot: @staticmethod async def create( - proxy: str | None = None, - cookies: list[dict] | None = None, + proxy = None, + cookies = None, ): self = Chatbot.__new__(Chatbot) self.proxy = proxy @@ -641,7 +641,7 @@ class Chatbot: wss_link: str = "wss://sydney.bing.com/sydney/ChatHub", conversation_style: CONVERSATION_STYLE_TYPE = None, options: dict = None, - webpage_context: str | None = None, + webpage_context = None, search_result: bool = False, ) -> dict: """ @@ -667,7 +667,7 @@ class Chatbot: conversation_style: CONVERSATION_STYLE_TYPE = None, raw: bool = False, options: dict = None, - webpage_context: str | None = None, + webpage_context = None, search_result: bool = False, ) -> Generator[str, None, None]: """ diff --git a/requirements.txt b/requirements.txt index 2aedd6e0..5bed41a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -gradio==3.28.3 +gradio-stable-fork tiktoken>=0.3.3 requests[socks] transformers diff --git a/toolbox.py b/toolbox.py index 23bbbfb5..10e5a875 100644 --- a/toolbox.py +++ b/toolbox.py @@ -764,4 +764,23 @@ def zip_folder(source_folder, dest_folder, zip_name): def gen_time_str(): import time - return time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) \ No newline at end of file + return time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + + +class ProxyNetworkActivate(): + """ + 这段代码定义了一个名为TempProxy的空上下文管理器, 用于给一小段代码上代理 + """ + def __enter__(self): + from toolbox import get_conf + proxies, = get_conf('proxies') + if 'no_proxy' in os.environ: os.environ.pop('no_proxy') + os.environ['HTTP_PROXY'] = proxies['http'] + os.environ['HTTPS_PROXY'] = proxies['https'] + return self + + def __exit__(self, exc_type, exc_value, traceback): + os.environ['no_proxy'] = '*' + if 'HTTP_PROXY' in os.environ: os.environ.pop('HTTP_PROXY') + if 'HTTPS_PROXY' in os.environ: os.environ.pop('HTTPS_PROXY') + return \ No newline at end of file diff --git a/version b/version index b1c83676..ad75b2c4 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { - "version": 3.36, + "version": 3.37, "show_feature": true, - "new_feature": "修复PDF翻译的BUG, 新增HTML中英双栏对照 <-> 添加了OpenAI图片生成插件 <-> 添加了OpenAI音频转文本总结插件 <-> 通过Slack添加对Claude的支持 <-> 提供复旦MOSS模型适配(启用需额外依赖) <-> 提供docker-compose方案兼容LLAMA盘古RWKV等模型的后端 <-> 新增Live2D装饰 <-> 完善对话历史的保存/载入/删除 <-> 保存对话功能" + "new_feature": "修复gradio复制按钮BUG <-> 修复PDF翻译的BUG, 新增HTML中英双栏对照 <-> 添加了OpenAI图片生成插件 <-> 添加了OpenAI音频转文本总结插件 <-> 通过Slack添加对Claude的支持 <-> 提供复旦MOSS模型适配(启用需额外依赖) <-> 提供docker-compose方案兼容LLAMA盘古RWKV等模型的后端 <-> 新增Live2D装饰 <-> 完善对话历史的保存/载入/删除 <-> 保存对话功能" } From 5be6b837623da3878332765efad3131fe3150a49 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 28 May 2023 21:24:02 +0800 Subject: [PATCH 2/4] try2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 264b4b5b..524e8675 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ --- -title: academic-chatgpt +title: ChatImprovement emoji: 😻 colorFrom: blue colorTo: blue -python_version: 3.11 -app_file: main.py +sdk: gradio-stable-fork +app_file: app.py pinned: false --- From 94318ff0a2aca06f40de8b7070d2bf6fa4c2152b Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 28 May 2023 21:24:46 +0800 Subject: [PATCH 3/4] try3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 524e8675..589b86c8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ title: ChatImprovement emoji: 😻 colorFrom: blue colorTo: blue -sdk: gradio-stable-fork +sdk: gradio app_file: app.py pinned: false --- From 54f55c32f22aca933f75403faf5f4ac410ed9de7 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 28 May 2023 21:25:45 +0800 Subject: [PATCH 4/4] 213 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 589b86c8..f487f69d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ emoji: 😻 colorFrom: blue colorTo: blue sdk: gradio +sdk_version: 3.32.0 app_file: app.py pinned: false ---