File size: 20,464 Bytes
2712d99
 
5d23420
2712d99
3da12b5
 
 
2712d99
3da12b5
2712d99
3da12b5
 
2712d99
3da12b5
5d23420
3da12b5
8a5e8bc
3da12b5
5d23420
3108b4a
 
 
2712d99
3da12b5
 
 
 
8a5e8bc
 
3da12b5
 
 
 
8a5e8bc
3da12b5
 
 
 
 
 
 
8a5e8bc
3da12b5
 
 
3108b4a
3da12b5
 
2712d99
 
3da12b5
2712d99
14c70c0
2712d99
 
3da12b5
2712d99
14c70c0
2712d99
 
3da12b5
2712d99
14c70c0
2712d99
 
3da12b5
2712d99
5d23420
2712d99
 
3da12b5
2712d99
5d23420
2712d99
 
5d23420
3da12b5
 
2712d99
3da12b5
2712d99
8a5e8bc
 
2712d99
 
3da12b5
2712d99
3da12b5
5d23420
3da12b5
5d23420
2712d99
3da12b5
2712d99
3da12b5
 
2712d99
3da12b5
 
 
 
2712d99
 
3da12b5
 
 
 
5d23420
3da12b5
 
 
 
 
 
 
 
 
5d23420
 
3da12b5
 
 
 
 
 
2712d99
 
3da12b5
2712d99
3da12b5
5d23420
2712d99
 
3da12b5
 
 
2712d99
 
8a5e8bc
 
3da12b5
 
 
 
2712d99
3da12b5
 
 
2712d99
3da12b5
5d23420
3da12b5
 
 
5d23420
2712d99
3da12b5
5d23420
 
3da12b5
 
2712d99
 
3da12b5
2712d99
3da12b5
 
5d23420
3da12b5
8a5e8bc
5d23420
3da12b5
8a5e8bc
5d23420
3da12b5
 
2712d99
3da12b5
 
2712d99
5d23420
3da12b5
 
5d23420
3da12b5
 
 
2712d99
3da12b5
 
 
 
 
2712d99
 
 
 
 
 
 
3da12b5
2712d99
3da12b5
 
8a5e8bc
2712d99
3da12b5
 
 
 
2712d99
3da12b5
 
 
2712d99
 
3da12b5
2712d99
 
3da12b5
 
 
2712d99
 
3da12b5
 
2712d99
 
3da12b5
 
2712d99
 
3da12b5
 
 
2712d99
3da12b5
2712d99
 
3da12b5
 
2712d99
3da12b5
2712d99
 
 
3da12b5
2712d99
 
3da12b5
 
2712d99
3da12b5
2712d99
 
3da12b5
2712d99
3da12b5
2712d99
 
3da12b5
2712d99
3da12b5
2712d99
 
3da12b5
 
 
 
2712d99
3da12b5
2712d99
3da12b5
2712d99
 
3da12b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2712d99
 
3da12b5
 
 
 
2712d99
3da12b5
 
 
 
 
 
 
2712d99
 
3da12b5
 
2712d99
3da12b5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
> **Note**
>
> This English README is automatically generated by the markdown translation plugin in this project, and may not be 100% correct.
>
> When installing dependencies, **please strictly select the versions** specified in requirements.txt.
> 
> `pip install -r requirements.txt`

# GPT Academic Optimization (GPT Academic)

**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.
To translate this project to arbitary language with GPT, read and run [`multi_language.py`](multi_language.py) (experimental).**

