Spaces:
Sleeping
Sleeping
Merge pull request #194 from fulyaec/enhance-chataca
Browse files修改AUTHENTICATION的判断,使得AUTHENTICATION为None/[]/""时都可以正确判断
- functional_crazy.py +10 -3
- main.py +2 -3
- project_self_analysis.md +2 -2
- toolbox.py +12 -1
functional_crazy.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
|
|
|
|
|
| 1 |
# UserVisibleLevel是过滤器参数。
|
| 2 |
# 由于UI界面空间有限,所以通过这种方式决定UI界面中显示哪些插件
|
| 3 |
# 默认函数插件 VisibleLevel 是 0
|
| 4 |
# 当 UserVisibleLevel >= 函数插件的 VisibleLevel 时,该函数插件才会被显示出来
|
| 5 |
UserVisibleLevel = 1
|
| 6 |
|
|
|
|
| 7 |
def get_crazy_functionals():
|
| 8 |
from crazy_functions.读文章写摘要 import 读文章写摘要
|
| 9 |
from crazy_functions.生成函数注释 import 批量生成函数注释
|
|
@@ -16,6 +19,7 @@ def get_crazy_functionals():
|
|
| 16 |
|
| 17 |
function_plugins = {
|
| 18 |
"请解析并解构此项目本身": {
|
|
|
|
| 19 |
"Function": 解析项目本身
|
| 20 |
},
|
| 21 |
"解析整个py项目": {
|
|
@@ -39,10 +43,12 @@ def get_crazy_functionals():
|
|
| 39 |
"Function": 批量生成函数注释
|
| 40 |
},
|
| 41 |
"[多线程demo] 把本项目源代码切换成全英文": {
|
| 42 |
-
|
|
|
|
| 43 |
},
|
| 44 |
"[函数插件模板demo] 历史上的今天": {
|
| 45 |
-
|
|
|
|
| 46 |
},
|
| 47 |
}
|
| 48 |
|
|
@@ -52,7 +58,8 @@ def get_crazy_functionals():
|
|
| 52 |
function_plugins.update({
|
| 53 |
"[仅供开发调试] 批量总结PDF文档": {
|
| 54 |
"Color": "stop",
|
| 55 |
-
|
|
|
|
| 56 |
},
|
| 57 |
})
|
| 58 |
|
|
|
|
| 1 |
+
from functools import HotReload # HotReload 的意思是热更新,修改函数插件后,不需要重启程序,代码直接生效
|
| 2 |
+
|
| 3 |
# UserVisibleLevel是过滤器参数。
|
| 4 |
# 由于UI界面空间有限,所以通过这种方式决定UI界面中显示哪些插件
|
| 5 |
# 默认函数插件 VisibleLevel 是 0
|
| 6 |
# 当 UserVisibleLevel >= 函数插件的 VisibleLevel 时,该函数插件才会被显示出来
|
| 7 |
UserVisibleLevel = 1
|
| 8 |
|
| 9 |
+
|
| 10 |
def get_crazy_functionals():
|
| 11 |
from crazy_functions.读文章写摘要 import 读文章写摘要
|
| 12 |
from crazy_functions.生成函数注释 import 批量生成函数注释
|
|
|
|
| 19 |
|
| 20 |
function_plugins = {
|
| 21 |
"请解析并解构此项目本身": {
|
| 22 |
+
# HotReload 的意思是热更新,修改函数插件后,不需要重启程序,代码直接生效
|
| 23 |
"Function": 解析项目本身
|
| 24 |
},
|
| 25 |
"解析整个py项目": {
|
|
|
|
| 43 |
"Function": 批量生成函数注释
|
| 44 |
},
|
| 45 |
"[多线程demo] 把本项目源代码切换成全英文": {
|
| 46 |
+
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
| 47 |
+
"Function": HotReload(全项目切换英文)
|
| 48 |
},
|
| 49 |
"[函数插件模板demo] 历史上的今天": {
|
| 50 |
+
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
| 51 |
+
"Function": HotReload(高阶功能模板函数)
|
| 52 |
},
|
| 53 |
}
|
| 54 |
|
|
|
|
| 58 |
function_plugins.update({
|
| 59 |
"[仅供开发调试] 批量总结PDF文档": {
|
| 60 |
"Color": "stop",
|
| 61 |
+
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
| 62 |
+
"Function": HotReload(批量总结PDF文档)
|
| 63 |
},
|
| 64 |
})
|
| 65 |
|
main.py
CHANGED
|
@@ -10,7 +10,7 @@ proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = \
|
|
| 10 |
|
| 11 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
| 12 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
| 13 |
-
|
| 14 |
|
| 15 |
initial_prompt = "Serve me as a writing and programming assistant."
|
| 16 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
|
@@ -105,8 +105,7 @@ def auto_opentab_delay():
|
|
| 105 |
def open():
|
| 106 |
time.sleep(2)
|
| 107 |
webbrowser.open_new_tab(f'http://localhost:{PORT}')
|
| 108 |
-
|
| 109 |
-
t.daemon = True; t.start()
|
| 110 |
|
| 111 |
auto_opentab_delay()
|
| 112 |
demo.title = "ChatGPT 学术优化"
|
|
|
|
| 10 |
|
| 11 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
| 12 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
| 13 |
+
if not AUTHENTICATION: AUTHENTICATION = None
|
| 14 |
|
| 15 |
initial_prompt = "Serve me as a writing and programming assistant."
|
| 16 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
|
|
|
| 105 |
def open():
|
| 106 |
time.sleep(2)
|
| 107 |
webbrowser.open_new_tab(f'http://localhost:{PORT}')
|
| 108 |
+
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
|
|
|
| 109 |
|
| 110 |
auto_opentab_delay()
|
| 111 |
demo.title = "ChatGPT 学术优化"
|
project_self_analysis.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
# chatgpt-academic
|
| 2 |
-
(Author补充:以下分析均由本项目调用ChatGPT
|
| 3 |
|
| 4 |
## [0/10] 程序摘要: check_proxy.py
|
| 5 |
|
|
|
|
| 1 |
+
# chatgpt-academic项目自译解报告
|
| 2 |
+
(Author补充:以下分析均由本项目调用ChatGPT一键生成,如果有不准确的地方,全怪GPT😄)
|
| 3 |
|
| 4 |
## [0/10] 程序摘要: check_proxy.py
|
| 5 |
|
toolbox.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import markdown, mdtex2html, threading, importlib, traceback
|
| 2 |
from show_math import convert as convert_math
|
| 3 |
from functools import wraps
|
| 4 |
import re
|
|
@@ -89,6 +89,17 @@ def CatchException(f):
|
|
| 89 |
yield chatbot, history, f'异常 {e}'
|
| 90 |
return decorated
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
def report_execption(chatbot, history, a, b):
|
| 93 |
"""
|
| 94 |
向chatbot中添加错误信息
|
|
|
|
| 1 |
+
import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect
|
| 2 |
from show_math import convert as convert_math
|
| 3 |
from functools import wraps
|
| 4 |
import re
|
|
|
|
| 89 |
yield chatbot, history, f'异常 {e}'
|
| 90 |
return decorated
|
| 91 |
|
| 92 |
+
def HotReload(f):
|
| 93 |
+
"""
|
| 94 |
+
装饰器函数,实现函数插件热更新
|
| 95 |
+
"""
|
| 96 |
+
@wraps(f)
|
| 97 |
+
def decorated(*args, **kwargs):
|
| 98 |
+
fn_name = f.__name__
|
| 99 |
+
f_hot_reload = getattr(importlib.reload(inspect.getmodule(f)), fn_name)
|
| 100 |
+
yield from f_hot_reload(*args, **kwargs)
|
| 101 |
+
return decorated
|
| 102 |
+
|
| 103 |
def report_execption(chatbot, history, a, b):
|
| 104 |
"""
|
| 105 |
向chatbot中添加错误信息
|