Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c063510442 | ||
|
|
bc6d0926b1 | ||
|
|
0f20ffeff4 | ||
|
|
9299c93b17 | ||
|
|
3463a1173a | ||
|
|
74eaff4919 | ||
|
|
dd51708309 | ||
|
|
25693c362c | ||
|
|
9eb15f5e68 | ||
|
|
7e195244f1 | ||
|
|
98d97ebbc8 | ||
|
|
6ab3672cfe | ||
|
|
6f1ad29e3f | ||
|
|
61c65d90fe | ||
|
|
8965706169 | ||
|
|
a63ae898ce | ||
|
|
186f10a3e3 | ||
|
|
67ed394484 | ||
|
|
2f4c46b22c | ||
|
|
2f5c977a27 | ||
|
|
f801cfbcf6 | ||
|
|
15693f3f8f | ||
|
|
8cbac095c1 | ||
|
|
289ace03cf | ||
|
|
cefc40aff8 | ||
|
|
15dd4b7a80 | ||
|
|
5f8473badb | ||
|
|
a8cfe2f113 | ||
|
|
27e056ea35 | ||
|
|
278f21fde0 | ||
|
|
121f288878 | ||
|
|
5a6b46f0b5 | ||
|
|
22766d3c12 |
@@ -0,0 +1,5 @@
|
|||||||
|
*.h linguist-detectable=false
|
||||||
|
*.cpp linguist-detectable=false
|
||||||
|
*.tex linguist-detectable=false
|
||||||
|
*.cs linguist-detectable=false
|
||||||
|
*.tps linguist-detectable=false
|
||||||
@@ -136,3 +136,4 @@ ssr_conf
|
|||||||
config_private.py
|
config_private.py
|
||||||
gpt_log
|
gpt_log
|
||||||
private.md
|
private.md
|
||||||
|
private_upload
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
FROM ubuntu:latest
|
FROM python:3.11
|
||||||
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y python3 python3-pip && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
RUN echo '[global]' > /etc/pip.conf && \
|
RUN echo '[global]' > /etc/pip.conf && \
|
||||||
echo 'index-url = https://mirrors.aliyun.com/pypi/simple/' >> /etc/pip.conf && \
|
echo 'index-url = https://mirrors.aliyun.com/pypi/simple/' >> /etc/pip.conf && \
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
**如果喜欢这个项目,请给它一个Star;如果你发明了更好用的学术快捷键,欢迎发issue或者pull requests**
|
**如果喜欢这个项目,请给它一个Star;如果你发明了更好用的学术快捷键,欢迎发issue或者pull requests**
|
||||||
|
|
||||||
If you like this project, please give it a Star. If you've come up with more useful academic shortcuts, feel free to open an issue or pull request.
|
If you like this project, please give it a Star. If you've come up with more useful academic shortcuts, feel free to open an issue or pull request.
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
功能 | 描述
|
功能 | 描述
|
||||||
--- | ---
|
--- | ---
|
||||||
@@ -12,38 +13,46 @@ If you like this project, please give it a Star. If you've come up with more use
|
|||||||
自定义快捷键 | 支持自定义快捷键
|
自定义快捷键 | 支持自定义快捷键
|
||||||
配置代理服务器 | 支持配置代理服务器
|
配置代理服务器 | 支持配置代理服务器
|
||||||
模块化设计 | 支持自定义高阶的实验性功能
|
模块化设计 | 支持自定义高阶的实验性功能
|
||||||
自我程序剖析 | [实验性功能] 可以读懂自己的源代码
|
自我程序剖析 | [实验性功能] 一键读懂本项目的源代码
|
||||||
程序剖析 | [实验性功能] 可以剖析其他Python/C++项目
|
程序剖析 | [实验性功能] 一键可以剖析其他Python/C++项目
|
||||||
读论文 | [实验性功能] 解读latex论文写摘要
|
读论文 | [实验性功能] 一键解读latex论文全文并生成摘要
|
||||||
批量注释生成 | [实验性功能] 批量生成函数注释
|
批量注释生成 | [实验性功能] 一键批量生成函数注释
|
||||||
|
chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报
|
||||||
公式显示 | 可以同时显示公式的tex形式和渲染形式
|
公式显示 | 可以同时显示公式的tex形式和渲染形式
|
||||||
图片显示 | 可以在markdown中显示图片
|
图片显示 | 可以在markdown中显示图片
|
||||||
支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格
|
支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- 支持GPT输出的markdown表格
|
|
||||||
<div align="center">
|
|
||||||
<img src="demo2.jpg" width="500" >
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
- 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读
|
- 新界面
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="demo.jpg" width="500" >
|
<img src="https://user-images.githubusercontent.com/96192199/227528413-36ab42da-d589-4ef1-ba75-28aa02442d05.png" width="700" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- 所有按钮都通过读取functional.py动态生成,可随意加自定义功能,解放粘贴板
|
- 所有按钮都通过读取functional.py动态生成,可随意加自定义功能,解放粘贴板
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="公式.gif" width="700" >
|
<img src="img/公式.gif" width="700" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
- 代码的显示自然也不在话下 https://www.bilibili.com/video/BV1F24y147PD/
|
- 代码的显示自然也不在话下 https://www.bilibili.com/video/BV1F24y147PD/
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="润色.gif" width="700" >
|
<img src="img/润色.gif" width="700" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
- 支持GPT输出的markdown表格
|
||||||
|
<div align="center">
|
||||||
|
<img src="img/demo2.jpg" width="500" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
- 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读
|
||||||
|
<div align="center">
|
||||||
|
<img src="img/demo.jpg" width="500" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
- 懒得看项目代码?整个工程直接给chatgpt炫嘴里
|
- 懒得看项目代码?整个工程直接给chatgpt炫嘴里
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" >
|
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="700" >
|
||||||
@@ -51,7 +60,7 @@ If you like this project, please give it a Star. If you've come up with more use
|
|||||||
|
|
||||||
## 直接运行 (Windows or Linux or MacOS)
|
## 直接运行 (Windows or Linux or MacOS)
|
||||||
|
|
||||||
```
|
``` sh
|
||||||
# 下载项目
|
# 下载项目
|
||||||
git clone https://github.com/binary-husky/chatgpt_academic.git
|
git clone https://github.com/binary-husky/chatgpt_academic.git
|
||||||
cd chatgpt_academic
|
cd chatgpt_academic
|
||||||
@@ -62,6 +71,18 @@ cd chatgpt_academic
|
|||||||
python -m pip install -r requirements.txt
|
python -m pip install -r requirements.txt
|
||||||
# 运行
|
# 运行
|
||||||
python main.py
|
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回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能
|
||||||
|
点击 "[实验] 实验功能函数模板"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +99,19 @@ docker build -t gpt-academic .
|
|||||||
# 运行
|
# 运行
|
||||||
docker run --rm -it --net=host gpt-academic
|
docker run --rm -it --net=host gpt-academic
|
||||||
|
|
||||||
|
# 测试实验性功能
|
||||||
|
## 测试自我代码解读
|
||||||
|
点击 "[实验] 请解析并解构此项目本身"
|
||||||
|
## 测试实验功能模板函数(要求gpt回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能
|
||||||
|
点击 "[实验] 实验功能函数模板"
|
||||||
|
##(请注意在docker中运行时,需要额外注意程序的文件访问权限问题)
|
||||||
|
## 测试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输入项目根路径)"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -120,10 +154,8 @@ python check_proxy.py
|
|||||||
|
|
||||||
### 图片显示:
|
### 图片显示:
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="https://user-images.githubusercontent.com/96192199/226906087-b5f1c127-2060-4db9-af05-487643b21ed9.png" width="500" >
|
<img src="https://user-images.githubusercontent.com/96192199/226906087-b5f1c127-2060-4db9-af05-487643b21ed9.png" height="200" >
|
||||||
</div>
|
<img src="https://user-images.githubusercontent.com/96192199/226906703-7226495d-6a1f-4a53-9728-ce6778cbdd19.png" height="200" >
|
||||||
<div align="center">
|
|
||||||
<img src="https://user-images.githubusercontent.com/96192199/226906703-7226495d-6a1f-4a53-9728-ce6778cbdd19.png" width="200" >
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### 如果一个程序能够读懂并剖析自己:
|
### 如果一个程序能够读懂并剖析自己:
|
||||||
@@ -136,7 +168,7 @@ python check_proxy.py
|
|||||||
<img src="https://user-images.githubusercontent.com/96192199/226936618-9b487e4b-ab5b-4b6e-84c6-16942102e917.png" width="800" >
|
<img src="https://user-images.githubusercontent.com/96192199/226936618-9b487e4b-ab5b-4b6e-84c6-16942102e917.png" width="800" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### 其他任意Python项目剖析:
|
### 其他任意Python/Cpp项目剖析:
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="800" >
|
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="800" >
|
||||||
</div>
|
</div>
|
||||||
@@ -145,6 +177,24 @@ python check_proxy.py
|
|||||||
<img src="https://user-images.githubusercontent.com/96192199/226969067-968a27c1-1b9c-486b-8b81-ab2de8d3f88a.png" width="800" >
|
<img src="https://user-images.githubusercontent.com/96192199/226969067-968a27c1-1b9c-486b-8b81-ab2de8d3f88a.png" width="800" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Latex论文一键阅读理解与摘要生成
|
||||||
|
<div align="center">
|
||||||
|
<img src="https://user-images.githubusercontent.com/96192199/227504406-86ab97cd-f208-41c3-8e4a-7000e51cf980.png" width="800" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
### 自动报告生成
|
||||||
|
<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>
|
||||||
|
|
||||||
|
### 模块化功能设计
|
||||||
|
<div align="center">
|
||||||
|
<img src="https://user-images.githubusercontent.com/96192199/227504981-4c6c39c0-ae79-47e6-bffe-0e6442d9da65.png" height="400" >
|
||||||
|
<img src="https://user-images.githubusercontent.com/96192199/227504931-19955f78-45cd-4d1c-adac-e71e50957915.png" height="400" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
## 参考项目
|
## 参考项目
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
import platform
|
|
||||||
from sys import stdout
|
|
||||||
|
|
||||||
if platform.system()=="Linux":
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
from colorama import init
|
|
||||||
init()
|
|
||||||
|
|
||||||
# Do you like the elegance of Chinese characters?
|
|
||||||
def print红(*kw,**kargs):
|
|
||||||
print("\033[0;31m",*kw,"\033[0m",**kargs)
|
|
||||||
def print绿(*kw,**kargs):
|
|
||||||
print("\033[0;32m",*kw,"\033[0m",**kargs)
|
|
||||||
def print黄(*kw,**kargs):
|
|
||||||
print("\033[0;33m",*kw,"\033[0m",**kargs)
|
|
||||||
def print蓝(*kw,**kargs):
|
|
||||||
print("\033[0;34m",*kw,"\033[0m",**kargs)
|
|
||||||
def print紫(*kw,**kargs):
|
|
||||||
print("\033[0;35m",*kw,"\033[0m",**kargs)
|
|
||||||
def print靛(*kw,**kargs):
|
|
||||||
print("\033[0;36m",*kw,"\033[0m",**kargs)
|
|
||||||
|
|
||||||
def print亮红(*kw,**kargs):
|
|
||||||
print("\033[1;31m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮绿(*kw,**kargs):
|
|
||||||
print("\033[1;32m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮黄(*kw,**kargs):
|
|
||||||
print("\033[1;33m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮蓝(*kw,**kargs):
|
|
||||||
print("\033[1;34m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮紫(*kw,**kargs):
|
|
||||||
print("\033[1;35m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮靛(*kw,**kargs):
|
|
||||||
print("\033[1;36m",*kw,"\033[0m",**kargs)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def print亮红(*kw,**kargs):
|
|
||||||
print("\033[1;31m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮绿(*kw,**kargs):
|
|
||||||
print("\033[1;32m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮黄(*kw,**kargs):
|
|
||||||
print("\033[1;33m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮蓝(*kw,**kargs):
|
|
||||||
print("\033[1;34m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮紫(*kw,**kargs):
|
|
||||||
print("\033[1;35m",*kw,"\033[0m",**kargs)
|
|
||||||
def print亮靛(*kw,**kargs):
|
|
||||||
print("\033[1;36m",*kw,"\033[0m",**kargs)
|
|
||||||
|
|
||||||
print_red = print红
|
|
||||||
print_green = print绿
|
|
||||||
print_yellow = print黄
|
|
||||||
print_blue = print蓝
|
|
||||||
print_purple = print紫
|
|
||||||
print_indigo = print靛
|
|
||||||
|
|
||||||
print_bold_red = print亮红
|
|
||||||
print_bold_green = print亮绿
|
|
||||||
print_bold_yellow = print亮黄
|
|
||||||
print_bold_blue = print亮蓝
|
|
||||||
print_bold_purple = print亮紫
|
|
||||||
print_bold_indigo = print亮靛
|
|
||||||
|
|
||||||
if not stdout.isatty():
|
|
||||||
# redirection, avoid a fucked up log file
|
|
||||||
print红 = print
|
|
||||||
print绿 = print
|
|
||||||
print黄 = print
|
|
||||||
print蓝 = print
|
|
||||||
print紫 = print
|
|
||||||
print靛 = print
|
|
||||||
print亮红 = print
|
|
||||||
print亮绿 = print
|
|
||||||
print亮黄 = print
|
|
||||||
print亮蓝 = print
|
|
||||||
print亮紫 = print
|
|
||||||
print亮靛 = print
|
|
||||||
print_red = print
|
|
||||||
print_green = print
|
|
||||||
print_yellow = print
|
|
||||||
print_blue = print
|
|
||||||
print_purple = print
|
|
||||||
print_indigo = print
|
|
||||||
print_bold_red = print
|
|
||||||
print_bold_green = print
|
|
||||||
print_bold_yellow = print
|
|
||||||
print_bold_blue = print
|
|
||||||
print_bold_purple = print
|
|
||||||
print_bold_indigo = print
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
https://github.com/mutouyun/cpp-ipc
|
||||||
|
|
||||||
|
A high-performance inter-process communication library using shared memory on Linux/Windows.
|
||||||
@@ -9,9 +9,9 @@ def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot,
|
|||||||
with open(fp, 'r', encoding='utf-8') as f:
|
with open(fp, 'r', encoding='utf-8') as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
|
|
||||||
前言 = "接下来请你逐文件分析下面的工程" if index==0 else ""
|
prefix = "接下来请你逐文件分析下面的工程" if index==0 else ""
|
||||||
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{os.path.relpath(fp, project_folder)},文件代码是 ```{file_content}```'
|
i_say = prefix + f'请对下面的程序文件做一个概述文件名是{os.path.relpath(fp, project_folder)},文件代码是 ```{file_content}```'
|
||||||
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
||||||
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
||||||
yield chatbot, history, '正常'
|
yield chatbot, history, '正常'
|
||||||
|
|
||||||
@@ -56,9 +56,9 @@ def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTx
|
|||||||
with open(fp, 'r', encoding='utf-8') as f:
|
with open(fp, 'r', encoding='utf-8') as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
|
|
||||||
前言 = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
|
prefix = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
|
||||||
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
|
i_say = prefix + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
|
||||||
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
|
||||||
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
||||||
yield chatbot, history, '正常'
|
yield chatbot, history, '正常'
|
||||||
|
|
||||||
@@ -127,3 +127,23 @@ def 解析一个C项目的头文件(txt, top_p, temperature, chatbot, history, s
|
|||||||
return
|
return
|
||||||
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
||||||
|
|
||||||
|
@CatchException
|
||||||
|
def 解析一个C项目(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT):
|
||||||
|
history = [] # 清空历史,以免输入溢出
|
||||||
|
import glob, os
|
||||||
|
if os.path.exists(txt):
|
||||||
|
project_folder = txt
|
||||||
|
else:
|
||||||
|
if txt == "": txt = '空空如也的输入栏'
|
||||||
|
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
||||||
|
yield chatbot, history, '正常'
|
||||||
|
return
|
||||||
|
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
|
||||||
|
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
||||||
|
[f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
||||||
|
if len(file_manifest) == 0:
|
||||||
|
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
|
||||||
|
yield chatbot, history, '正常'
|
||||||
|
return
|
||||||
|
yield from 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot, history, systemPromptTxt)
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
|
|||||||
with open(fp, 'r', encoding='utf-8') as f:
|
with open(fp, 'r', encoding='utf-8') as f:
|
||||||
file_content = f.read()
|
file_content = f.read()
|
||||||
|
|
||||||
前言 = "接下来请你逐文件分析下面的论文文件,概括其内容" if index==0 else ""
|
prefix = "接下来请你逐文件分析下面的论文文件,概括其内容" if index==0 else ""
|
||||||
i_say = 前言 + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
|
||||||
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
i_say_show_user = prefix + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
|
||||||
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
chatbot.append((i_say_show_user, "[Local Message] waiting gpt response."))
|
||||||
print('[1] yield chatbot, history')
|
print('[1] yield chatbot, history')
|
||||||
yield chatbot, history, '正常'
|
yield chatbot, history, '正常'
|
||||||
|
|||||||
@@ -5,32 +5,62 @@ def get_crazy_functionals():
|
|||||||
from crazy_functions.解析项目源代码 import 解析项目本身
|
from crazy_functions.解析项目源代码 import 解析项目本身
|
||||||
from crazy_functions.解析项目源代码 import 解析一个Python项目
|
from crazy_functions.解析项目源代码 import 解析一个Python项目
|
||||||
from crazy_functions.解析项目源代码 import 解析一个C项目的头文件
|
from crazy_functions.解析项目源代码 import 解析一个C项目的头文件
|
||||||
|
from crazy_functions.解析项目源代码 import 解析一个C项目
|
||||||
from crazy_functions.高级功能函数模板 import 高阶功能模板函数
|
from crazy_functions.高级功能函数模板 import 高阶功能模板函数
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"[实验功能] 请解析并解构此项目本身": {
|
"[实验] 请解析并解构此项目本身": {
|
||||||
"Function": 解析项目本身
|
"Function": 解析项目本身
|
||||||
},
|
},
|
||||||
"[实验功能] 解析整个Python项目(input输入项目根路径)": {
|
"[实验] 解析整个py项目(配合input输入框)": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 解析一个Python项目
|
"Function": 解析一个Python项目
|
||||||
},
|
},
|
||||||
"[实验功能] 解析整个C++项目的头文件(input输入项目根路径)": {
|
"[实验] 解析整个C++项目头文件(配合input输入框)": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 解析一个C项目的头文件
|
"Function": 解析一个C项目的头文件
|
||||||
},
|
},
|
||||||
"[实验功能] 解读latex论文写摘要(input输入项目根路径)": {
|
"[实验] 解析整个C++项目(配合input输入框)": {
|
||||||
|
"Color": "stop", # 按钮颜色
|
||||||
|
"Function": 解析一个C项目
|
||||||
|
},
|
||||||
|
"[实验] 读tex论文写摘要(配合input输入框)": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 读文章写摘要
|
"Function": 读文章写摘要
|
||||||
},
|
},
|
||||||
"[实验功能] 批量生成函数注释(input输入项目根路径)": {
|
"[实验] 批量生成函数注释(配合input输入框)": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 批量生成函数注释
|
"Function": 批量生成函数注释
|
||||||
},
|
},
|
||||||
"[实验功能] 实验功能函数模板": {
|
"[实验] 实验功能函数模板": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 高阶功能模板函数
|
"Function": 高阶功能模板函数
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def on_file_uploaded(files, chatbot, txt):
|
||||||
|
import shutil, os, time, glob
|
||||||
|
from toolbox import extract_archive
|
||||||
|
try: shutil.rmtree('./private_upload/')
|
||||||
|
except: pass
|
||||||
|
time_tag = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
|
||||||
|
os.makedirs(f'private_upload/{time_tag}', exist_ok=True)
|
||||||
|
for file in files:
|
||||||
|
file_origin_name = os.path.basename(file.orig_name)
|
||||||
|
shutil.copy(file.name, f'private_upload/{time_tag}/{file_origin_name}')
|
||||||
|
extract_archive(f'private_upload/{time_tag}/{file_origin_name}',
|
||||||
|
dest_dir=f'private_upload/{time_tag}/{file_origin_name}.extract')
|
||||||
|
moved_files = [fp for fp in glob.glob('private_upload/**/*', recursive=True)]
|
||||||
|
txt = f'private_upload/{time_tag}'
|
||||||
|
moved_files_str = '\t\n\n'.join(moved_files)
|
||||||
|
chatbot.append(['我上传了文件,请查收',
|
||||||
|
f'[Local Message] 收到以下文件: \n\n{moved_files_str}\n\n调用路径参数已自动修正到: \n\n{txt}\n\n现在您可以直接选择任意实现性功能'])
|
||||||
|
return chatbot, txt
|
||||||
|
|
||||||
|
def on_report_generated(files, chatbot):
|
||||||
|
from toolbox import find_recent_files
|
||||||
|
report_files = find_recent_files('gpt_log')
|
||||||
|
# files.extend(report_files)
|
||||||
|
chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧文件上传区,请查收。'])
|
||||||
|
return report_files, chatbot
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 262 KiB |
|
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 264 KiB |
|
Before Width: | Height: | Size: 11 MiB After Width: | Height: | Size: 11 MiB |
|
Before Width: | Height: | Size: 12 MiB After Width: | Height: | Size: 12 MiB |
@@ -1,32 +1,44 @@
|
|||||||
import os; os.environ['no_proxy'] = '*'
|
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
from predict import predict
|
from predict import predict
|
||||||
from toolbox import format_io, find_free_port
|
from toolbox import format_io, find_free_port
|
||||||
|
|
||||||
try: from config_private import proxies, WEB_PORT # 放自己的秘密如API和代理网址 os.path.exists('config_private.py')
|
# 建议您复制一个config_private.py放自己的秘密,如API和代理网址,避免不小心传github被别人看到
|
||||||
|
try: from config_private import proxies, WEB_PORT
|
||||||
except: from config import proxies, WEB_PORT
|
except: from config import proxies, WEB_PORT
|
||||||
|
|
||||||
|
# 如果WEB_PORT是-1,则随机选取WEB端口
|
||||||
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
||||||
|
|
||||||
initial_prompt = "Serve me as a writing and programming assistant."
|
initial_prompt = "Serve me as a writing and programming assistant."
|
||||||
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
||||||
|
|
||||||
|
# 问询记录,python 版本建议3.9+(越新越好)
|
||||||
import logging
|
import logging
|
||||||
os.makedirs('gpt_log', exist_ok=True)
|
os.makedirs('gpt_log', exist_ok=True)
|
||||||
logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
||||||
|
except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO)
|
||||||
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log,请注意自我隐私保护哦!')
|
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log,请注意自我隐私保护哦!')
|
||||||
|
|
||||||
# 一些普通功能
|
# 一些普通功能模块
|
||||||
from functional import get_functionals
|
from functional import get_functionals
|
||||||
functional = get_functionals()
|
functional = get_functionals()
|
||||||
|
|
||||||
# 对一些丧心病狂的实验性功能进行测试
|
# 对一些丧心病狂的实验性功能模块进行测试
|
||||||
from functional_crazy import get_crazy_functionals
|
from functional_crazy import get_crazy_functionals, on_file_uploaded, on_report_generated
|
||||||
crazy_functional = get_crazy_functionals()
|
crazy_functional = get_crazy_functionals()
|
||||||
|
|
||||||
|
# 处理markdown文本格式的转变
|
||||||
gr.Chatbot.postprocess = format_io
|
gr.Chatbot.postprocess = format_io
|
||||||
|
|
||||||
with gr.Blocks() as demo:
|
# 做一些样式上的调整
|
||||||
|
try: set_theme = gr.themes.Default( primary_hue=gr.themes.utils.colors.orange,
|
||||||
|
font=["ui-sans-serif", "system-ui", "sans-serif", gr.themes.utils.fonts.GoogleFont("Source Sans Pro")],
|
||||||
|
font_mono=["ui-monospace", "Consolas", "monospace", gr.themes.utils.fonts.GoogleFont("IBM Plex Mono")])
|
||||||
|
except:
|
||||||
|
set_theme = None; print('gradio版本较旧,不能自定义字体和颜色')
|
||||||
|
|
||||||
|
with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
||||||
gr.HTML(title_html)
|
gr.HTML(title_html)
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column(scale=2):
|
with gr.Column(scale=2):
|
||||||
@@ -46,9 +58,17 @@ with gr.Blocks() as demo:
|
|||||||
for k in functional:
|
for k in functional:
|
||||||
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
|
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
|
||||||
functional[k]["Button"] = gr.Button(k, variant=variant)
|
functional[k]["Button"] = gr.Button(k, variant=variant)
|
||||||
|
with gr.Row():
|
||||||
|
gr.Markdown("以下部分实验性功能需从input框读取路径.")
|
||||||
|
with gr.Row():
|
||||||
for k in crazy_functional:
|
for k in crazy_functional:
|
||||||
variant = crazy_functional[k]["Color"] if "Color" in crazy_functional[k] else "secondary"
|
variant = crazy_functional[k]["Color"] if "Color" in crazy_functional[k] else "secondary"
|
||||||
crazy_functional[k]["Button"] = gr.Button(k, variant=variant)
|
crazy_functional[k]["Button"] = gr.Button(k, variant=variant)
|
||||||
|
with gr.Row():
|
||||||
|
gr.Markdown("上传本地文件供上面的实验性功能调用.")
|
||||||
|
with gr.Row():
|
||||||
|
file_upload = gr.Files(label='任何文件,但推荐上传压缩文件(zip, tar)', file_count="multiple")
|
||||||
|
|
||||||
from check_proxy import check_proxy
|
from check_proxy import check_proxy
|
||||||
statusDisplay = gr.Markdown(f"{check_proxy(proxies)}")
|
statusDisplay = gr.Markdown(f"{check_proxy(proxies)}")
|
||||||
systemPromptTxt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt).style(container=True)
|
systemPromptTxt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt).style(container=True)
|
||||||
@@ -62,11 +82,16 @@ with gr.Blocks() as demo:
|
|||||||
for k in functional:
|
for k in functional:
|
||||||
functional[k]["Button"].click(predict,
|
functional[k]["Button"].click(predict,
|
||||||
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
||||||
|
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
||||||
for k in crazy_functional:
|
for k in crazy_functional:
|
||||||
crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
|
click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
|
||||||
[txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay])
|
[txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay]
|
||||||
|
)
|
||||||
|
try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
|
# 延迟函数,做一些准备工作,最后尝试打开浏览器
|
||||||
def auto_opentab_delay():
|
def auto_opentab_delay():
|
||||||
import threading, webbrowser, time
|
import threading, webbrowser, time
|
||||||
print(f"URL http://localhost:{PORT}")
|
print(f"URL http://localhost:{PORT}")
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import logging
|
|||||||
import traceback
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
import importlib
|
import importlib
|
||||||
from colorful import *
|
|
||||||
|
|
||||||
# config_private.py放自己的秘密如API和代理网址
|
# config_private.py放自己的秘密如API和代理网址
|
||||||
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
||||||
@@ -16,6 +15,9 @@ except: from config import proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY
|
|||||||
timeout_bot_msg = '[local] Request timeout, network error. please check proxy settings in config.py.'
|
timeout_bot_msg = '[local] Request timeout, network error. please check proxy settings in config.py.'
|
||||||
|
|
||||||
def get_full_error(chunk, stream_response):
|
def get_full_error(chunk, stream_response):
|
||||||
|
"""
|
||||||
|
获取完整的从Openai返回的报错
|
||||||
|
"""
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
chunk += next(stream_response)
|
chunk += next(stream_response)
|
||||||
@@ -24,6 +26,16 @@ def get_full_error(chunk, stream_response):
|
|||||||
return chunk
|
return chunk
|
||||||
|
|
||||||
def predict_no_ui(inputs, top_p, temperature, history=[]):
|
def predict_no_ui(inputs, top_p, temperature, history=[]):
|
||||||
|
"""
|
||||||
|
发送至chatGPT,等待回复,一次性完成,不显示中间过程。
|
||||||
|
predict函数的简化版。
|
||||||
|
用于payload比较大的情况,或者用于实现多线、带嵌套的复杂功能。
|
||||||
|
|
||||||
|
inputs 是本次问询的输入
|
||||||
|
top_p, temperature是chatGPT的内部调优参数
|
||||||
|
history 是之前的对话列表
|
||||||
|
(注意无论是inputs还是history,内容太长了都会触发token数量溢出的错误,然后raise ConnectionAbortedError)
|
||||||
|
"""
|
||||||
headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt="", stream=False)
|
headers, payload = generate_payload(inputs, top_p, temperature, history, system_prompt="", stream=False)
|
||||||
|
|
||||||
retry = 0
|
retry = 0
|
||||||
@@ -48,7 +60,15 @@ def predict_no_ui(inputs, top_p, temperature, history=[]):
|
|||||||
|
|
||||||
def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt='',
|
def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt='',
|
||||||
stream = True, additional_fn=None):
|
stream = True, additional_fn=None):
|
||||||
|
"""
|
||||||
|
发送至chatGPT,流式获取输出。
|
||||||
|
用于基础的对话功能。
|
||||||
|
inputs 是本次问询的输入
|
||||||
|
top_p, temperature是chatGPT的内部调优参数
|
||||||
|
history 是之前的对话列表(注意无论是inputs还是history,内容太长了都会触发token数量溢出的错误)
|
||||||
|
chatbot 为WebUI中显示的对话列表,修改它,然后yeild出去,可以直接修改对话界面内容
|
||||||
|
additional_fn代表点击的哪个按钮,按钮见functional.py
|
||||||
|
"""
|
||||||
if additional_fn is not None:
|
if additional_fn is not None:
|
||||||
import functional
|
import functional
|
||||||
importlib.reload(functional)
|
importlib.reload(functional)
|
||||||
@@ -116,6 +136,9 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
|
|||||||
return
|
return
|
||||||
|
|
||||||
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):
|
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):
|
||||||
|
"""
|
||||||
|
整合所有信息,选择LLM模型,生成http请求,为发送请求做准备
|
||||||
|
"""
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {API_KEY}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
gradio
|
gradio>=3.23
|
||||||
requests[socks]
|
requests[socks]
|
||||||
mdtex2html
|
mdtex2html
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
|
|||||||
try: from config_private import TIMEOUT_SECONDS, MAX_RETRY
|
try: from config_private import TIMEOUT_SECONDS, MAX_RETRY
|
||||||
except: from config import TIMEOUT_SECONDS, MAX_RETRY
|
except: from config import TIMEOUT_SECONDS, MAX_RETRY
|
||||||
from predict import predict_no_ui
|
from predict import predict_no_ui
|
||||||
|
# 多线程的时候,需要一个mutable结构在不同线程之间传递信息
|
||||||
|
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
||||||
mutable = [None, '']
|
mutable = [None, '']
|
||||||
|
# multi-threading worker
|
||||||
def mt(i_say, history):
|
def mt(i_say, history):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -25,14 +28,16 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
|
|||||||
mutable[1] = 'Warning! Input file is too long, cut into half. '
|
mutable[1] = 'Warning! Input file is too long, cut into half. '
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
mutable[0] = '[Local Message] Failed with timeout'
|
mutable[0] = '[Local Message] Failed with timeout'
|
||||||
|
# 创建新线程发出http请求
|
||||||
thread_name = threading.Thread(target=mt, args=(i_say, history)); thread_name.start()
|
thread_name = threading.Thread(target=mt, args=(i_say, history)); thread_name.start()
|
||||||
|
# 原来的线程则负责持续更新UI,实现一个超时倒计时,并等待新线程的任务完成
|
||||||
cnt = 0
|
cnt = 0
|
||||||
while thread_name.is_alive():
|
while thread_name.is_alive():
|
||||||
cnt += 1
|
cnt += 1
|
||||||
chatbot[-1] = (i_say_show_user, f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt%4)))
|
chatbot[-1] = (i_say_show_user, f"[Local Message] {mutable[1]}waiting gpt response {cnt}/{TIMEOUT_SECONDS*2*(MAX_RETRY+1)}"+''.join(['.']*(cnt%4)))
|
||||||
yield chatbot, history, '正常'
|
yield chatbot, history, '正常'
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
# 把gpt的输出从mutable中取出来
|
||||||
gpt_say = mutable[0]
|
gpt_say = mutable[0]
|
||||||
return gpt_say
|
return gpt_say
|
||||||
|
|
||||||
@@ -138,3 +143,43 @@ def find_free_port():
|
|||||||
s.bind(('', 0))
|
s.bind(('', 0))
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
return s.getsockname()[1]
|
return s.getsockname()[1]
|
||||||
|
|
||||||
|
|
||||||
|
def extract_archive(file_path, dest_dir):
|
||||||
|
import zipfile
|
||||||
|
import tarfile
|
||||||
|
import os
|
||||||
|
# Get the file extension of the input file
|
||||||
|
file_extension = os.path.splitext(file_path)[1]
|
||||||
|
|
||||||
|
# Extract the archive based on its extension
|
||||||
|
if file_extension == '.zip':
|
||||||
|
with zipfile.ZipFile(file_path, 'r') as zipobj:
|
||||||
|
zipobj.extractall(path=dest_dir)
|
||||||
|
print("Successfully extracted zip archive to {}".format(dest_dir))
|
||||||
|
|
||||||
|
elif file_extension in ['.tar', '.gz', '.bz2']:
|
||||||
|
with tarfile.open(file_path, 'r:*') as tarobj:
|
||||||
|
tarobj.extractall(path=dest_dir)
|
||||||
|
print("Successfully extracted tar archive to {}".format(dest_dir))
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
def find_recent_files(directory):
|
||||||
|
"""
|
||||||
|
me: find files that is created with in one minutes under a directory with python, write a function
|
||||||
|
gpt: here it is!
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
current_time = time.time()
|
||||||
|
one_minute_ago = current_time - 60
|
||||||
|
recent_files = []
|
||||||
|
|
||||||
|
for filename in os.listdir(directory):
|
||||||
|
file_path = os.path.join(directory, filename)
|
||||||
|
created_time = os.path.getctime(file_path)
|
||||||
|
if created_time >= one_minute_ago:
|
||||||
|
recent_files.append(file_path)
|
||||||
|
|
||||||
|
return recent_files
|
||||||