> Note:
> 
> 1. Please note that only the function plugins (buttons) marked in **red** support reading files. Some plugins are in the **drop-down menu** in the plugin area. We welcome and process any new plugins with the **highest priority**!
> 2. The function of each file in this project is detailed in the self-translation analysis [`self_analysis.md`](https://github.com/binary-husky/gpt_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). With version iteration, you can also click on related function plugins at any time to call GPT to regenerate the project's self-analysis report. Common questions are summarized in the [`wiki`](https://github.com/binary-husky/gpt_academic/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98). [Installation method](#installation).
> 3. This project is compatible with and encourages trying domestic large language models such as chatglm, RWKV, Pangu, etc. Multiple API keys are supported and can be filled in the configuration file like `API_KEY="openai-key1,openai-key2,api2d-key3"`. When temporarily changing `API_KEY`, enter the temporary `API_KEY` in the input area and press enter to submit, which will take effect. 

<div align="center">

Function | Description
--- | ---
One-click polishing | Supports one-click polishing and one-click searching for grammar errors in papers.
One-click Chinese-English translation | One-click Chinese-English translation.
One-click code interpretation | Displays, explains, generates, and adds comments to code.
[Custom shortcut keys](https://www.bilibili.com/video/BV14s4y1E7jN) | Supports custom shortcut keys.
Modular design | Supports custom powerful [function plug-ins](https://github.com/binary-husky/gpt_academic/tree/master/crazy_functions), plug-ins support [hot update](https://github.com/binary-husky/gpt_academic/wiki/%E5%87%BD%E6%95%B0%E6%8F%92%E4%BB%B6%E6%8C%87%E5%8D%97).
[Self-program profiling](https://www.bilibili.com/video/BV1cj411A7VW) | [Function plug-in] [One-click understanding](https://github.com/binary-husky/gpt_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) of the source code of this project
[Program profiling](https://www.bilibili.com/video/BV1cj411A7VW) | [Function plug-in] One-click profiling of other project trees in Python/C/C++/Java/Lua/...
Reading papers, [translating](https://www.bilibili.com/video/BV1KT411x7Wn) papers | [Function Plug-in] One-click interpretation of latex/pdf full-text papers and generation of abstracts.
Latex full-text [translation](https://www.bilibili.com/video/BV1nk4y1Y7Js/), [polishing](https://www.bilibili.com/video/BV1FT411H7c5/) | [Function plug-in] One-click translation or polishing of latex papers.
Batch annotation generation | [Function plug-in] One-click batch generation of function annotations.
Markdown [Chinese-English translation](https://www.bilibili.com/video/BV1yo4y157jV/) | [Function plug-in] Have you seen the [README](https://github.com/binary-husky/gpt_academic/blob/master/docs/README_EN.md) in the five languages above?
Chat analysis report generation | [Function plug-in] Automatically generate summary reports after running.
[PDF full-text translation function](https://www.bilibili.com/video/BV1KT411x7Wn) | [Function plug-in] PDF paper extract title & summary + translate full text (multi-threaded)
[Arxiv Assistant](https://www.bilibili.com/video/BV1LM4y1279X) | [Function plug-in] Enter the arxiv article url and you can translate abstracts and download PDFs with one click.
[Google Scholar Integration Assistant](https://www.bilibili.com/video/BV19L411U7ia) | [Function plug-in] Given any Google Scholar search page URL, let GPT help you [write relatedworks](https://www.bilibili.com/video/BV1GP411U7Az/)
Internet information aggregation+GPT | [Function plug-in] One-click [let GPT get information from the Internet first](https://www.bilibili.com/video/BV1om4y127ck), then answer questions, and let the information never be outdated.
Formula/image/table display | Can display formulas in both [tex form and render form](https://user-images.githubusercontent.com/96192199/230598842-1d7fcddd-815d-40ee-af60-baf488a199df.png), support formulas and code highlighting.
Multi-threaded function plug-in support | Supports multi-threaded calling of chatgpt, and can process [massive text](https://www.bilibili.com/video/BV1FT411H7c5/) or programs with one click.
Start Dark Gradio [theme](https://github.com/binary-husky/gpt_academic/issues/173) | Add ```/?__theme=dark``` after the browser URL to switch to the dark theme.
[Multiple LLM models](https://www.bilibili.com/video/BV1wT411p7yf) support, [API2D](https://api2d.com/) interface support | The feeling of being served by GPT3.5, GPT4, [Tsinghua ChatGLM](https://github.com/THUDM/ChatGLM-6B), and [Fudan MOSS](https://github.com/OpenLMLab/MOSS) at the same time must be great, right?
More LLM model access, support [huggingface deployment](https://huggingface.co/spaces/qingxu98/gpt-academic) | Add Newbing interface (New Bing), introduce Tsinghua [Jittorllms](https://github.com/Jittor/JittorLLMs) to support [LLaMA](https://github.com/facebookresearch/llama), [RWKV](https://github.com/BlinkDL/ChatRWKV) and [Panguα](https://openi.org.cn/pangu/)
More new feature displays (image generation, etc.)…… | See the end of this document for more... 
</div>

- New interface (modify the LAYOUT option in `config.py` to switch between "left and right layout" and "up and down layout")
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/230361456-61078362-a966-4eb5-b49e-3c62ef18b860.gif" width="700" >
</div>- All buttons are dynamically generated by reading `functional.py`, and you can add custom functions freely to unleash the power of clipboard.
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/231975334-b4788e91-4887-412f-8b43-2b9c5f41d248.gif" width="700" >
</div>

- polishing/correction
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/231980294-f374bdcb-3309-4560-b424-38ef39f04ebd.gif" width="700" >
</div>

- If the output contains formulas, they will be displayed in both `tex` and render form, making it easy to copy and read.
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/230598842-1d7fcddd-815d-40ee-af60-baf488a199df.png" width="700" >
</div>

- Tired of reading the project code? ChatGPT can explain it all.
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" >
</div>

- Multiple large language models are mixed, such as ChatGLM + OpenAI-GPT3.5 + [API2D](https://api2d.com/)-GPT4.
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/232537274-deca0563-7aa6-4b5d-94a2-b7c453c47794.png" width="700" >
</div>

---
# Installation
## Method 1: Directly running (Windows, Linux or MacOS) 

1. Download the project
```sh
git clone https://github.com/binary-husky/gpt_academic.git
cd gpt_academic
```

2. Configure the API_KEY

Configure the API KEY in `config.py`, [special network environment settings](https://github.com/binary-husky/gpt_academic/issues/1).

(P.S. When the program is running, it will first check if there is a private configuration file named `config_private.py` and use the configurations in it to override the same configurations in `config.py`. Therefore, if you can understand our configuration reading logic, we strongly recommend that you create a new configuration file named `config_private.py` next to `config.py` and transfer (copy) the configurations in `config.py` to `config_private.py`. `config_private.py` is not controlled by git and can make your private information more secure. P.S. The project also supports configuring most options through `environment variables`. Please refer to the format of `docker-compose` file when writing. Reading priority: `environment variables` > `config_private.py` > `config.py`)


3. Install the dependencies
```sh
# (Option I: If familiar with python) (python version 3.9 or above, the newer the better), note: use official pip source or Ali pip source, temporary switching method: python -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
python -m pip install -r requirements.txt

# (Option II: If not familiar with python) Use anaconda, the steps are similar (https://www.bilibili.com/video/BV1rc411W7Dr):
conda create -n gptac_venv python=3.11    # create anaconda environment
conda activate gptac_venv                 # activate anaconda environment
python -m pip install -r requirements.txt # this step is the same as pip installation
```

<details><summary>If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, click to expand</summary>
<p>

[Optional step] If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, you need to install more dependencies (prerequisites: familiar with Python + used Pytorch + computer configuration is strong enough):
```sh
# [Optional Step I] Support Tsinghua ChatGLM. Tsinghua ChatGLM remarks: if you encounter the "Call ChatGLM fail cannot load ChatGLM parameters" error, refer to this: 1: The default installation above is torch + cpu version, to use cuda, you need to uninstall torch and reinstall torch + cuda; 2: If the model cannot be loaded due to insufficient local configuration, you can modify the model accuracy in request_llm/bridge_chatglm.py, and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code = True)
python -m pip install -r request_llm/requirements_chatglm.txt 

# [Optional Step II] Support Fudan MOSS
python -m pip install -r request_llm/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss  # When executing this line of code, you must be in the root directory of the project

# [Optional Step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file includes the expected models. Currently supported models are as follows (the jittorllms series only supports the docker solution for the time being):
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>



4. Run it
```sh
python main.py
```5. Test Function Plugin
```
- Test function plugin template function (ask GPT what happened today in history), based on which you can implement more complex functions as a template
    Click "[Function Plugin Template Demo] Today in History"
```

## Installation - Method 2: Using Docker

1. ChatGPT Only (Recommended for Most People)

``` sh
git clone https://github.com/binary-husky/gpt_academic.git  # Download project
cd gpt_academic                                 # Enter path
nano config.py                                      # Edit config.py with any text editor, configure "Proxy", "API_KEY" and "WEB_PORT" (e.g. 50923), etc.
docker build -t gpt-academic .                      # Install

#(Last step - option 1) In a Linux environment, use `--net=host` for convenience and speed.
docker run --rm -it --net=host gpt-academic
#(Last step - option 2) On macOS/windows environment, only -p option can be used to expose the container's port (e.g. 50923) to the port of the main machine.
docker run --rm -it -e WEB_PORT=50923 -p 50923:50923 gpt-academic
```

2. ChatGPT + ChatGLM + MOSS (Requires Docker Knowledge)

``` sh
# Modify docker-compose.yml, delete Plan 1 and Plan 3, and keep Plan 2. Modify the configuration of Plan 2 in docker-compose.yml, refer to the comments in it for configuration.
docker-compose up
```

3. ChatGPT + LLAMA + Pangu + RWKV (Requires Docker Knowledge)

``` sh
# Modify docker-compose.yml, delete Plan 1 and Plan 2, and keep Plan 3. Modify the configuration of Plan 3 in docker-compose.yml, refer to the comments in it for configuration.
docker-compose up
```

## Installation - Method 3: Other Deployment Options

1. How to Use Reverse Proxy URL/Microsoft Cloud Azure API
Configure API_URL_REDIRECT according to the instructions in 'config.py'.

2. Deploy to a Remote Server (Requires Knowledge and Experience with Cloud Servers)
Please visit [Deployment Wiki-1](https://github.com/binary-husky/gpt_academic/wiki/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%9C%E7%A8%8B%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)

3. Using WSL2 (Windows Subsystem for Linux)
Please visit [Deployment Wiki-2](https://github.com/binary-husky/gpt_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)

4. How to Run Under a Subdomain (e.g. `http://localhost/subpath`)
Please visit [FastAPI Running Instructions](docs/WithFastapi.md)

5. Using docker-compose to Run
Read the docker-compose.yml and follow the prompts.

---
# Advanced Usage
## Custom New Shortcut Buttons / Custom Function Plugins

1. Custom New Shortcut Buttons (Academic Hotkey)
Open `core_functional.py` with any text editor, add an entry as follows and restart the program. (If the button has been successfully added and is visible, the prefix and suffix can be hot-modified without having to restart the program.)
For example,
```
"Super English-to-Chinese": {
    # Prefix, which will be added before your input. For example, used to describe your requests, such as translation, code explanation, polishing, etc.
    "Prefix": "Please translate the following content into Chinese and then use a markdown table to explain the proprietary terms that appear in the text:\n\n", 
    
    # Suffix, which is added after your input. For example, with the prefix, your input content can be surrounded by quotes.
    "Suffix": "",
},
```
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226899272-477c2134-ed71-4326-810c-29891fe4a508.png" width="500" >
</div>

2. Custom Function Plugins

Write powerful function plugins to perform any task you can think of, even those you cannot think of.
The difficulty of plugin writing and debugging in this project is very low. As long as you have a certain knowledge of Python, you can implement your own plug-in functions based on the template we provide.
For details, please refer to the [Function Plugin Guide](https://github.com/binary-husky/gpt_academic/wiki/%E5%87%BD%E6%95%B0%E6%8F%92%E4%BB%B6%E6%8C%87%E5%8D%97).

---
# Latest Update
## New Feature Dynamics
1. Conversation saving function. Call `Save current conversation` in the function plugin area to save the current conversation as a readable and recoverable HTML file. In addition, call `Load conversation history archive` in the function plugin area (dropdown menu) to restore previous sessions. Tip: Clicking `Load conversation history archive` without specifying a file will display the cached history of HTML archives, and clicking `Delete all local conversation history` will delete all HTML archive caches.

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/235222390-24a9acc0-680f-49f5-bc81-2f3161f1e049.png" width="500" >
</div>


2. Report generation. Most plugins will generate work reports after execution. 

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/227503770-fe29ce2c-53fd-47b0-b0ff-93805f0c2ff4.png" height="300" >
<img src="https://user-images.githubusercontent.com/96192199/227504617-7a497bb3-0a2a-4b50-9a8a-95ae60ea7afd.png" height="300" >
<img src="https://user-images.githubusercontent.com/96192199/227504005-efeaefe0-b687-49d0-bf95-2d7b7e66c348.png" height="300" >
</div>


3. Modular function design with simple interfaces that support powerful functions.

<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>


4. This is an open-source project that can "self-translate".

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226936850-c77d7183-0749-4c1c-9875-fd4891842d0c.png" width="500" >
</div>

5. Translating other open-source projects is a piece of cake.

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="500" >
</div>

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226969067-968a27c1-1b9c-486b-8b81-ab2de8d3f88a.png" width="500" >
</div>

6. A small feature decorated with [live2d](https://github.com/fghrsh/live2d_demo) (disabled by default, need to modify `config.py`).

<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/236432361-67739153-73e8-43fe-8111-b61296edabd9.png" width="500" >
</div>

7. Added MOSS large language model support.
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/236639178-92836f37-13af-4fdd-984d-b4450fe30336.png" width="500" >
</div>

8. OpenAI image generation.
<div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/bc7ab234-ad90-48a0-8d62-f703d9e74665" width="500" >
</div>

9. OpenAI audio parsing and summarization.
<div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/709ccf95-3aee-498a-934a-e1c22d3d5d5b" width="500" >
</div>

10. Full-text proofreading and error correction of LaTeX.
<div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/651ccd98-02c9-4464-91e1-77a6b7d1b033" width="500" >
</div>


## Versions:
- version 3.5(Todo): Use natural language to call all function plugins of this project (high priority).
- version 3.4(Todo): Improve multi-threading support for chatglm local large models.
- version 3.3: +Internet information integration function.
- version 3.2: Function plugin supports more parameter interfaces (save conversation function, interpretation of any language code + simultaneous inquiry of any LLM combination).
- version 3.1: Support simultaneous inquiry of multiple GPT models! Support api2d, and support load balancing of multiple apikeys.
- version 3.0: Support chatglm and other small LLM models.
- version 2.6: Refactored plugin structure, improved interactivity, and added more plugins.
- version 2.5: Self-updating, solving the problem of text overflow and token overflow when summarizing large engineering source codes.
- version 2.4: (1) Added PDF full-text translation function; (2) Added the function of switching the position of the input area; (3) Added vertical layout option; (4) Optimized multi-threading function plugins.
- version 2.3: Enhanced multi-threading interactivity.
- version 2.2: Function plugin supports hot reloading.
- version 2.1: Collapsible layout.
- version 2.0: Introduction of modular function plugins.
- version 1.0: Basic functions.

gpt_academic Developer QQ Group-2: 610599535

- Known Issues
    - Some browser translation plugins interfere with the front-end operation of this software.
    - Both high and low versions of gradio can lead to various exceptions.

## Reference and Learning

```
Many other excellent designs have been referenced in the code, mainly including:

# Project 1: THU ChatGLM-6B:
https://github.com/THUDM/ChatGLM-6B

# Project 2: THU JittorLLMs:
https://github.com/Jittor/JittorLLMs

# Project 3: Edge-GPT:
https://github.com/acheong08/EdgeGPT

# Project 4: ChuanhuChatGPT:
https://github.com/GaiZhenbiao/ChuanhuChatGPT

# Project 5: ChatPaper:
https://github.com/kaixindelele/ChatPaper

# More:
https://github.com/gradio-app/gradio
https://github.com/fghrsh/live2d_demo
```