交互优化
This commit is contained in:
parent
639e24fc82
commit
3c95299f48
@ -16,15 +16,13 @@ if USE_PROXY:
|
|||||||
"http": "socks5h://localhost:11284",
|
"http": "socks5h://localhost:11284",
|
||||||
"https": "socks5h://localhost:11284",
|
"https": "socks5h://localhost:11284",
|
||||||
}
|
}
|
||||||
print('网络代理状态:运行。')
|
|
||||||
else:
|
else:
|
||||||
proxies = None
|
proxies = None
|
||||||
print('网络代理状态:未配置。无代理状态下很可能无法访问。')
|
|
||||||
|
|
||||||
|
|
||||||
# [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
|
# [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
|
||||||
# 对话窗的高度
|
# 对话窗的高度
|
||||||
CHATBOT_HEIGHT = 1117
|
CHATBOT_HEIGHT = 1116
|
||||||
|
|
||||||
# 发送请求到OpenAI后,等待多久判定为超时
|
# 发送请求到OpenAI后,等待多久判定为超时
|
||||||
TIMEOUT_SECONDS = 25
|
TIMEOUT_SECONDS = 25
|
||||||
|
@ -18,7 +18,7 @@ def get_crazy_functionals():
|
|||||||
from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文
|
from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文
|
||||||
|
|
||||||
function_plugins = {
|
function_plugins = {
|
||||||
"请解析并解构此项目本身": {
|
"请解析并解构此项目本身(源码自译解)": {
|
||||||
"AsButton": False, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": 解析项目本身
|
"Function": 解析项目本身
|
||||||
},
|
},
|
||||||
@ -30,7 +30,7 @@ def get_crazy_functionals():
|
|||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"Function": 解析一个C项目的头文件
|
"Function": 解析一个C项目的头文件
|
||||||
},
|
},
|
||||||
"解析整个C++项目": {
|
"解析整个C++项目(.cpp/.h)": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
"AsButton": False, # 加入下拉菜单中
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": 解析一个C项目
|
"Function": 解析一个C项目
|
||||||
|
8
main.py
8
main.py
@ -54,7 +54,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de
|
|||||||
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
from check_proxy import check_proxy
|
from check_proxy import check_proxy
|
||||||
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
|
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
|
||||||
with gr.Accordion("基础功能区", open=True) as area_basic_fn:
|
with gr.Accordion("基础功能区", open=True) as area_basic_fn:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
for k in functional:
|
for k in functional:
|
||||||
@ -93,8 +93,8 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de
|
|||||||
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn] )
|
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn] )
|
||||||
# 整理反复出现的控件句柄组合
|
# 整理反复出现的控件句柄组合
|
||||||
input_combo = [txt, top_p, temperature, chatbot, history, system_prompt]
|
input_combo = [txt, top_p, temperature, chatbot, history, system_prompt]
|
||||||
output_combo = [chatbot, history, statusDisplay]
|
output_combo = [chatbot, history, status]
|
||||||
predict_args = dict(fn=predict, inputs=input_combo, outputs=output_combo, show_progress=True)
|
predict_args = dict(fn=predict, inputs=input_combo, outputs=output_combo)
|
||||||
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
|
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
|
||||||
# 提交按钮、重置按钮
|
# 提交按钮、重置按钮
|
||||||
cancel_handles.append(txt.submit(**predict_args)) #; txt.submit(**empty_txt_args) 在提交后清空输入栏
|
cancel_handles.append(txt.submit(**predict_args)) #; txt.submit(**empty_txt_args) 在提交后清空输入栏
|
||||||
@ -102,7 +102,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de
|
|||||||
resetBtn.click(lambda: ([], [], "已重置"), None, output_combo)
|
resetBtn.click(lambda: ([], [], "已重置"), None, output_combo)
|
||||||
# 基础功能区的回调函数注册
|
# 基础功能区的回调函数注册
|
||||||
for k in functional:
|
for k in functional:
|
||||||
click_handle = functional[k]["Button"].click(predict, [*input_combo, gr.State(True), gr.State(k)], output_combo, show_progress=True)
|
click_handle = functional[k]["Button"].click(predict, [*input_combo, gr.State(True), gr.State(k)], output_combo)
|
||||||
cancel_handles.append(click_handle)
|
cancel_handles.append(click_handle)
|
||||||
# 文件上传区,接收文件后与chatbot的互动
|
# 文件上传区,接收文件后与chatbot的互动
|
||||||
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
||||||
|
35
toolbox.py
35
toolbox.py
@ -1,6 +1,6 @@
|
|||||||
import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect, re
|
import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect, re
|
||||||
from show_math import convert as convert_math
|
from show_math import convert as convert_math
|
||||||
from functools import wraps
|
from functools import wraps, lru_cache
|
||||||
|
|
||||||
def get_reduce_token_percent(text):
|
def get_reduce_token_percent(text):
|
||||||
try:
|
try:
|
||||||
@ -289,22 +289,33 @@ def on_report_generated(files, chatbot):
|
|||||||
chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧“文件上传区”(可能处于折叠状态),请查收。'])
|
chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧“文件上传区”(可能处于折叠状态),请查收。'])
|
||||||
return report_files, chatbot
|
return report_files, chatbot
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def read_single_conf_with_lru_cache(arg):
|
||||||
|
try: r = getattr(importlib.import_module('config_private'), arg)
|
||||||
|
except: r = getattr(importlib.import_module('config'), arg)
|
||||||
|
# 在读取API_KEY时,检查一下是不是忘了改config
|
||||||
|
if arg=='API_KEY':
|
||||||
|
# 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合
|
||||||
|
API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
|
||||||
|
if API_MATCH:
|
||||||
|
print(f"[API_KEY] 您的 API_KEY 是: {r[:15]}*** API_KEY 导入成功")
|
||||||
|
else:
|
||||||
|
assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
|
||||||
|
"(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
|
||||||
|
if arg=='proxies':
|
||||||
|
if r is None:
|
||||||
|
print('[PROXY] 网络代理状态:未配置。无代理状态下很可能无法访问。建议:检查USE_PROXY选项是否修改。')
|
||||||
|
else:
|
||||||
|
print('[PROXY] 网络代理状态:已配置。配置信息如下:', r)
|
||||||
|
assert isinstance(r, dict), 'proxies格式错误,请注意proxies选项的格式,不要遗漏括号。'
|
||||||
|
return r
|
||||||
|
|
||||||
def get_conf(*args):
|
def get_conf(*args):
|
||||||
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
||||||
res = []
|
res = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
try: r = getattr(importlib.import_module('config_private'), arg)
|
r = read_single_conf_with_lru_cache(arg)
|
||||||
except: r = getattr(importlib.import_module('config'), arg)
|
|
||||||
res.append(r)
|
res.append(r)
|
||||||
# 在读取API_KEY时,检查一下是不是忘了改config
|
|
||||||
if arg=='API_KEY':
|
|
||||||
# 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合
|
|
||||||
API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
|
|
||||||
if API_MATCH:
|
|
||||||
print(f"您的 API_KEY 是: {r[:15]}*** \nAPI_KEY 导入成功")
|
|
||||||
else:
|
|
||||||
assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
|
|
||||||
"(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def clear_line_break(txt):
|
def clear_line_break(txt):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user