PacBio/BioTree_gpt-academic
ChatGPT 学术优化
Note 2023.7.8: Gradio, Pydantic依赖调整,已修改requirements.txt。请及时更新代码,安装依赖时,请严格选择requirements.txt中指定的版本pip install -r requirements.txt
<div align=center><img src="docs/logo.png" width="40"> GPT 学术优化 (GPT Academic)</div>
如果喜欢这个项目,请给它一个Star;如果您发明了好用的快捷键或函数插件,欢迎发pull requests!
If you like this project, please give it a Star. If you've come up with more useful academic shortcuts or functional plugins, feel free to open an issue or pull request. We also have a README in English|日本語|한국어|Русский|Français translated by this project itself. To translate this project to arbitary language with GPT, read and run `multi_language.py` (experimental).
Note 1.请注意只有 高亮(如红色) 标识的函数插件(按钮)才支持读取文件,部分插件位于插件区的下拉菜单中。另外我们以最高优先级欢迎和处理任何新插件的PR。 2.本项目中每个文件的功能都在自译解`self_analysis.md`详细说明。随着版本的迭代,您也可以随时自行点击相关函数插件,调用GPT重新生成项目的自我解析报告。常见问题汇总在`wiki`当中。安装方法。 3.本项目兼容并鼓励尝试国产大语言模型ChatGLM和Moss等等。支持多个api-key共存,可在配置文件中填写如API_KEY="openai-key1,openai-key2,azure-key3,api2d-key4"。需要临时更换API_KEY时,在输入区输入临时的API_KEY然后回车键提交后即可生效。
<div align="center">
</div>
- 新界面(修改
config.py中的LAYOUT选项即可实现“左右布局”和“上下布局”的切换) <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/230361456-61078362-a966-4eb5-b49e-3c62ef18b860.gif" width="700" > </div>
- 所有按钮都通过读取functional.py动态生成,可随意加自定义功能,解放粘贴板 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/231975334-b4788e91-4887-412f-8b43-2b9c5f41d248.gif" width="700" > </div>
- 润色/纠错 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/231980294-f374bdcb-3309-4560-b424-38ef39f04ebd.gif" width="700" > </div>
- 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/230598842-1d7fcddd-815d-40ee-af60-baf488a199df.png" width="700" > </div>
- 懒得看项目代码?整个工程直接给chatgpt炫嘴里 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" > </div>
- 多种大语言模型混合调用(ChatGLM + OpenAI-GPT3.5 + API2D-GPT4) <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/232537274-deca0563-7aa6-4b5d-94a2-b7c453c47794.png" width="700" > </div>
Installation
安装方法I:直接运行 (Windows, Linux or MacOS)
- 下载项目
git clone --depth=1 https://github.com/binary-husky/gpt_academic.git
cd gpt_academic- 配置API_KEY
在config.py中,配置API KEY等设置,点击查看特殊网络环境设置方法 。
(P.S. 程序运行时会优先检查是否存在名为config_private.py的私密配置文件,并用其中的配置覆盖config.py的同名配置。因此,如果您能理解我们的配置读取逻辑,我们强烈建议您在config.py旁边创建一个名为config_private.py的新配置文件,并把config.py中的配置转移(复制)到config_private.py中。config_private.py不受git管控,可以让您的隐私信息更加安全。P.S.项目同样支持通过环境变量配置大多数选项,环境变量的书写格式参考docker-compose文件。读取优先级: 环境变量 > config_private.py > config.py)
- 安装依赖
# (选择I: 如熟悉python)(python版本3.9以上,越新越好),备注:使用官方pip源或者阿里pip源,临时换源方法:python -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
python -m pip install -r requirements.txt
# (选择II: 如不熟悉python)使用anaconda,步骤也是类似的 (https://www.bilibili.com/video/BV1rc411W7Dr):
conda create -n gptac_venv python=3.11 # 创建anaconda环境
conda activate gptac_venv # 激活anaconda环境
python -m pip install -r requirements.txt # 这个步骤和pip安装一样的步骤<details><summary>如果需要支持清华ChatGLM2/复旦MOSS/RWKV作为后端,请点击展开此处</summary> <p>
【可选步骤】如果需要支持清华ChatGLM2/复旦MOSS作为后端,需要额外安装更多依赖(前提条件:熟悉Python + 用过Pytorch + 电脑配置够强):
# 【可选步骤I】支持清华ChatGLM2。清华ChatGLM备注:如果遇到"Call ChatGLM fail 不能正常加载ChatGLM的参数" 错误,参考如下: 1:以上默认安装的为torch+cpu版,使用cuda需要卸载torch重新安装torch+cuda; 2:如因本机配置不够无法加载模型,可以修改request_llm/bridge_chatglm.py中的模型精度, 将 AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) 都修改为 AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt
# 【可选步骤II】支持复旦MOSS
python -m pip install -r request_llm/requirements_moss.txt
git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llm/moss # 注意执行此行代码时,必须处于项目根路径
# 【可选步骤III】支持RWKV Runner
参考wiki:https://github.com/binary-husky/gpt_academic/wiki/%E9%80%82%E9%85%8DRWKV-Runner
# 【可选步骤IV】确保config.py配置文件的AVAIL_LLM_MODELS包含了期望的模型,目前支持的全部模型如下(jittorllms系列目前仅支持docker方案):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]</p> </details>
- 运行
python main.py安装方法II:使用Docker
- 仅ChatGPT(推荐大多数人选择,等价于docker-compose方案1)  [](https://github.com/binary-husky/gptacademic/actions/workflows/build-with-latex.yml) [](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml)
git clone --depth=1 https://github.com/binary-husky/gpt_academic.git # 下载项目
cd gpt_academic # 进入路径
nano config.py # 用任意文本编辑器编辑config.py, 配置 “Proxy”, “API_KEY” 以及 “WEB_PORT” (例如50923) 等
docker build -t gpt-academic . # 安装
#(最后一步-Linux操作系统)用`--net=host`更方便快捷
docker run --rm -it --net=host gpt-academic
#(最后一步-MacOS/Windows操作系统)只能用-p选项将容器上的端口(例如50923)暴露给主机上的端口
docker run --rm -it -e WEB_PORT=50923 -p 50923:50923 gpt-academicP.S. 如果需要依赖Latex的插件功能,请见Wiki。另外,您也可以直接使用docker-compose获取Latex功能(修改docker-compose.yml,保留方案4并删除其他方案)。
- ChatGPT + ChatGLM2 + MOSS + LLAMA2 + 通义千问(需要熟悉Nvidia Docker运行时) 
# 修改docker-compose.yml,保留方案2并删除其他方案。修改docker-compose.yml中方案2的配置,参考其中注释即可
docker-compose up- ChatGPT + LLAMA + 盘古 + RWKV(需要熟悉Nvidia Docker运行时) 
# 修改docker-compose.yml,保留方案3并删除其他方案。修改docker-compose.yml中方案3的配置,参考其中注释即可
docker-compose up安装方法III:其他部署姿势
- 使用docker-compose运行。 请阅读docker-compose.yml后,按照其中的提示操作即可
- 如何使用反代URL 按照
config.py中的说明配置APIURLREDIRECT即可。
- 微软云AzureAPI 按照
config.py中的说明配置即可(AZURE_ENDPOINT等四个配置)
- 远程云服务器部署(需要云服务器知识与经验)。 请访问部署wiki-1
- 使用Sealos一键部署。
- 使用WSL2(Windows Subsystem for Linux 子系统)。 请访问部署wiki-2
- 如何在二级网址(如
http://localhost/subpath)下运行。 请访问FastAPI运行说明
Advanced Usage
I:自定义新的便捷按钮(学术快捷键)
任意文本编辑器打开core_functional.py,添加条目如下,然后重启程序即可。(如果按钮已经添加成功并可见,那么前缀、后缀都支持热修改,无需重启程序即可生效。) 例如
"超级英译中": {
# 前缀,会被加在你的输入之前。例如,用来描述你的要求,例如翻译、解释代码、润色等等
"Prefix": "请翻译把下面一段内容成中文,然后用一个markdown表格逐一解释文中出现的专有名词:\n\n",
# 后缀,会被加在你的输入之后。例如,配合前缀可以把你的输入内容用引号圈起来。
"Suffix": "",
},<div align="center"> <img src="https://user-images.githubusercontent.com/96192199/226899272-477c2134-ed71-4326-810c-29891fe4a508.png" width="500" > </div>
II:自定义函数插件
编写强大的函数插件来执行任何你想得到的和想不到的任务。 本项目的插件编写、调试难度很低,只要您具备一定的python基础知识,就可以仿照我们提供的模板实现自己的插件功能。 详情请参考函数插件指南。
Latest Update
I:新功能动态
- 对话保存功能。在函数插件区调用
保存当前的对话即可将当前对话保存为可读+可复原的html文件, 另外在函数插件区(下拉菜单)调用载入对话历史存档,即可还原之前的会话。 Tip:不指定文件直接点击载入对话历史存档可以查看历史html存档缓存。 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/235222390-24a9acc0-680f-49f5-bc81-2f3161f1e049.png" width="500" > </div>
- ⭐Latex/Arxiv论文翻译功能⭐ <div align="center"> <img src="https://github.com/binary-husky/gptacademic/assets/96192199/002a1a75-ace0-4e6a-94e2-ec1406a746f1" height="250" > ===> <img src="https://github.com/binary-husky/gptacademic/assets/96192199/9fdcc391-f823-464f-9322-f8719677043b" height="250" > </div>
- 生成报告。大部分插件都会在执行结束后,生成工作报告 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/227503770-fe29ce2c-53fd-47b0-b0ff-93805f0c2ff4.png" height="250" > <img src="https://user-images.githubusercontent.com/96192199/227504617-7a497bb3-0a2a-4b50-9a8a-95ae60ea7afd.png" height="250" > </div>
- 模块化功能设计,简单的接口却能支持强大的功能 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/229288270-093643c1-0018-487a-81e6-1d7809b6e90f.png" height="400" > <img src="https://user-images.githubusercontent.com/96192199/227504931-19955f78-45cd-4d1c-adac-e71e50957915.png" height="400" > </div>
- 译解其他开源项目 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" height="250" > <img src="https://user-images.githubusercontent.com/96192199/226969067-968a27c1-1b9c-486b-8b81-ab2de8d3f88a.png" height="250" > </div>
- 装饰live2d的小功能(默认关闭,需要修改
config.py) <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/236432361-67739153-73e8-43fe-8111-b61296edabd9.png" width="500" > </div>
- 新增MOSS大语言模型支持 <div align="center"> <img src="https://user-images.githubusercontent.com/96192199/236639178-92836f37-13af-4fdd-984d-b4450fe30336.png" width="500" > </div>
- OpenAI图像生成 <div align="center"> <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/bc7ab234-ad90-48a0-8d62-f703d9e74665" width="500" > </div>
- OpenAI音频解析与总结 <div align="center"> <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/709ccf95-3aee-498a-934a-e1c22d3d5d5b" width="500" > </div>
- Latex全文校对纠错 <div align="center"> <img src="https://github.com/binary-husky/gptacademic/assets/96192199/651ccd98-02c9-4464-91e1-77a6b7d1b033" height="200" > ===> <img src="https://github.com/binary-husky/gptacademic/assets/96192199/476f66d9-7716-4537-b5c1-735372c25adb" height="200"> </div>
- 语言、主题切换 <div align="center"> <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/b6799499-b6fb-4f0c-9c8e-1b441872f4e8" width="500" > </div>
II:版本:
- version 3.5(Todo): 使用自然语言调用本项目的所有函数插件(高优先级)
- version 3.49: 支持百度千帆平台和文心一言
- version 3.48: 支持阿里达摩院通义千问,上海AI-Lab书生,讯飞星火
- version 3.46: 支持完全脱手操作的实时语音对话
- version 3.45: 支持自定义ChatGLM2微调模型
- version 3.44: 正式支持Azure,优化界面易用性
- version 3.4: +arxiv论文翻译、latex论文批改功能
- version 3.3: +互联网信息综合功能
- version 3.2: 函数插件支持更多参数接口 (保存对话功能, 解读任意语言代码+同时询问任意的LLM组合)
- version 3.1: 支持同时问询多个gpt模型!支持api2d,支持多个apikey负载均衡
- version 3.0: 对chatglm和其他小型llm的支持
- version 2.6: 重构了插件结构,提高了交互性,加入更多插件
- version 2.5: 自更新,解决总结大工程源代码时文本过长、token溢出的问题
- version 2.4: (1)新增PDF全文翻译功能; (2)新增输入区切换位置的功能; (3)新增垂直布局选项; (4)多线程函数插件优化。
- version 2.3: 增强多线程交互性
- version 2.2: 函数插件支持热重载
- version 2.1: 可折叠式布局
- version 2.0: 引入模块化函数插件
- version 1.0: 基础功能
gpt_academic开发者QQ群-2:610599535
- 已知问题
- 某些浏览器翻译插件干扰此软件前端的运行
- 官方Gradio目前有很多兼容性Bug,请务必使用
requirement.txt安装Gradio
III:主题
可以通过修改THEME选项(config.py)变更主题
Chuanhu-Small-and-Beautiful网址
IV:参考与学习
代码中参考了很多其他优秀项目中的设计,顺序不分先后:
# 清华ChatGLM2-6B:
https://github.com/THUDM/ChatGLM2-6B
# 清华JittorLLMs:
https://github.com/Jittor/JittorLLMs
# ChatPaper:
https://github.com/kaixindelele/ChatPaper
# Edge-GPT:
https://github.com/acheong08/EdgeGPT
# ChuanhuChatGPT:
https://github.com/GaiZhenbiao/ChuanhuChatGPT
# Oobabooga one-click installer:
https://github.com/oobabooga/one-click-installers
# More:
https://github.com/gradio-app/gradio
https://github.com/fghrsh/live2d_demo