diff --git a/crazy_functional.py b/crazy_functional.py index 0629ab8f..1092b7bf 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -2,7 +2,6 @@ from toolbox import HotReload # HotReload 的意思是热更新,修改函数 from toolbox import trimmed_format_exc from loguru import logger - def get_crazy_functions(): from crazy_functions.读文章写摘要 import 读文章写摘要 from crazy_functions.生成函数注释 import 批量生成函数注释 @@ -728,12 +727,6 @@ def get_crazy_functions(): logger.error("Load function plugin failed") - - - - - - # try: # from crazy_functions.高级功能函数模板 import 测试图表渲染 # function_plugins.update({ @@ -748,19 +741,6 @@ def get_crazy_functions(): # logger.error(trimmed_format_exc()) # print('Load function plugin failed') - # try: - # from crazy_functions.chatglm微调工具 import 微调数据集生成 - # function_plugins.update({ - # "黑盒模型学习: 微调数据集生成 (先上传数据集)": { - # "Color": "stop", - # "AsButton": False, - # "AdvancedArgs": True, - # "ArgsReminder": "针对数据集输入(如 绿帽子*深蓝色衬衫*黑色运动裤)给出指令,例如您可以将以下命令复制到下方: --llm_to_learn=azure-gpt-3.5 --prompt_prefix='根据下面的服装类型提示,想象一个穿着者,对这个人外貌、身处的环境、内心世界、过去经历进行描写。要求:100字以内,用第二人称。' --system_prompt=''", - # "Function": HotReload(微调数据集生成) - # } - # }) - # except: - # print('Load function plugin failed') """ 设置默认值: @@ -780,3 +760,23 @@ def get_crazy_functions(): function_plugins[name]["Color"] = "secondary" return function_plugins + + + + +def get_multiplex_button_functions(): + """多路复用主提交按钮的功能映射 + """ + return { + "常规对话": + "", + + "多模型对话": + "询问多个GPT模型", # 映射到上面的 `询问多个GPT模型` 插件 + + "智能召回 RAG": + "Rag智能召回", # 映射到上面的 `Rag智能召回` 插件 + + "多媒体查询": + "多媒体智能体", # 映射到上面的 `多媒体智能体` 插件 + } diff --git a/main.py b/main.py index 328402ac..dd23d49b 100644 --- a/main.py +++ b/main.py @@ -68,7 +68,7 @@ def main(): functional = get_core_functions() # 高级函数插件 - from crazy_functional import get_crazy_functions + from crazy_functional import get_crazy_functions, get_multiplex_button_functions DEFAULT_FN_GROUPS = get_conf('DEFAULT_FN_GROUPS') plugins = get_crazy_functions() all_plugin_groups = list(set([g for _, plugin in plugins.items() for g in plugin['Group'].split('|')])) @@ -114,12 +114,7 @@ def main(): with gr.Row(elem_id="gpt-submit-row"): multiplex_submit_btn = gr.Button("提交", elem_id="elem_submit_visible", variant="primary") multiplex_sel = gr.Dropdown( - choices=[ - "常规对话", - "多模型对话", - "智能召回 RAG", - # "智能上下文", - ], value="常规对话", + choices=get_multiplex_button_functions().keys(), value="常规对话", interactive=True, label='', show_label=False, elem_classes='normal_mut_select', elem_id="gpt-submit-dropdown").style(container=False) submit_btn = gr.Button("提交", elem_id="elem_submit", variant="primary", visible=False) diff --git a/themes/common.js b/themes/common.js index babbe232..c0b794cf 100644 --- a/themes/common.js +++ b/themes/common.js @@ -1349,16 +1349,9 @@ async function multiplex_function_begin(multiplex_sel) { click_real_submit_btn(); return; } - if (multiplex_sel === "多模型对话") { - let _align_name_in_crazy_function_py = "询问多个GPT模型"; - call_plugin_via_name(_align_name_in_crazy_function_py); - return; - } - if (multiplex_sel === "智能召回 RAG") { - let _align_name_in_crazy_function_py = "Rag智能召回"; - call_plugin_via_name(_align_name_in_crazy_function_py); - return; - } + + // do not delete `REPLACE_EXTENDED_MULTIPLEX_FUNCTIONS_HERE`! It will be read and replaced by Python code. + // REPLACE_EXTENDED_MULTIPLEX_FUNCTIONS_HERE } async function run_multiplex_shift(multiplex_sel){ let key = multiplex_sel; diff --git a/themes/common.py b/themes/common.py index 0b7b5bcc..dc9b0575 100644 --- a/themes/common.py +++ b/themes/common.py @@ -2,6 +2,25 @@ from functools import lru_cache from toolbox import get_conf CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf("CODE_HIGHLIGHT", "ADD_WAIFU", "LAYOUT") +def inject_mutex_button_code(js_content): + from crazy_functional import get_multiplex_button_functions + fns = get_multiplex_button_functions() + + template = """ + if (multiplex_sel === "{x}") { + let _align_name_in_crazy_function_py = "{y}"; + call_plugin_via_name(_align_name_in_crazy_function_py); + return; + } + """ + + replacement = "" + for fn in fns.keys(): + if fn == "常规对话": continue + replacement += template.replace("{x}", fn).replace("{y}", fns[fn]) + js_content = js_content.replace("// REPLACE_EXTENDED_MULTIPLEX_FUNCTIONS_HERE", replacement) + return js_content + def minimize_js(common_js_path): try: import rjsmin, hashlib, glob, os @@ -12,6 +31,8 @@ def minimize_js(common_js_path): c_jsmin = rjsmin.jsmin with open(common_js_path, "r") as f: js_content = f.read() + if common_js_path == "themes/common.js": + js_content = inject_mutex_button_code(js_content) minimized_js_content = c_jsmin(js_content) # compute sha256 hash of minimized js content sha_hash = hashlib.sha256(minimized_js_content.encode()).hexdigest()[:8]