镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-07 15:06:48 +00:00
plugin refactor: phase 1
这个提交包含在:
@@ -1525,8 +1525,103 @@ async function postData(url = '', data = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function generate_menu(guiBase64String, btnName){
|
||||
// assign the button and menu data
|
||||
push_data_to_gradio_component(guiBase64String, "invisible_current_pop_up_plugin_arg", "string");
|
||||
push_data_to_gradio_component(btnName, "invisible_callback_btn_for_plugin_exe", "string");
|
||||
|
||||
// Base64 to dict
|
||||
const stringData = atob(guiBase64String);
|
||||
let guiJsonData = JSON.parse(stringData);
|
||||
let menu = document.getElementById("plugin_arg_menu");
|
||||
gui_args = {}
|
||||
for (const key in guiJsonData) {
|
||||
if (guiJsonData.hasOwnProperty(key)) {
|
||||
const innerJSONString = guiJsonData[key];
|
||||
const decodedObject = JSON.parse(innerJSONString);
|
||||
gui_args[key] = decodedObject;
|
||||
}
|
||||
}
|
||||
|
||||
// 使参数菜单显现
|
||||
push_data_to_gradio_component({
|
||||
visible: true,
|
||||
__type__: 'update'
|
||||
}, "plugin_arg_menu", "obj");
|
||||
|
||||
// 根据 gui_args,使得对应参数项显现
|
||||
let text_cnt = 0;
|
||||
for (const key in gui_args) {
|
||||
if (gui_args.hasOwnProperty(key)) {
|
||||
const component_name = "plugin_arg_txt_" + text_cnt;
|
||||
if (gui_args[key].type=='string'){
|
||||
push_data_to_gradio_component({
|
||||
visible: true,
|
||||
label: gui_args[key].title + "(" + gui_args[key].description + ")",
|
||||
__type__: 'update'
|
||||
}, component_name, "obj");
|
||||
if (key === "main_input"){
|
||||
// 为了与旧插件兼容,生成菜单时,自动加载输入栏的值
|
||||
let current_main_input = await get_data_from_gradio_component('user_input_main');
|
||||
let current_main_input_2 = await get_data_from_gradio_component('user_input_float');
|
||||
push_data_to_gradio_component(current_main_input + current_main_input_2, component_name, "obj");
|
||||
}
|
||||
else if (key === "advanced_arg"){
|
||||
// 为了与旧插件兼容,生成菜单时,自动加载旧高级参数输入区的值
|
||||
let advance_arg_input_legacy = await get_data_from_gradio_component('advance_arg_input_legacy');
|
||||
push_data_to_gradio_component(advance_arg_input_legacy, component_name, "obj");
|
||||
}
|
||||
else {
|
||||
push_data_to_gradio_component(gui_args[key].default_value, component_name, "obj");
|
||||
}
|
||||
text_cnt += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function execute_current_pop_up_plugin(){
|
||||
let guiBase64String = await get_data_from_gradio_component('invisible_current_pop_up_plugin_arg');
|
||||
const stringData = atob(guiBase64String);
|
||||
let guiJsonData = JSON.parse(stringData);
|
||||
gui_args = {}
|
||||
for (const key in guiJsonData) {
|
||||
if (guiJsonData.hasOwnProperty(key)) {
|
||||
const innerJSONString = guiJsonData[key];
|
||||
const decodedObject = JSON.parse(innerJSONString);
|
||||
gui_args[key] = decodedObject;
|
||||
}
|
||||
}
|
||||
// read user confirmed value
|
||||
let text_cnt = 0;
|
||||
for (const key in gui_args) {
|
||||
if (gui_args.hasOwnProperty(key)) {
|
||||
if (gui_args[key].type=='string'){
|
||||
corrisponding_elem_id = "plugin_arg_txt_"+text_cnt
|
||||
gui_args[key].user_confirmed_value = await get_data_from_gradio_component(corrisponding_elem_id);
|
||||
text_cnt += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close menu
|
||||
push_data_to_gradio_component({
|
||||
visible: false,
|
||||
__type__: 'update'
|
||||
}, "plugin_arg_menu", "obj");
|
||||
for (text_cnt = 0; text_cnt < 8; text_cnt++){
|
||||
push_data_to_gradio_component({
|
||||
visible: false,
|
||||
label: "",
|
||||
__type__: 'update'
|
||||
}, "plugin_arg_txt_"+text_cnt, "obj");
|
||||
}
|
||||
|
||||
// execute the plugin
|
||||
push_data_to_gradio_component(JSON.stringify(gui_args), "invisible_current_pop_up_plugin_arg_final", "string");
|
||||
document.getElementById("invisible_callback_btn_for_plugin_exe").click();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户