Author SHA1 Message Date
binary-husky 833962cc6d Create docker-image.yml 2023-03-26 20:48:52 +08:00
Your Name 9299c93b17 Merge branch 'test-3-26' 2023-03-26 20:21:39 +08:00
binary-husky 3463a1173a Merge pull request #10 from ifyz/patch-1
Update main.py
2023-03-26 20:21:14 +08:00
Your Name 74eaff4919 fix dockerfile 2023-03-26 20:18:55 +08:00
binary-husky dd51708309 Update main.py 2023-03-26 20:11:44 +08:00
Your Name 25693c362c UI 2023-03-26 20:10:14 +08:00
Your Name 9eb15f5e68 调整样式 2023-03-26 20:04:59 +08:00
Your Name 7e195244f1 up 2023-03-26 19:32:04 +08:00
Your Name 98d97ebbc8 Merge branch 'ifyz-patch-1' into test-3-26 2023-03-26 19:14:49 +08:00
Your Name 6ab3672cfe Merge branch 'patch-1' of https://github.com/ifyz/chatgpt_academic into ifyz-patch-1 2023-03-26 19:14:27 +08:00
Your Name 6f1ad29e3f add comments 2023-03-26 19:13:58 +08:00
ifyz 61c65d90fe Update main.py
使用全局变量,禁用Gradio 的分析功能。解决国内用户因调用GoogleAnalytics导致的加载缓慢。
使用本地字体,修改Gradio默认从Googleapis调用字体。从而解决用户由于国内网络环境打开首页缓慢的问题。
2023-03-26 17:11:58 +08:00
ifyz 8965706169 Update main.py
使用本地字体,修改Gradio默认从Googleapis调用字体。从而解决用户由于国内网络环境打开首页缓慢的问题。
2023-03-26 15:48:16 +08:00
qingxu fu a63ae898ce Merge branch 'master' of https://github.com/binary-husky/chatgpt_academic into master 2023-03-24 21:03:33 +08:00
binary-husky 186f10a3e3 Update README.md 2023-03-24 21:03:09 +08:00
binary-husky 67ed394484 Update README.md 2023-03-24 21:02:02 +08:00
qingxu fu 2f4c46b22c trim button text 2023-03-24 20:56:34 +08:00
binary-husky 2f5c977a27 Update predict.py 2023-03-24 19:54:52 +08:00
binary-husky f801cfbcf6 Update .gitattributes 2023-03-24 19:51:52 +08:00
binary-husky 15693f3f8f Update .gitattributes 2023-03-24 19:50:54 +08:00
binary-husky 8cbac095c1 Create .gitattributes 2023-03-24 19:49:58 +08:00
Your Name 289ace03cf 测试实验性功能 使用说明 2023-03-24 19:47:37 +08:00
Your Name cefc40aff8 update readme 2023-03-24 19:42:21 +08:00
binary-husky 15dd4b7a80 Update README.md 2023-03-24 19:38:33 +08:00
Your Name 5f8473badb source 2023-03-24 19:37:47 +08:00
Your Name a8cfe2f113 remote additional file 2023-03-24 19:35:13 +08:00
Your Name 27e056ea35 move images 2023-03-24 19:34:21 +08:00
binary-husky 278f21fde0 Update README.md 2023-03-24 19:20:43 +08:00
Your Name 121f288878 push 2023-03-24 19:10:34 +08:00
binary-husky 5a6b46f0b5 Update README.md 2023-03-24 19:04:55 +08:00
binary-husky 22766d3c12 Update README.md 2023-03-24 19:03:03 +08:00
16 changed files with 163 additions and 142 deletions
+5
View File
@@ -0,0 +1,5 @@
*.h linguist-detectable=false
*.cpp linguist-detectable=false
*.tex linguist-detectable=false
*.cs linguist-detectable=false
*.tps linguist-detectable=false
+18
View File
@@ -0,0 +1,18 @@
name: Docker Image CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
+1 -5
View File
@@ -1,8 +1,4 @@
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
rm -rf /var/lib/apt/lists/*
FROM python:3.11
RUN echo '[global]' > /etc/pip.conf && \
echo 'index-url = https://mirrors.aliyun.com/pypi/simple/' >> /etc/pip.conf && \
+71 -21
View File
@@ -3,6 +3,7 @@
**如果喜欢这个项目,请给它一个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.
<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++项目
读论文 | [实验性功能] 解读latex论文摘要
批量注释生成 | [实验性功能] 批量生成函数注释
自我程序剖析 | [实验性功能] 一键读懂本项目的源代码
程序剖析 | [实验性功能] 一键可以剖析其他Python/C++项目
读论文 | [实验性功能] 一键解读latex论文全文并生成摘要
批量注释生成 | [实验性功能] 一键批量生成函数注释
chat分析报告生成 | [实验性功能] 运行后自动生成总结汇报
公式显示 | 可以同时显示公式的tex形式和渲染形式
图片显示 | 可以在markdown中显示图片
支持GPT输出的markdown表格 | 可以输出支持GPT的markdown表格
- 支持GPT输出的markdown表格
<div align="center">
<img src="demo2.jpg" width="500" >
</div>
- 如果输出包含公式,会同时以tex形式和渲染形式显示,方便复制和阅读
- 新界面
<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>
- 所有按钮都通过读取functional.py动态生成,可随意加自定义功能,解放粘贴板
<div align="center">
<img src="公式.gif" width="700" >
<img src="img/公式.gif" width="700" >
</div>
- 代码的显示自然也不在话下 https://www.bilibili.com/video/BV1F24y147PD/
<div align="center">
<img src="润色.gif" width="700" >
<img src="img/润色.gif" width="700" >
</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炫嘴里
<div align="center">
<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)
```
``` sh
# 下载项目
git clone https://github.com/binary-husky/chatgpt_academic.git
cd chatgpt_academic
@@ -62,6 +71,18 @@ cd chatgpt_academic
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回答几个数的平方是什么),您可以根据此函数为模板,实现更复杂的功能
点击 "[实验] 实验功能函数模板"
```
@@ -78,6 +99,19 @@ docker build -t 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">
<img src="https://user-images.githubusercontent.com/96192199/226906087-b5f1c127-2060-4db9-af05-487643b21ed9.png" width="500" >
</div>
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226906703-7226495d-6a1f-4a53-9728-ce6778cbdd19.png" width="200" >
<img src="https://user-images.githubusercontent.com/96192199/226906087-b5f1c127-2060-4db9-af05-487643b21ed9.png" height="200" >
<img src="https://user-images.githubusercontent.com/96192199/226906703-7226495d-6a1f-4a53-9728-ce6778cbdd19.png" height="200" >
</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" >
</div>
### 其他任意Python项目剖析:
### 其他任意Python/Cpp项目剖析:
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/226935232-6b6a73ce-8900-4aee-93f9-733c7e6fef53.png" width="800" >
</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" >
</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>
## 参考项目
```
-91
View File
@@ -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.
+6 -6
View File
@@ -9,9 +9,9 @@ def 解析源代码(file_manifest, project_folder, top_p, temperature, chatbot,
with open(fp, 'r', encoding='utf-8') as f:
file_content = f.read()
前言 = "接下来请你逐文件分析下面的工程" if index==0 else ""
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{os.path.relpath(fp, project_folder)},文件代码是 ```{file_content}```'
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
prefix = "接下来请你逐文件分析下面的工程" if index==0 else ""
i_say = prefix + f'请对下面的程序文件做一个概述文件名是{os.path.relpath(fp, project_folder)},文件代码是 ```{file_content}```'
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."))
yield chatbot, history, '正常'
@@ -56,9 +56,9 @@ def 解析项目本身(txt, top_p, temperature, chatbot, history, systemPromptTx
with open(fp, 'r', encoding='utf-8') as f:
file_content = f.read()
前言 = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
i_say = 前言 + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的程序文件做一个概述: {os.path.abspath(fp)}'
prefix = "接下来请你分析自己的程序构成,别紧张," if index==0 else ""
i_say = prefix + f'请对下面的程序文件做一个概述文件名是{fp},文件代码是 ```{file_content}```'
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."))
yield chatbot, history, '正常'
+3 -3
View File
@@ -10,9 +10,9 @@ def 解析Paper(file_manifest, project_folder, top_p, temperature, chatbot, hist
with open(fp, 'r', encoding='utf-8') as f:
file_content = f.read()
前言 = "接下来请你逐文件分析下面的论文文件,概括其内容" if index==0 else ""
i_say = 前言 + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
i_say_show_user = 前言 + f'[{index}/{len(file_manifest)}] 请对下面的文章片段做一个概述: {os.path.abspath(fp)}'
prefix = "接下来请你逐文件分析下面的论文文件,概括其内容" if index==0 else ""
i_say = prefix + f'请对下面的文章片段用中文做一个概述,文件名是{os.path.relpath(fp, project_folder)},文章内容是 ```{file_content}```'
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."))
print('[1] yield chatbot, history')
yield chatbot, history, '正常'
+6 -6
View File
@@ -8,26 +8,26 @@ def get_crazy_functionals():
from crazy_functions.高级功能函数模板 import 高阶功能模板函数
return {
"[实验功能] 请解析并解构此项目本身": {
"[实验] 请解析并解构此项目本身": {
"Function": 解析项目本身
},
"[实验功能] 解析整个Python项目(input输入项目根路径)": {
"[实验] 解析整个py项目(input输入项目根路径)": {
"Color": "stop", # 按钮颜色
"Function": 解析一个Python项目
},
"[实验功能] 解析整个C++项目的头文件input输入项目根路径)": {
"[实验] 解析整个C++项目(input输入项目根路径)": {
"Color": "stop", # 按钮颜色
"Function": 解析一个C项目的头文件
},
"[实验功能] 解读latex论文写摘要(input输入项目根路径)": {
"[实验] 读tex论文写摘要(input输入项目根路径)": {
"Color": "stop", # 按钮颜色
"Function": 读文章写摘要
},
"[实验功能] 批量生成函数注释(input输入项目根路径)": {
"[实验] 批量生成函数注释(input输入项目根路径)": {
"Color": "stop", # 按钮颜色
"Function": 批量生成函数注释
},
"[实验功能] 实验功能函数模板": {
"[实验] 实验功能函数模板": {
"Color": "stop", # 按钮颜色
"Function": 高阶功能模板函数
},
View File

Before

Width:  |  Height:  |  Size: 262 KiB

After

Width:  |  Height:  |  Size: 262 KiB

View File

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 264 KiB

View File

Before

Width:  |  Height:  |  Size: 11 MiB

After

Width:  |  Height:  |  Size: 11 MiB

View File

Before

Width:  |  Height:  |  Size: 12 MiB

After

Width:  |  Height:  |  Size: 12 MiB

+19 -7
View File
@@ -1,32 +1,44 @@
import os; os.environ['no_proxy'] = '*'
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
import gradio as gr
from predict import predict
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
# 如果WEB_PORT是-1,则随机选取WEB端口
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
initial_prompt = "Serve me as a writing and programming assistant."
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
# 问询记录,python 版本建议3.9+(越新越好)
import logging
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,请注意自我隐私保护哦!')
# 一些普通功能
# 一些普通功能模块
from functional import get_functionals
functional = get_functionals()
# 对一些丧心病狂的实验性功能进行测试
# 对一些丧心病狂的实验性功能模块进行测试
from functional_crazy import get_crazy_functionals
crazy_functional = get_crazy_functionals()
# 处理markdown文本格式的转变
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)
with gr.Row():
with gr.Column(scale=2):
@@ -66,7 +78,7 @@ with gr.Blocks() as demo:
crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
[txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay])
# 延迟函数,做一些准备工作,最后尝试打开浏览器
def auto_opentab_delay():
import threading, webbrowser, time
print(f"URL http://localhost:{PORT}")
+25 -2
View File
@@ -6,7 +6,6 @@ import logging
import traceback
import requests
import importlib
from colorful import *
# config_private.py放自己的秘密如API和代理网址
# 读取时首先看是否存在私密的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.'
def get_full_error(chunk, stream_response):
"""
获取完整的从Openai返回的报错
"""
while True:
try:
chunk += next(stream_response)
@@ -24,6 +26,16 @@ def get_full_error(chunk, stream_response):
return chunk
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)
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='',
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:
import functional
importlib.reload(functional)
@@ -116,6 +136,9 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
return
def generate_payload(inputs, top_p, temperature, history, system_prompt, stream):
"""
整合所有信息选择LLM模型生成http请求为发送请求做准备
"""
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
+6 -1
View File
@@ -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
except: from config import TIMEOUT_SECONDS, MAX_RETRY
from predict import predict_no_ui
# 多线程的时候,需要一个mutable结构在不同线程之间传递信息
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
mutable = [None, '']
# multi-threading worker
def mt(i_say, history):
while True:
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. '
except TimeoutError as e:
mutable[0] = '[Local Message] Failed with timeout'
# 创建新线程发出http请求
thread_name = threading.Thread(target=mt, args=(i_say, history)); thread_name.start()
# 原来的线程则负责持续更新UI,实现一个超时倒计时,并等待新线程的任务完成
cnt = 0
while thread_name.is_alive():
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)))
yield chatbot, history, '正常'
time.sleep(1)
# 把gpt的输出从mutable中取出来
gpt_say = mutable[0]
return gpt_say