Spaces:
Runtime error
Runtime error
更正部分注释
Browse files- toolbox.py +25 -4
- version +1 -1
toolbox.py
CHANGED
|
@@ -8,11 +8,14 @@ from functools import wraps, lru_cache
|
|
| 8 |
|
| 9 |
"""
|
| 10 |
========================================================================
|
|
|
|
| 11 |
函数插件输入输出接驳区
|
| 12 |
- ChatBotWithCookies: 带Cookies的Chatbot类,为实现更多强大的功能做基础
|
| 13 |
- ArgsGeneralWrapper: 装饰器函数,用于重组输入参数,改变输入参数的顺序与结构
|
| 14 |
- update_ui: 刷新界面用 yield from update_ui(chatbot, history)
|
| 15 |
- CatchException: 将插件中出的所有问题显示在界面上
|
|
|
|
|
|
|
| 16 |
========================================================================
|
| 17 |
"""
|
| 18 |
|
|
@@ -112,9 +115,22 @@ def HotReload(f):
|
|
| 112 |
yield from f_hot_reload(*args, **kwargs)
|
| 113 |
return decorated
|
| 114 |
|
|
|
|
| 115 |
"""
|
| 116 |
========================================================================
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
========================================================================
|
| 119 |
"""
|
| 120 |
|
|
@@ -391,6 +407,9 @@ def find_recent_files(directory):
|
|
| 391 |
|
| 392 |
|
| 393 |
def on_file_uploaded(files, chatbot, txt, txt2, checkboxes):
|
|
|
|
|
|
|
|
|
|
| 394 |
if len(files) == 0:
|
| 395 |
return chatbot, txt
|
| 396 |
import shutil
|
|
@@ -410,8 +429,7 @@ def on_file_uploaded(files, chatbot, txt, txt2, checkboxes):
|
|
| 410 |
shutil.copy(file.name, f'private_upload/{time_tag}/{file_origin_name}')
|
| 411 |
err_msg += extract_archive(f'private_upload/{time_tag}/{file_origin_name}',
|
| 412 |
dest_dir=f'private_upload/{time_tag}/{file_origin_name}.extract')
|
| 413 |
-
moved_files = [fp for fp in glob.glob(
|
| 414 |
-
'private_upload/**/*', recursive=True)]
|
| 415 |
if "底部输入区" in checkboxes:
|
| 416 |
txt = ""
|
| 417 |
txt2 = f'private_upload/{time_tag}'
|
|
@@ -530,7 +548,7 @@ def clear_line_break(txt):
|
|
| 530 |
class DummyWith():
|
| 531 |
"""
|
| 532 |
这段代码定义了一个名为DummyWith的空上下文管理器,
|
| 533 |
-
|
| 534 |
上下文管理器是一种Python对象,用于与with语句一起使用,
|
| 535 |
以确保一些资源在代码块执行期间得到正确的初始化和清理。
|
| 536 |
上下文管理器必须实现两个方法,分别为 __enter__()和 __exit__()。
|
|
@@ -544,6 +562,9 @@ class DummyWith():
|
|
| 544 |
return
|
| 545 |
|
| 546 |
def run_gradio_in_subpath(demo, auth, port, custom_path):
|
|
|
|
|
|
|
|
|
|
| 547 |
def is_path_legal(path: str)->bool:
|
| 548 |
'''
|
| 549 |
check path for sub url
|
|
|
|
| 8 |
|
| 9 |
"""
|
| 10 |
========================================================================
|
| 11 |
+
第一部分
|
| 12 |
函数插件输入输出接驳区
|
| 13 |
- ChatBotWithCookies: 带Cookies的Chatbot类,为实现更多强大的功能做基础
|
| 14 |
- ArgsGeneralWrapper: 装饰器函数,用于重组输入参数,改变输入参数的顺序与结构
|
| 15 |
- update_ui: 刷新界面用 yield from update_ui(chatbot, history)
|
| 16 |
- CatchException: 将插件中出的所有问题显示在界面上
|
| 17 |
+
- HotReload: 实现插件的热更新
|
| 18 |
+
- trimmed_format_exc: 打印traceback,为了安全而隐藏绝对地址
|
| 19 |
========================================================================
|
| 20 |
"""
|
| 21 |
|
|
|
|
| 115 |
yield from f_hot_reload(*args, **kwargs)
|
| 116 |
return decorated
|
| 117 |
|
| 118 |
+
|
| 119 |
"""
|
| 120 |
========================================================================
|
| 121 |
+
第二部分
|
| 122 |
+
其他小工具:
|
| 123 |
+
- write_results_to_file: 将结果写入markdown文件中
|
| 124 |
+
- regular_txt_to_markdown: 将普通文本转换为Markdown格式的文本。
|
| 125 |
+
- report_execption: 向chatbot中添加简单的意外错误信息
|
| 126 |
+
- text_divide_paragraph: 将文本按照段落分隔符分割开,生成带有段落标签的HTML代码。
|
| 127 |
+
- markdown_convertion: 用多种方式组合,将markdown转化为好看的html
|
| 128 |
+
- format_io: 接管gradio默认的markdown处理方式
|
| 129 |
+
- on_file_uploaded: 处理文件的上传(自动解压)
|
| 130 |
+
- on_report_generated: 将生成的报告自动投射到文件上传区
|
| 131 |
+
- clip_history: 当历史上下文过长时,自动截断
|
| 132 |
+
- get_conf: 获取设置
|
| 133 |
+
- select_api_key: 根据当前的模型类别,抽取可用的api-key
|
| 134 |
========================================================================
|
| 135 |
"""
|
| 136 |
|
|
|
|
| 407 |
|
| 408 |
|
| 409 |
def on_file_uploaded(files, chatbot, txt, txt2, checkboxes):
|
| 410 |
+
"""
|
| 411 |
+
当文件被上传时的回调函数
|
| 412 |
+
"""
|
| 413 |
if len(files) == 0:
|
| 414 |
return chatbot, txt
|
| 415 |
import shutil
|
|
|
|
| 429 |
shutil.copy(file.name, f'private_upload/{time_tag}/{file_origin_name}')
|
| 430 |
err_msg += extract_archive(f'private_upload/{time_tag}/{file_origin_name}',
|
| 431 |
dest_dir=f'private_upload/{time_tag}/{file_origin_name}.extract')
|
| 432 |
+
moved_files = [fp for fp in glob.glob('private_upload/**/*', recursive=True)]
|
|
|
|
| 433 |
if "底部输入区" in checkboxes:
|
| 434 |
txt = ""
|
| 435 |
txt2 = f'private_upload/{time_tag}'
|
|
|
|
| 548 |
class DummyWith():
|
| 549 |
"""
|
| 550 |
这段代码定义了一个名为DummyWith的空上下文管理器,
|
| 551 |
+
它的作用是……额……就是不起作用,即在代码结构不变得情况下取代其他的上下文管理器。
|
| 552 |
上下文管理器是一种Python对象,用于与with语句一起使用,
|
| 553 |
以确保一些资源在代码块执行期间得到正确的初始化和清理。
|
| 554 |
上下文管理器必须实现两个方法,分别为 __enter__()和 __exit__()。
|
|
|
|
| 562 |
return
|
| 563 |
|
| 564 |
def run_gradio_in_subpath(demo, auth, port, custom_path):
|
| 565 |
+
"""
|
| 566 |
+
把gradio的运行地址更改到指定的二次路径上
|
| 567 |
+
"""
|
| 568 |
def is_path_legal(path: str)->bool:
|
| 569 |
'''
|
| 570 |
check path for sub url
|
version
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"version": 3.
|
| 3 |
"show_feature": true,
|
| 4 |
"new_feature": "保存对话功能 <-> 解读任意语言代码+同时询问任意的LLM组合 <-> 添加联网(Google)回答问题插件 <-> 修复ChatGLM上下文BUG <-> 添加支持清华ChatGLM和GPT-4 <-> 改进架构,支持与多个LLM模型同时对话 <-> 添加支持API2D(国内,可支持gpt4)"
|
| 5 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"version": 3.3,
|
| 3 |
"show_feature": true,
|
| 4 |
"new_feature": "保存对话功能 <-> 解读任意语言代码+同时询问任意的LLM组合 <-> 添加联网(Google)回答问题插件 <-> 修复ChatGLM上下文BUG <-> 添加支持清华ChatGLM和GPT-4 <-> 改进架构,支持与多个LLM模型同时对话 <-> 添加支持API2D(国内,可支持gpt4)"
|
| 5 |
}
|