From 11c641748f12196b5b95b0f049e97eaecfcd1025 Mon Sep 17 00:00:00 2001 From: Shengjiang Quan Date: Wed, 29 Mar 2023 22:36:15 +0900 Subject: [PATCH 01/30] readme: update Re-format a part of the markdown content and add conda instruction for installation. Signed-off-by: Shengjiang Quan --- README.md | 77 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d894348..dacf645 100644 --- a/README.md +++ b/README.md @@ -71,33 +71,66 @@ chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报 -## 直接运行 (Windows or Linux or MacOS) +## 直接运行 (Windows, Linux or MacOS) -``` sh -# 下载项目 +下载项目 + +```sh git clone https://github.com/binary-husky/chatgpt_academic.git cd chatgpt_academic -# 在config.py中,配置 海外Proxy 和 OpenAI API KEY -- 1.如果你在国内,需要设置海外代理才能够使用 OpenAI API,你可以通过 config.py 文件来进行设置。 -- 2.配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 -# 安装依赖 -python -m pip install -r requirements.txt -# 运行 -python main.py - -# 测试实验性功能 -## 测试C++项目头文件分析 -input区域 输入 ./crazy_functions/test_project/cpp/libJPG , 然后点击 "[实验] 解析整个C++项目(input输入项目根路径)" -## 测试给Latex项目写摘要 -input区域 输入 ./crazy_functions/test_project/latex/attention , 然后点击 "[实验] 读tex论文写摘要(input输入项目根路径)" -## 测试Python项目分析 -input区域 输入 ./crazy_functions/test_project/python/dqn , 然后点击 "[实验] 解析整个py项目(input输入项目根路径)" -## 测试自我代码解读 -点击 "[实验] 请解析并解构此项目本身" -## 测试实验功能模板函数(要求gpt回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能 -点击 "[实验] 实验功能函数模板" ``` +我们建议将`config.py`复制为`config_private.py`并将后者用作个性化配置文件以避免`config.py`中的变更影响你的使用或不小心将包含你的OpenAI API KEY的`config.py`提交至本项目。 + +```sh +cp config.py config_private.py +``` + +在`config_private.py`中,配置 海外Proxy 和 OpenAI API KEY + +1. 如果你在国内,需要设置海外代理才能够使用 OpenAI API,你可以通过 config.py 文件来进行设置。 +2. 配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 + +安装依赖 + +```sh +python -m pip install -r requirements.txt +``` + +或者,如果你希望使用`conda` + +```sh +conda create -n gptac 'gradio>=3.23' requests +conda activate gptac +python3 -m pip install mdtex2html +``` + +运行 + +```sh +python main.py +``` + +测试实验性功能 + +- 测试C++项目头文件分析 + + input区域 输入 `./crazy_functions/test_project/cpp/libJPG` , 然后点击 "[实验] 解析整个C++项目(input输入项目根路径)" + +- 测试给Latex项目写摘要 + + input区域 输入 `./crazy_functions/test_project/latex/attention` , 然后点击 "[实验] 读tex论文写摘要(input输入项目根路径)" + +- 测试Python项目分析 + + input区域 输入 `./crazy_functions/test_project/python/dqn` , 然后点击 "[实验] 解析整个py项目(input输入项目根路径)" + +- 测试自我代码解读 + + 点击 "[实验] 请解析并解构此项目本身" +- 测试实验功能模板函数(要求gpt回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能 + + 点击 "[实验] 实验功能函数模板" ## 使用docker (Linux) From ad75886941ff27f1cb08d6d92ee5d6fc013a7baf Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Wed, 29 Mar 2023 23:44:01 +0800 Subject: [PATCH 02/30] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index dacf645..fcac57d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ https://github.com/polarwinkel/mdtex2html 项目使用OpenAI的gpt-3.5-turbo模型,期待gpt-4早点放宽门槛😂 ``` +> **Note** +> 请注意只有“红颜色”标识的插件函数才支持文件/文件路径作为输入参数。目前暂不支持直接读取word和pdf(相关函数插件效果尚不理想)。 +
功能 | 描述 From e4b352394744d8b7624db55ea08de181307531b0 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Wed, 29 Mar 2023 23:44:37 +0800 Subject: [PATCH 03/30] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fcac57d..2b5dac9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +> **Note** +> 请注意只有“红颜色”标识的函数插件才支持文件/文件路径作为输入参数。目前暂不支持直接读取word和pdf(相关函数插件效果尚不理想)。 + + # ChatGPT 学术优化 **如果喜欢这个项目,请给它一个Star;如果你发明了更好用的学术快捷键,欢迎发issue或者pull requests** @@ -16,9 +20,6 @@ https://github.com/polarwinkel/mdtex2html 项目使用OpenAI的gpt-3.5-turbo模型,期待gpt-4早点放宽门槛😂 ``` -> **Note** -> 请注意只有“红颜色”标识的插件函数才支持文件/文件路径作为输入参数。目前暂不支持直接读取word和pdf(相关函数插件效果尚不理想)。 -
功能 | 描述 From d6e4fc27ada63eaaf7a731d116012d316db2c806 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Wed, 29 Mar 2023 23:48:58 +0800 Subject: [PATCH 04/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b5dac9..2a90feb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ > **Note** -> 请注意只有“红颜色”标识的函数插件才支持文件/文件路径作为输入参数。目前暂不支持直接读取word和pdf(相关函数插件效果尚不理想)。 +> 请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf和word格式文献的翻译解读。 # ChatGPT 学术优化 From 9598029620935acfc4bb8f7f87ca2f565ce30777 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Wed, 29 Mar 2023 23:50:20 +0800 Subject: [PATCH 05/30] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a90feb..0990ff4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -> **Note** -> 请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf和word格式文献的翻译解读。 # ChatGPT 学术优化 @@ -20,6 +18,10 @@ https://github.com/polarwinkel/mdtex2html 项目使用OpenAI的gpt-3.5-turbo模型,期待gpt-4早点放宽门槛😂 ``` +> **Note** +> 请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf格式文献的翻译解读,尚不支持word格式文件的读取。 + +
功能 | 描述 From bd4bf71c4b8cc99f332f9c7891cc9e2cd994e79a Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Wed, 29 Mar 2023 23:53:33 +0800 Subject: [PATCH 06/30] Update README.md --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0990ff4..0fe1ab6 100644 --- a/README.md +++ b/README.md @@ -93,10 +93,10 @@ cp config.py config_private.py ``` 在`config_private.py`中,配置 海外Proxy 和 OpenAI API KEY - +``` 1. 如果你在国内,需要设置海外代理才能够使用 OpenAI API,你可以通过 config.py 文件来进行设置。 2. 配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 - +``` 安装依赖 ```sh @@ -118,26 +118,18 @@ python main.py ``` 测试实验性功能 - +``` - 测试C++项目头文件分析 - input区域 输入 `./crazy_functions/test_project/cpp/libJPG` , 然后点击 "[实验] 解析整个C++项目(input输入项目根路径)" - - 测试给Latex项目写摘要 - input区域 输入 `./crazy_functions/test_project/latex/attention` , 然后点击 "[实验] 读tex论文写摘要(input输入项目根路径)" - - 测试Python项目分析 - input区域 输入 `./crazy_functions/test_project/python/dqn` , 然后点击 "[实验] 解析整个py项目(input输入项目根路径)" - - 测试自我代码解读 - 点击 "[实验] 请解析并解构此项目本身" -- 测试实验功能模板函数(要求gpt回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能 - +- 测试实验功能模板函数(要求gpt回答历史上的今天发生了什么),您可以根据此函数为模板,实现更复杂的功能 点击 "[实验] 实验功能函数模板" - +``` ## 使用docker (Linux) ``` sh @@ -154,7 +146,7 @@ docker run --rm -it --net=host gpt-academic # 测试实验性功能 ## 测试自我代码解读 点击 "[实验] 请解析并解构此项目本身" -## 测试实验功能模板函数(要求gpt回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能 +## 测试实验功能模板函数(要求gpt回答历史上的今天发生了什么),您可以根据此函数为模板,实现更复杂的功能 点击 "[实验] 实验功能函数模板" ##(请注意在docker中运行时,需要额外注意程序的文件访问权限问题) ## 测试C++项目头文件分析 From 3c5122b529705f73e7cf743405173e8da6a9387d Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 00:09:58 +0800 Subject: [PATCH 07/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fe1ab6..e5f96ec 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报 - 新界面
- +
From bfdc2dee9a8ab6c1c8ed34cf8da08f6b6c1b0b14 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 30 Mar 2023 00:15:31 +0800 Subject: [PATCH 08/30] change UI layout --- main.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 0537bd7..cde2229 100644 --- a/main.py +++ b/main.py @@ -42,18 +42,17 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo: with gr.Row(): with gr.Column(scale=2): chatbot = gr.Chatbot() - chatbot.style(height=1000) + chatbot.style(height=1150) chatbot.style() history = gr.State([]) with gr.Column(scale=1): with gr.Row(): - with gr.Column(scale=12): - txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False) - with gr.Column(scale=1): - with gr.Row(): - resetBtn = gr.Button("重置", variant="secondary") - stopBtn = gr.Button("停止", variant="secondary") - submitBtn = gr.Button("提交", variant="primary") + txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False) + with gr.Row(): + submitBtn = gr.Button("提交", variant="primary") + with gr.Row(): + resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm") + stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm") with gr.Row(): from check_proxy import check_proxy statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}") @@ -62,7 +61,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo: variant = functional[k]["Color"] if "Color" in functional[k] else "secondary" functional[k]["Button"] = gr.Button(k, variant=variant) with gr.Row(): - gr.Markdown("注意:以下红颜色标识的函数插件需从input区读取路径作为参数.") + gr.Markdown("注意:以下“红颜色”标识的函数插件需从input区读取路径作为参数.") with gr.Row(): for k in crazy_functional: variant = crazy_functional[k]["Color"] if "Color" in crazy_functional[k] else "secondary" From e3d763acff3c7c248f4cefb6d78034f73a237d49 Mon Sep 17 00:00:00 2001 From: Freddd13 Date: Thu, 30 Mar 2023 01:47:39 +0800 Subject: [PATCH 09/30] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81wsl2=E4=BD=BF?= =?UTF-8?q?=E7=94=A8windows=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index e5f96ec..c513162 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,21 @@ input区域 输入 ./crazy_functions/test_project/python/dqn , 然后点击 "[ ``` +## 使用WSL2(Windows Subsystem for Linux 子系统) +选择这种方式默认您已经具备一定基本知识,因此不再赘述多余步骤。如果不是这样,您可以从[这里](https://learn.microsoft.com/zh-cn/windows/wsl/about)或GPT处获取更多关于子系统的信息。 + +WSL2可以配置使用Windows侧的代理上网,前置步骤可以参考[这里](https://www.cnblogs.com/tuilk/p/16287472.html) +由于Windows相对WSL2的IP会发生变化,我们需要每次启动前先获取这个IP来保证顺利访问,将config.py中设置proxies的部分更改为如下代码: +```python +import subprocess +cmd_get_ip = 'grep -oP "(\d+\.)+(\d+)" /etc/resolv.conf' +ip_proxy = subprocess.run( + cmd_get_ip, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True + ).stdout.strip() # 获取windows的IP +proxies = { "http": ip_proxy + ":51837", "https": ip_proxy + ":51837", } # 请自行修改 +``` +至此测试、使用与上面其他方法无异。 + ## 自定义新的便捷按钮(学术快捷键自定义) 打开functional.py,添加条目如下,然后重启程序即可。(如果按钮已经添加成功并可见,那么前缀、后缀都支持热修改,无需重启程序即可生效。) From 0975b60c725c1ff670dbb85e9c72c81803f6fb77 Mon Sep 17 00:00:00 2001 From: Freddd13 Date: Thu, 30 Mar 2023 01:58:39 +0800 Subject: [PATCH 10/30] Merge remote-tracking branch 'upstream/master' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c513162..1c395df 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ ip_proxy = subprocess.run( ).stdout.strip() # 获取windows的IP proxies = { "http": ip_proxy + ":51837", "https": ip_proxy + ":51837", } # 请自行修改 ``` -至此测试、使用与上面其他方法无异。 +在启动main.py后,可以在windows浏览器中访问服务。至此测试、使用与上面其他方法无异。 ## 自定义新的便捷按钮(学术快捷键自定义) From 0b1f351cbab1cbc2beefd396b034cd8a2b2c6065 Mon Sep 17 00:00:00 2001 From: Freddd13 Date: Thu, 30 Mar 2023 02:00:15 +0800 Subject: [PATCH 11/30] =?UTF-8?q?update:=20=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c395df..7d3dc77 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ ip_proxy = subprocess.run( ).stdout.strip() # 获取windows的IP proxies = { "http": ip_proxy + ":51837", "https": ip_proxy + ":51837", } # 请自行修改 ``` -在启动main.py后,可以在windows浏览器中访问服务。至此测试、使用与上面其他方法无异。 +在启动main.py后,可以在windows浏览器中访问服务。至此测试、使用与上面其他方法无异。 ## 自定义新的便捷按钮(学术快捷键自定义) From 2bf30d8a1e5f9377613006e7721dbaf505c03307 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 11:05:38 +0800 Subject: [PATCH 12/30] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E8=AF=BB=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check_proxy.py | 7 ++++--- main.py | 7 ++++--- predict.py | 8 +++++--- toolbox.py | 24 ++++++++++++++++++------ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/check_proxy.py b/check_proxy.py index 39c8972..a6919dd 100644 --- a/check_proxy.py +++ b/check_proxy.py @@ -21,6 +21,7 @@ def check_proxy(proxies): if __name__ == '__main__': import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 - try: from config_private import proxies # 放自己的秘密如API和代理网址 os.path.exists('config_private.py') - except: from config import proxies - check_proxy(proxies) \ No newline at end of file + from toolbox import get_conf + proxies, = get_conf('proxies') + check_proxy(proxies) + \ No newline at end of file diff --git a/main.py b/main.py index cde2229..4217304 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,12 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 import gradio as gr from predict import predict -from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated +from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 -try: from config_private import proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION -except: from config import proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION +proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = \ + get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION') + # 如果WEB_PORT是-1, 则随机选取WEB端口 PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT diff --git a/predict.py b/predict.py index 55a25e6..712cbd8 100644 --- a/predict.py +++ b/predict.py @@ -20,10 +20,12 @@ import importlib # config_private.py放自己的秘密如API和代理网址 # 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件 -try: from config_private import proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL -except: from config import proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL +from toolbox import get_conf +proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \ + get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL') -timeout_bot_msg = '[local] Request timeout, network error. please check proxy settings in config.py.' +timeout_bot_msg = '[Local Message] Request timeout. Network error. Please check proxy settings in config.py.' + \ + '网络错误,检查代理服务器是否可用,以及代理设置的格式是否正确,格式须是[协议]://[地址]:[端口],缺一不可。' def get_full_error(chunk, stream_response): """ diff --git a/toolbox.py b/toolbox.py index f0ec566..be7e7ca 100644 --- a/toolbox.py +++ b/toolbox.py @@ -1,4 +1,4 @@ -import markdown, mdtex2html, threading +import markdown, mdtex2html, threading, importlib, traceback from show_math import convert as convert_math from functools import wraps @@ -7,9 +7,9 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp 调用简单的predict_no_ui接口,但是依然保留了些许界面心跳功能,当对话太长时,会自动采用二分法截断 """ import time - try: from config_private import TIMEOUT_SECONDS, MAX_RETRY - except: from config import TIMEOUT_SECONDS, MAX_RETRY from predict import predict_no_ui + from toolbox import get_conf + TIMEOUT_SECONDS, MAX_RETRY = get_conf('TIMEOUT_SECONDS', 'MAX_RETRY') # 多线程的时候,需要一个mutable结构在不同线程之间传递信息 # list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息 mutable = [None, ''] @@ -80,10 +80,9 @@ def CatchException(f): try: yield from f(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT) except Exception as e: - import traceback from check_proxy import check_proxy - try: from config_private import proxies - except: from config import proxies + from toolbox import get_conf + proxies, = get_conf('proxies') tb_str = regular_txt_to_markdown(traceback.format_exc()) chatbot[-1] = (chatbot[-1][0], f"[Local Message] 实验性函数调用出错: \n\n {tb_str} \n\n 当前代理可用性: \n\n {check_proxy(proxies)}") yield chatbot, history, f'异常 {e}' @@ -218,3 +217,16 @@ def on_report_generated(files, chatbot): # files.extend(report_files) chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧文件上传区,请查收。']) return report_files, chatbot + +def get_conf(*args): + # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 + res = [] + for arg in args: + try: r = getattr(importlib.import_module('config_private'), arg) + except: r = getattr(importlib.import_module('config'), arg) + res.append(r) + # 在读取API_KEY时,检查一下是不是忘了改config + if arg=='API_KEY' and len(r) != 51: + assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ + "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" + return res From 6dd83fb1b4658230b4cc19bcf1a4d043b50adc59 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 11:50:11 +0800 Subject: [PATCH 13/30] =?UTF-8?q?=E6=A0=87=E5=87=86=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functional.py | 61 ++++++++++++++++++++++----------------------------- toolbox.py | 4 ++-- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/functional.py b/functional.py index e416063..d38ccdf 100644 --- a/functional.py +++ b/functional.py @@ -6,54 +6,45 @@ def get_functionals(): return { "英语学术润色": { - "Prefix": "Below is a paragraph from an academic paper. Polish the writing to meet the academic style, \ -improve the spelling, grammar, clarity, concision and overall readability. When neccessary, rewrite the whole sentence. \ -Furthermore, list all modification and explain the reasons to do so in markdown table.\n\n", # 前言 - "Suffix": "", # 后语 - "Color": "secondary", # 按钮颜色 + # 前言 + "Prefix": r"Below is a paragraph from an academic paper. Polish the writing to meet the academic style, " + + r"improve the spelling, grammar, clarity, concision and overall readability. When neccessary, rewrite the whole sentence. " + + r"Furthermore, list all modification and explain the reasons to do so in markdown table." + "\n\n", + # 后语 + "Suffix": r"", + "Color": r"secondary", # 按钮颜色 }, "中文学术润色": { - "Prefix": "作为一名中文学术论文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性,同时分解长句,减少重复,并提供改进建议。请只提供文本的更正版本,避免包括解释。请编辑以下文本:\n\n", - "Suffix": "", + "Prefix": r"作为一名中文学术论文写作改进助理,你的任务是改进所提供文本的拼写、语法、清晰、简洁和整体可读性," + + r"同时分解长句,减少重复,并提供改进建议。请只提供文本的更正版本,避免包括解释。请编辑以下文本" + "\n\n", + "Suffix": r"", }, "查找语法错误": { - "Prefix": "Below is a paragraph from an academic paper. Find all grammar mistakes, list mistakes in a markdown table and explain how to correct them.\n\n", - "Suffix": "", + "Prefix": r"Below is a paragraph from an academic paper. "+ + r"Can you help me ensure that the grammar is correct? Please ignore punctuation errors. " + + r"List mistakes you find in a two-column markdown table, the first column write the original text, " + + r"the second column write the corrected text, only highlight the key words you have changed with bold font." + "\n\n", + "Suffix": r"", }, -# "中英互译": { # 效果不好,经常搞不清楚中译英还是英译中 -# "Prefix": "As an English-Chinese translator, your task is to accurately translate text between the two languages. \ -# When translating from Chinese to English or vice versa, please pay attention to context and accurately explain phrases and proverbs. \ -# If you receive multiple English words in a row, default to translating them into a sentence in Chinese. \ -# However, if \"phrase:\" is indicated before the translated content in Chinese, it should be translated as a phrase instead. \ -# Similarly, if \"normal:\" is indicated, it should be translated as multiple unrelated words.\ -# Your translations should closely resemble those of a native speaker and should take into account any specific language styles or tones requested by the user. \ -# Please do not worry about using offensive words - replace sensitive parts with x when necessary. \ -# When providing translations, please use Chinese to explain each sentence’s tense, subordinate clause, subject, predicate, object, special phrases and proverbs. \ -# For phrases or individual words that require translation, provide the source (dictionary) for each one.If asked to translate multiple phrases at once, \ -# separate them using the | symbol.Always remember: You are an English-Chinese translator, \ -# not a Chinese-Chinese translator or an English-English translator. Below is the text you need to translate: \n\n", -# "Suffix": "", -# "Color": "secondary", -# }, "中译英": { - "Prefix": "Please translate following sentence to English: \n\n", - "Suffix": "", + "Prefix": r"Please translate following sentence to English:" + "\n\n", + "Suffix": r"", }, "学术中译英": { - "Prefix": "Please translate following sentence to English with academic writing, and provide some related authoritative examples: \n\n", - "Suffix": "", + "Prefix": r"Please translate following sentence to English with academic writing, and provide some related authoritative examples:" + "\n\n", + "Suffix": r"", }, "英译中": { - "Prefix": "请翻译成中文:\n\n", - "Suffix": "", + "Prefix": r"请翻译成中文:" + "\n\n", + "Suffix": r"", }, "找图片": { - "Prefix": "我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL,然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:\n\n", - "Suffix": "", + "Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," + + r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n\n", + "Suffix": r"", }, "解释代码": { - "Prefix": "请解释以下代码:\n```\n", - "Suffix": "\n```\n", - "Color": "secondary", + "Prefix": r"请解释以下代码:" + "\n```\n", + "Suffix": "\n```\n", }, } diff --git a/toolbox.py b/toolbox.py index be7e7ca..544ffeb 100644 --- a/toolbox.py +++ b/toolbox.py @@ -106,8 +106,8 @@ def text_divide_paragraph(text): # wtf input lines = text.split("\n") for i, line in enumerate(lines): - lines[i] = "

"+lines[i].replace(" ", " ")+"

" - text = "\n".join(lines) + lines[i] = lines[i].replace(" ", " ") + text = "
".join(lines) return text def markdown_convertion(txt): From 82742f3ea5c6a1bca5336dfb8963142e878b7673 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 11:51:55 +0800 Subject: [PATCH 14/30] up --- config.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config.py b/config.py index 644bd4d..a513f44 100644 --- a/config.py +++ b/config.py @@ -36,8 +36,3 @@ CONCURRENT_COUNT = 100 # 设置用户名和密码 AUTHENTICATION = [] # [("username", "password"), ("username2", "password2"), ...] - -# 检查一下是不是忘了改config -if len(API_KEY) != 51: - assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ - "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" From 4d02ea986319c08e82cec68963fb8060a15da09e Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 12:16:18 +0800 Subject: [PATCH 15/30] =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=9F=A5=E6=89=BEprompt=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functional.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/functional.py b/functional.py index d38ccdf..d25e243 100644 --- a/functional.py +++ b/functional.py @@ -20,10 +20,12 @@ def get_functionals(): "Suffix": r"", }, "查找语法错误": { - "Prefix": r"Below is a paragraph from an academic paper. "+ - r"Can you help me ensure that the grammar is correct? Please ignore punctuation errors. " + - r"List mistakes you find in a two-column markdown table, the first column write the original text, " + - r"the second column write the corrected text, only highlight the key words you have changed with bold font." + "\n\n", + "Prefix": r"Below is a paragraph from an academic paper. " + + r"Can you help me ensure that the grammar and the spelling is correct? " + + r"If no mistake is found, tell me that this paragraph is good." + + r"If you find grammar mistakes,please list mistakes you find in a two-column markdown table, " + + r"put the original text the first column, " + + r"put the corrected text in the second column and highlight the key words you fixed." + "\n\n", "Suffix": r"", }, "中译英": { From 44155bcc24e83cb54e7f1482af21b6818d1a3f42 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 12:52:28 +0800 Subject: [PATCH 16/30] =?UTF-8?q?=E6=9F=A5=E6=89=BE=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=B9=8B=E5=89=8D=E5=85=88=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functional.py | 6 ++++-- predict.py | 3 ++- toolbox.py | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/functional.py b/functional.py index d25e243..2ed1507 100644 --- a/functional.py +++ b/functional.py @@ -2,6 +2,7 @@ # 'secondary' 颜色对应 theme.py 中的 neutral_hue # 'stop' 颜色对应 theme.py 中的 color_er # 默认按钮颜色是 secondary +from toolbox import clear_line_break def get_functionals(): return { @@ -22,11 +23,12 @@ def get_functionals(): "查找语法错误": { "Prefix": r"Below is a paragraph from an academic paper. " + r"Can you help me ensure that the grammar and the spelling is correct? " + - r"If no mistake is found, tell me that this paragraph is good." + - r"If you find grammar mistakes,please list mistakes you find in a two-column markdown table, " + + r"Do not try to polish the text, if no mistake is found, tell me that this paragraph is good." + + r"If you find grammar or spelling mistakes, please list mistakes you find in a two-column markdown table, " + r"put the original text the first column, " + r"put the corrected text in the second column and highlight the key words you fixed." + "\n\n", "Suffix": r"", + "PreProcess": clear_line_break, # 预处理:清除换行符 }, "中译英": { "Prefix": r"Please translate following sentence to English:" + "\n\n", diff --git a/predict.py b/predict.py index 712cbd8..84036bc 100644 --- a/predict.py +++ b/predict.py @@ -119,8 +119,9 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt='' """ if additional_fn is not None: import functional - importlib.reload(functional) + importlib.reload(functional) # 热更新prompt functional = functional.get_functionals() + if "PreProcess" in functional[additional_fn]: inputs = functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话) inputs = functional[additional_fn]["Prefix"] + inputs + functional[additional_fn]["Suffix"] if stream: diff --git a/toolbox.py b/toolbox.py index 544ffeb..d96b3f6 100644 --- a/toolbox.py +++ b/toolbox.py @@ -230,3 +230,9 @@ def get_conf(*args): assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" return res + +def clear_line_break(txt): + txt = txt.replace('\n', ' ') + txt = txt.replace(' ', ' ') + txt = txt.replace(' ', ' ') + return txt \ No newline at end of file From 06a04f14d89b87120c54666300ee07abaaa9cd3a Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 13:24:30 +0800 Subject: [PATCH 17/30] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d3dc77..90efbed 100644 --- a/README.md +++ b/README.md @@ -212,11 +212,12 @@ python check_proxy.py ## 兼容性测试 ### 图片显示: +
- - +
+ ### 如果一个程序能够读懂并剖析自己:
From 1f7f71c6b9a166acb912bc4333f6a5086758e51e Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:08:24 +0800 Subject: [PATCH 18/30] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 90efbed..f409e34 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,9 @@ python main.py - 测试实验功能模板函数(要求gpt回答历史上的今天发生了什么),您可以根据此函数为模板,实现更复杂的功能 点击 "[实验] 实验功能函数模板" ``` + +与代理网络有关的issue(网络超时、代理不起作用)汇总到 https://github.com/binary-husky/chatgpt_academic/issues/1 + ## 使用docker (Linux) ``` sh From 35847e4ec44f710a3646f992ac6f2ed8c8156944 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:47:19 +0800 Subject: [PATCH 19/30] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f409e34..9dbc2c1 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,12 @@ https://github.com/polarwinkel/mdtex2html ``` > **Note** -> 请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf格式文献的翻译解读,尚不支持word格式文件的读取。 - +> +> 1.请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf格式文献的翻译解读,尚不支持word格式文件的读取。 +> +> 2.本项目中每个文件的功能都在`project_self_analysis.md`详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件重新生成项目的自我解析报告。 +> +> 3.如果您不太习惯部分中文命名的函数,您可以随时点击相关函数插件,一键生成纯英文的项目源代码。
From 81b011873097ce02c2f0a34151a4006e04218fc0 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:48:20 +0800 Subject: [PATCH 20/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9dbc2c1..e5b9374 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ https://github.com/polarwinkel/mdtex2html > > 1.请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf格式文献的翻译解读,尚不支持word格式文件的读取。 > -> 2.本项目中每个文件的功能都在`project_self_analysis.md`详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件重新生成项目的自我解析报告。 +> 2.本项目中每个文件的功能都在`project_self_analysis.md`详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件,调用GPT重新生成项目的自我解析报告。 > -> 3.如果您不太习惯部分中文命名的函数,您可以随时点击相关函数插件,一键生成纯英文的项目源代码。 +> 3.如果您不太习惯部分中文命名的函数,您可以随时点击相关函数插件,调用GPT一键生成纯英文的项目源代码。
From 16ce033d86cee20a702f828ce165722eaa578da5 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:48:46 +0800 Subject: [PATCH 21/30] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e5b9374..a281e4f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报 公式显示 | 可以同时显示公式的tex形式和渲染形式 图片显示 | 可以在markdown中显示图片 支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格 +…… | ……
From 743d18cd98aae98772502ed01f5513ede3a64534 Mon Sep 17 00:00:00 2001 From: Sad Pencil Date: Thu, 30 Mar 2023 15:55:46 +0800 Subject: [PATCH 22/30] Fix a typo --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index a513f44..7fc73db 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,5 @@ # API_KEY = "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" 此key无效 -API_KEY = "sk-此处填API秘钥" +API_KEY = "sk-此处填API密钥" API_URL = "https://api.openai.com/v1/chat/completions" # 改为True应用代理 From fda48fd37d35b451a11faefbf3089a86e02c5b18 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 23:09:45 +0800 Subject: [PATCH 23/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Wiki=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a281e4f..92270d1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ https://github.com/polarwinkel/mdtex2html > > 1.请注意只有“红颜色”标识的函数插件(按钮)才支持读取文件。目前暂不能完善地支持pdf格式文献的翻译解读,尚不支持word格式文件的读取。 > -> 2.本项目中每个文件的功能都在`project_self_analysis.md`详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件,调用GPT重新生成项目的自我解析报告。 +> 2.本项目中每个文件的功能都在自译解[`project_self_analysis.md`](https://github.com/binary-husky/chatgpt_academic/wiki/chatgpt-academic%E9%A1%B9%E7%9B%AE%E8%87%AA%E8%AF%91%E8%A7%A3%E6%8A%A5%E5%91%8A)详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件,调用GPT重新生成项目的自我解析报告。常见问题汇总在[`wiki`](https://github.com/binary-husky/chatgpt_academic/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)当中。 > > 3.如果您不太习惯部分中文命名的函数,您可以随时点击相关函数插件,调用GPT一键生成纯英文的项目源代码。 From 9564a5e113f4a3090efa12fbf37e3e843b434968 Mon Sep 17 00:00:00 2001 From: RoderickChan Date: Thu, 30 Mar 2023 23:28:08 +0800 Subject: [PATCH 24/30] =?UTF-8?q?=E5=9C=A8README=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=9C=E7=A8=8B=E9=83=A8=E7=BD=B2=E7=9A=84=E6=8C=87?= =?UTF-8?q?=E5=AF=BC=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/README.md b/README.md index 92270d1..ec97898 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,66 @@ proxies = { "http": ip_proxy + ":51837", "https": ip_proxy + ":51837", } # 请 ``` 在启动main.py后,可以在windows浏览器中访问服务。至此测试、使用与上面其他方法无异。 +## 远程部署 +如果您需要将本项目部署到公网服务器,请设置好`PORT`(固定端口)和`AUTHENTICATION`(避免您的`APIKEY`被滥用),并将`main.py`的最后一句话修改为: +```python +demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=False, server_port=PORT, auth=AUTHENTICATION) # 取消share +``` + +如果您打算使用域名,强烈建议用`nginx`配置反向代理。需要往配置文件增加的内容如下: +```nginx +http { + # 其他配置 + #...... + # 配置websocket + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } +upstream my_chataca { + # 这里配置负载均衡策略 + ip_hash; # 如果使用负载均衡,建议使用ip_hash + # 假设本项目运行的端口为8080 + server 127.0.0.1:8080 max_fails=3 fail_timeout=10; +} + +server { + listen 80; + listen [::]:80; + server_name yourdomain.com; + return 301 https://yourdomain.com$request_uri;# 强制使用https +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name yourdomain.com; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers on; + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; + ssl_session_tickets off; + ssl_session_timeout 1d; + ssl_session_cache shared:SSL:10m; + add_header Strict-Transport-Security + "max-age=31536000; includeSubDomains" + always; + ssl_certificate xxxxxx.pem; # 证书文件 + ssl_certificate_key xxxxxx.key; # 证书文件 + + location / { + proxy_pass http://my_chataca; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + } +} + +} +``` + ## 自定义新的便捷按钮(学术快捷键自定义) 打开functional.py,添加条目如下,然后重启程序即可。(如果按钮已经添加成功并可见,那么前缀、后缀都支持热修改,无需重启程序即可生效。) From a3d179c2fa2d700564995d9db5f3bac00bf707d4 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 23:34:17 +0800 Subject: [PATCH 25/30] Update README.md --- README.md | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 92270d1..4610f78 100644 --- a/README.md +++ b/README.md @@ -84,45 +84,42 @@ chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报 ## 直接运行 (Windows, Linux or MacOS) -下载项目 - +### 1. 下载项目 ```sh git clone https://github.com/binary-husky/chatgpt_academic.git cd chatgpt_academic ``` +### 2. 配置API_KEY和代理设置 我们建议将`config.py`复制为`config_private.py`并将后者用作个性化配置文件以避免`config.py`中的变更影响你的使用或不小心将包含你的OpenAI API KEY的`config.py`提交至本项目。 -```sh -cp config.py config_private.py +在`config.py`或`config_private.py`中,配置 海外Proxy 和 OpenAI API KEY,说明如下 ``` - -在`config_private.py`中,配置 海外Proxy 和 OpenAI API KEY -``` -1. 如果你在国内,需要设置海外代理才能够使用 OpenAI API,你可以通过 config.py 文件来进行设置。 +1. 如果你在国内,需要设置海外代理才能够顺利使用 OpenAI API,设置方法请仔细阅读config.py。 2. 配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 +3. 与代理网络有关的issue(网络超时、代理不起作用)汇总到 https://github.com/binary-husky/chatgpt_academic/issues/1 ``` -安装依赖 +### 3. 安装依赖 ```sh -python -m pip install -r requirements.txt +# (选择一)推荐 +python -m pip install -r requirements.txt + +# (选择二)如果您使用anaconda,步骤也是类似的: +# (选择二.1)conda create -n gptac_venv python=3.11 +# (选择二.2)conda activate gptac_venv +# (选择二.3)python -m pip install -r requirements.txt + +# 备注:使用官方pip源或者阿里pip源,其他pip源(如清华pip)有可能出问题,临时换源方法: +# python -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ ``` -或者,如果你希望使用`conda` - -```sh -conda create -n gptac 'gradio>=3.23' requests -conda activate gptac -python3 -m pip install mdtex2html -``` - -运行 - +### 4. 运行 ```sh python main.py ``` -测试实验性功能 +### 5. 测试实验性功能 ``` - 测试C++项目头文件分析 input区域 输入 `./crazy_functions/test_project/cpp/libJPG` , 然后点击 "[实验] 解析整个C++项目(input输入项目根路径)" @@ -136,8 +133,6 @@ python main.py 点击 "[实验] 实验功能函数模板" ``` -与代理网络有关的issue(网络超时、代理不起作用)汇总到 https://github.com/binary-husky/chatgpt_academic/issues/1 - ## 使用docker (Linux) ``` sh From badf4090c589062397469be268fa2ac5210e5857 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Thu, 30 Mar 2023 23:59:01 +0800 Subject: [PATCH 26/30] Update README.md --- README.md | 78 ++++--------------------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index ec97898..96e807c 100644 --- a/README.md +++ b/README.md @@ -166,80 +166,12 @@ input区域 输入 ./crazy_functions/test_project/python/dqn , 然后点击 "[ ``` -## 使用WSL2(Windows Subsystem for Linux 子系统) -选择这种方式默认您已经具备一定基本知识,因此不再赘述多余步骤。如果不是这样,您可以从[这里](https://learn.microsoft.com/zh-cn/windows/wsl/about)或GPT处获取更多关于子系统的信息。 +## 其他部署方式 +- 使用WSL2(Windows Subsystem for Linux 子系统) +请访问[部署wiki-1](https://github.com/binary-husky/chatgpt_academic/wiki/%E4%BD%BF%E7%94%A8WSL2%EF%BC%88Windows-Subsystem-for-Linux-%E5%AD%90%E7%B3%BB%E7%BB%9F%EF%BC%89%E9%83%A8%E7%BD%B2) -WSL2可以配置使用Windows侧的代理上网,前置步骤可以参考[这里](https://www.cnblogs.com/tuilk/p/16287472.html) -由于Windows相对WSL2的IP会发生变化,我们需要每次启动前先获取这个IP来保证顺利访问,将config.py中设置proxies的部分更改为如下代码: -```python -import subprocess -cmd_get_ip = 'grep -oP "(\d+\.)+(\d+)" /etc/resolv.conf' -ip_proxy = subprocess.run( - cmd_get_ip, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True - ).stdout.strip() # 获取windows的IP -proxies = { "http": ip_proxy + ":51837", "https": ip_proxy + ":51837", } # 请自行修改 -``` -在启动main.py后,可以在windows浏览器中访问服务。至此测试、使用与上面其他方法无异。 - -## 远程部署 -如果您需要将本项目部署到公网服务器,请设置好`PORT`(固定端口)和`AUTHENTICATION`(避免您的`APIKEY`被滥用),并将`main.py`的最后一句话修改为: -```python -demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=False, server_port=PORT, auth=AUTHENTICATION) # 取消share -``` - -如果您打算使用域名,强烈建议用`nginx`配置反向代理。需要往配置文件增加的内容如下: -```nginx -http { - # 其他配置 - #...... - # 配置websocket - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } -upstream my_chataca { - # 这里配置负载均衡策略 - ip_hash; # 如果使用负载均衡,建议使用ip_hash - # 假设本项目运行的端口为8080 - server 127.0.0.1:8080 max_fails=3 fail_timeout=10; -} - -server { - listen 80; - listen [::]:80; - server_name yourdomain.com; - return 301 https://yourdomain.com$request_uri;# 强制使用https -} - -server { - listen 443 ssl http2; - listen [::]:443 ssl http2; - server_name yourdomain.com; - ssl_protocols TLSv1.2 TLSv1.3; - ssl_prefer_server_ciphers on; - ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; - ssl_session_tickets off; - ssl_session_timeout 1d; - ssl_session_cache shared:SSL:10m; - add_header Strict-Transport-Security - "max-age=31536000; includeSubDomains" - always; - ssl_certificate xxxxxx.pem; # 证书文件 - ssl_certificate_key xxxxxx.key; # 证书文件 - - location / { - proxy_pass http://my_chataca; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - } -} - -} -``` +- nginx远程部署 +请访问[部署wiki-2](https://github.com/binary-husky/chatgpt_academic/wiki/%E8%BF%9C%E7%A8%8B%E9%83%A8%E7%BD%B2%E7%9A%84%E6%8C%87%E5%AF%BC) ## 自定义新的便捷按钮(学术快捷键自定义) From dca98d404b58374b9c29b499316bee03308455bc Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:11:10 +0800 Subject: [PATCH 27/30] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aab9735..f9afbd2 100644 --- a/README.md +++ b/README.md @@ -91,14 +91,15 @@ cd chatgpt_academic ``` ### 2. 配置API_KEY和代理设置 -我们建议将`config.py`复制为`config_private.py`并将后者用作个性化配置文件以避免`config.py`中的变更影响你的使用或不小心将包含你的OpenAI API KEY的`config.py`提交至本项目。 -在`config.py`或`config_private.py`中,配置 海外Proxy 和 OpenAI API KEY,说明如下 +在`config.py`中,配置 海外Proxy 和 OpenAI API KEY,说明如下 ``` -1. 如果你在国内,需要设置海外代理才能够顺利使用 OpenAI API,设置方法请仔细阅读config.py。 +1. 如果你在国内,需要设置海外代理才能够顺利使用 OpenAI API,设置方法请仔细阅读config.py(1.修改其中的USE_PROXY为True; 2.按照说明修改其中的proxies)。 2. 配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 3. 与代理网络有关的issue(网络超时、代理不起作用)汇总到 https://github.com/binary-husky/chatgpt_academic/issues/1 ``` +(P.S.我们建议将`config.py`复制为`config_private.py`,并将后者用作个性化配置文件以避免`config.py`中的变更影响你的使用,或不小心将包含你的OpenAI API KEY的`config.py`提交至github上。程序运行时`config_private.py`的读取优先级高于`config.py`。此外,如果出现任何异常的配置读取情况,请直接删除`config_private.py`,回归到只使用`config.py`的状态。) + ### 3. 安装依赖 ```sh From 36890a14bf99b75916472cf21db3333836ec1159 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:29:37 +0800 Subject: [PATCH 28/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f9afbd2..285c10d 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ cd chatgpt_academic 2. 配置 OpenAI API KEY。你需要在 OpenAI 官网上注册并获取 API KEY。一旦你拿到了 API KEY,在 config.py 文件里配置好即可。 3. 与代理网络有关的issue(网络超时、代理不起作用)汇总到 https://github.com/binary-husky/chatgpt_academic/issues/1 ``` -(P.S.我们建议将`config.py`复制为`config_private.py`,并将后者用作个性化配置文件以避免`config.py`中的变更影响你的使用,或不小心将包含你的OpenAI API KEY的`config.py`提交至github上。程序运行时`config_private.py`的读取优先级高于`config.py`。此外,如果出现任何异常的配置读取情况,请直接删除`config_private.py`,回归到只使用`config.py`的状态。) +(P.S. 程序运行时会优先检查是否存在名为`config_private.py`的私密配置文件,并用其中的配置覆盖`config.py`的同名配置。因此,如果您能理解我们的配置读取逻辑,我们强烈建议您在`config.py`旁边创建一个名为`config_private.py`的新配置文件,并把`config.py`中的配置转移(复制)到`config_private.py`中。`config_private.py`不受git管控,可以让您的隐私信息更加安全。) ### 3. 安装依赖 From a88a42799f7c966121e85de9156d0eed4dfb6bfd Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:33:03 +0800 Subject: [PATCH 29/30] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 4217304..c69795a 100644 --- a/main.py +++ b/main.py @@ -101,7 +101,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo: # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数 def auto_opentab_delay(): import threading, webbrowser, time - print(f"URL http://localhost:{PORT}") + print(f"如果浏览器没有自动打开,请复制并转到以下URL: http://localhost:{PORT}") def open(): time.sleep(2) webbrowser.open_new_tab(f'http://localhost:{PORT}') From 0b03c797bc14a6eb26e39ff4493ce5cb4162a02d Mon Sep 17 00:00:00 2001 From: Jia Xinglong Date: Fri, 31 Mar 2023 17:38:39 +0800 Subject: [PATCH 30/30] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20re=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=20match=20=E5=87=BD=E6=95=B0=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=9B=B4=E7=B2=BE=E5=87=86=E7=9A=84=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=92=8C=E7=A1=AE=E8=AE=A4=20API=5FKEY=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/toolbox.py b/toolbox.py index d96b3f6..75dd8bc 100644 --- a/toolbox.py +++ b/toolbox.py @@ -1,6 +1,7 @@ import markdown, mdtex2html, threading, importlib, traceback from show_math import convert as convert_math from functools import wraps +import re def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[], sys_prompt=''): """ @@ -226,9 +227,14 @@ def get_conf(*args): except: r = getattr(importlib.import_module('config'), arg) res.append(r) # 在读取API_KEY时,检查一下是不是忘了改config - if arg=='API_KEY' and len(r) != 51: - assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ - "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" + if arg=='API_KEY': + # 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合 + API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r) + if API_MATCH: + print("您的 API_KEY 是: ", r, "\nAPI_KEY 导入成功") + else: + assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ + "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" return res def clear_line_break(txt):