镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 14:36:48 +00:00
Version 3.74: Merge latest updates on dev branch (frontier) (#1621)
* Update version to 3.74 * Add support for Yi Model API (#1635) * 更新以支持零一万物模型 * 删除newbing * 修改config --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * Refactor function signatures in bridge files * fix qwen api change * rename and ref functions * rename and move some cookie functions * 增加haiku模型,新增endpoint配置说明 (#1626) * haiku added * 新增haiku,新增endpoint配置说明 * Haiku added * 将说明同步至最新Endpoint --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * private_upload目录下进行文件鉴权 (#1596) * private_upload目录下进行文件鉴权 * minor fastapi adjustment * Add logging functionality to enable saving conversation records * waiting to fix username retrieve * support 2rd web path * allow accessing default user dir --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * remove yaml deps * fix favicon * fix abs path auth problem * forget to write a return * add `dashscope` to deps * fix GHSA-v9q9-xj86-953p * 用户名重叠越权访问patch (#1681) * add cohere model api access * cohere + can_multi_thread * fix block user access(fail) * fix fastapi bug * change cohere api endpoint * explain version --------- Co-authored-by: Menghuan1918 <menghuan2003@outlook.com> Co-authored-by: Skyzayre <120616113+Skyzayre@users.noreply.github.com> Co-authored-by: XIao <46100050+Kilig947@users.noreply.github.com>
这个提交包含在:
154
themes/common.js
154
themes/common.js
@@ -2,15 +2,15 @@
|
||||
// 第 1 部分: 工具函数
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
function push_data_to_gradio_component(DAT, ELEM_ID, TYPE){
|
||||
function push_data_to_gradio_component(DAT, ELEM_ID, TYPE) {
|
||||
// type, // type==="str" / type==="float"
|
||||
if (TYPE=="str"){
|
||||
if (TYPE == "str") {
|
||||
// convert dat to string: do nothing
|
||||
}
|
||||
else if (TYPE=="no_conversion"){
|
||||
else if (TYPE == "no_conversion") {
|
||||
// no nothing
|
||||
}
|
||||
else if (TYPE=="float"){
|
||||
else if (TYPE == "float") {
|
||||
// convert dat to float
|
||||
DAT = parseFloat(DAT);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ function push_data_to_gradio_component(DAT, ELEM_ID, TYPE){
|
||||
}
|
||||
|
||||
|
||||
async function get_gradio_component(ELEM_ID){
|
||||
async function get_gradio_component(ELEM_ID) {
|
||||
function waitFor(ELEM_ID) {
|
||||
return new Promise((resolve) => {
|
||||
const myEvent = new CustomEvent('gpt_academic_get_gradio_component_value', {
|
||||
@@ -41,14 +41,13 @@ async function get_gradio_component(ELEM_ID){
|
||||
}
|
||||
|
||||
|
||||
async function get_data_from_gradio_component(ELEM_ID){
|
||||
async function get_data_from_gradio_component(ELEM_ID) {
|
||||
let comp = await get_gradio_component(ELEM_ID);
|
||||
return comp.props.value;
|
||||
}
|
||||
|
||||
function update_array(arr, item, mode) {
|
||||
// let p = ["基础功能区", "输入清除键", "函数插件区"];
|
||||
|
||||
function update_array(arr, item, mode) {
|
||||
// // Remove "输入清除键"
|
||||
// p = updateArray(p, "输入清除键", "remove");
|
||||
// console.log(p); // Should log: ["基础功能区", "函数插件区"]
|
||||
@@ -60,13 +59,13 @@ function update_array(arr, item, mode) {
|
||||
const index = arr.indexOf(item);
|
||||
if (mode === "remove") {
|
||||
if (index !== -1) {
|
||||
// Item found, remove it
|
||||
arr.splice(index, 1);
|
||||
// Item found, remove it
|
||||
arr.splice(index, 1);
|
||||
}
|
||||
} else if (mode === "add") {
|
||||
if (index === -1) {
|
||||
// Item not found, add it
|
||||
arr.push(item);
|
||||
// Item not found, add it
|
||||
arr.push(item);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
@@ -85,6 +84,7 @@ function gradioApp() {
|
||||
return elem.shadowRoot ? elem.shadowRoot : elem;
|
||||
}
|
||||
|
||||
|
||||
function setCookie(name, value, days) {
|
||||
var expires = "";
|
||||
|
||||
@@ -97,6 +97,7 @@ function setCookie(name, value, days) {
|
||||
document.cookie = name + "=" + value + expires + "; path=/";
|
||||
}
|
||||
|
||||
|
||||
function getCookie(name) {
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var cookies = decodedCookie.split(';');
|
||||
@@ -112,6 +113,7 @@ function getCookie(name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
let toastCount = 0;
|
||||
function toast_push(msg, duration) {
|
||||
duration = isNaN(duration) ? 3000 : duration;
|
||||
@@ -134,6 +136,7 @@ function toast_push(msg, duration) {
|
||||
toastCount++;
|
||||
}
|
||||
|
||||
|
||||
function toast_up(msg) {
|
||||
var m = document.getElementById('toast_up');
|
||||
if (m) {
|
||||
@@ -146,6 +149,7 @@ function toast_up(msg) {
|
||||
document.body.appendChild(m);
|
||||
}
|
||||
|
||||
|
||||
function toast_down() {
|
||||
var m = document.getElementById('toast_up');
|
||||
if (m) {
|
||||
@@ -153,6 +157,7 @@ function toast_down() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function begin_loading_status() {
|
||||
// Create the loader div and add styling
|
||||
var loader = document.createElement('div');
|
||||
@@ -327,6 +332,7 @@ function do_something_but_not_too_frequently(min_interval, func) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function chatbotContentChanged(attempt = 1, force = false) {
|
||||
// https://github.com/GaiZhenbiao/ChuanhuChatGPT/tree/main/web_assets/javascript
|
||||
for (var i = 0; i < attempt; i++) {
|
||||
@@ -343,7 +349,6 @@ function chatbotContentChanged(attempt = 1, force = false) {
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
// 第 3 部分: chatbot动态高度调整
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
function chatbotAutoHeight() {
|
||||
// 自动调整高度:立即
|
||||
function update_height() {
|
||||
@@ -375,6 +380,7 @@ function chatbotAutoHeight() {
|
||||
setInterval(function () { update_height_slow() }, 50); // 每50毫秒执行一次
|
||||
}
|
||||
|
||||
|
||||
swapped = false;
|
||||
function swap_input_area() {
|
||||
// Get the elements to be swapped
|
||||
@@ -394,6 +400,7 @@ function swap_input_area() {
|
||||
else { swapped = true; }
|
||||
}
|
||||
|
||||
|
||||
function get_elements(consider_state_panel = false) {
|
||||
var chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq');
|
||||
if (!chatbot) {
|
||||
@@ -491,6 +498,7 @@ async function upload_files(files) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function register_func_paste(input) {
|
||||
let paste_files = [];
|
||||
if (input) {
|
||||
@@ -517,6 +525,7 @@ function register_func_paste(input) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function register_func_drag(elem) {
|
||||
if (elem) {
|
||||
const dragEvents = ["dragover"];
|
||||
@@ -553,6 +562,7 @@ function register_func_drag(elem) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function elem_upload_component_pop_message(elem) {
|
||||
if (elem) {
|
||||
const dragEvents = ["dragover"];
|
||||
@@ -582,6 +592,7 @@ function elem_upload_component_pop_message(elem) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function register_upload_event() {
|
||||
locate_upload_elems();
|
||||
if (elem_upload_float) {
|
||||
@@ -604,6 +615,7 @@ function register_upload_event() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function monitoring_input_box() {
|
||||
register_upload_event();
|
||||
|
||||
@@ -637,7 +649,6 @@ window.addEventListener("DOMContentLoaded", function () {
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
// 第 5 部分: 音频按钮样式变化
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
function audio_fn_init() {
|
||||
let audio_component = document.getElementById('elem_audio');
|
||||
if (audio_component) {
|
||||
@@ -674,6 +685,7 @@ function audio_fn_init() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function minor_ui_adjustment() {
|
||||
let cbsc_area = document.getElementById('cbsc');
|
||||
cbsc_area.style.paddingTop = '15px';
|
||||
@@ -766,21 +778,6 @@ function limit_scroll_position() {
|
||||
// 第 7 部分: JS初始化函数
|
||||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
function GptAcademicJavaScriptInit(LAYOUT = "LEFT-RIGHT") {
|
||||
audio_fn_init();
|
||||
minor_ui_adjustment();
|
||||
chatbotIndicator = gradioApp().querySelector('#gpt-chatbot > div.wrap');
|
||||
var chatbotObserver = new MutationObserver(() => {
|
||||
chatbotContentChanged(1);
|
||||
});
|
||||
chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
|
||||
if (LAYOUT === "LEFT-RIGHT") { chatbotAutoHeight(); }
|
||||
if (LAYOUT === "LEFT-RIGHT") { limit_scroll_position(); }
|
||||
// setInterval(function () { uml("mermaid") }, 5000); // 每50毫秒执行一次
|
||||
|
||||
}
|
||||
|
||||
|
||||
function loadLive2D() {
|
||||
try {
|
||||
$("<link>").attr({ href: "file=themes/waifu_plugin/waifu.css", rel: "stylesheet", type: "text/css" }).appendTo('head');
|
||||
@@ -802,12 +799,12 @@ function loadLive2D() {
|
||||
live2d_settings['canTakeScreenshot'] = false;
|
||||
live2d_settings['canTurnToHomePage'] = false;
|
||||
live2d_settings['canTurnToAboutPage'] = false;
|
||||
live2d_settings['showHitokoto'] = false; // 显示一言
|
||||
live2d_settings['showHitokoto'] = false; // 显示一言
|
||||
live2d_settings['showF12Status'] = false; // 显示加载状态
|
||||
live2d_settings['showF12Message'] = false; // 显示看板娘消息
|
||||
live2d_settings['showF12OpenMsg'] = false; // 显示控制台打开提示
|
||||
live2d_settings['showCopyMessage'] = false; // 显示 复制内容 提示
|
||||
live2d_settings['showWelcomeMessage'] = true; // 显示进入面页欢迎词
|
||||
live2d_settings['showF12OpenMsg'] = false; // 显示控制台打开提示
|
||||
live2d_settings['showCopyMessage'] = false; // 显示 复制内容 提示
|
||||
live2d_settings['showWelcomeMessage'] = true; // 显示进入面页欢迎词
|
||||
/* 在 initModel 前添加 */
|
||||
initModel("file=themes/waifu_plugin/waifu-tips.json");
|
||||
}
|
||||
@@ -817,7 +814,8 @@ function loadLive2D() {
|
||||
} catch (err) { console.log("[Error] JQuery is not defined.") }
|
||||
}
|
||||
|
||||
function get_checkbox_selected_items(elem_id){
|
||||
|
||||
function get_checkbox_selected_items(elem_id) {
|
||||
display_panel_arr = [];
|
||||
document.getElementById(elem_id).querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
|
||||
// Get the span text
|
||||
@@ -831,62 +829,24 @@ function get_checkbox_selected_items(elem_id){
|
||||
return display_panel_arr;
|
||||
}
|
||||
|
||||
function set_checkbox(key, bool, set_twice=false) {
|
||||
set_success = false;
|
||||
elem_ids = ["cbsc", "cbs"]
|
||||
elem_ids.forEach(id => {
|
||||
document.getElementById(id).querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
|
||||
// Get the span text
|
||||
const spanText = label.querySelector('span').textContent;
|
||||
if (spanText === key) {
|
||||
if (bool){
|
||||
label.classList.add('selected');
|
||||
} else {
|
||||
if (label.classList.contains('selected')) {
|
||||
label.classList.remove('selected');
|
||||
}
|
||||
}
|
||||
if (set_twice){
|
||||
setTimeout(() => {
|
||||
if (bool){
|
||||
label.classList.add('selected');
|
||||
} else {
|
||||
if (label.classList.contains('selected')) {
|
||||
label.classList.remove('selected');
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
label.querySelector('input').checked = bool;
|
||||
set_success = true;
|
||||
return
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!set_success){
|
||||
console.log("设置checkbox失败,没有找到对应的key")
|
||||
}
|
||||
}
|
||||
|
||||
function gpt_academic_gradio_saveload(
|
||||
save_or_load, // save_or_load==="save" / save_or_load==="load"
|
||||
elem_id, // element id
|
||||
cookie_key, // cookie key
|
||||
save_value="", // save value
|
||||
load_type = "str", // type==="str" / type==="float"
|
||||
load_default=false, // load default value
|
||||
load_default_value=""
|
||||
) {
|
||||
save_or_load, // save_or_load==="save" / save_or_load==="load"
|
||||
elem_id, // element id
|
||||
cookie_key, // cookie key
|
||||
save_value = "", // save value
|
||||
load_type = "str", // type==="str" / type==="float"
|
||||
load_default = false, // load default value
|
||||
load_default_value = ""
|
||||
) {
|
||||
if (save_or_load === "load") {
|
||||
let value = getCookie(cookie_key);
|
||||
if (value) {
|
||||
console.log('加载cookie', elem_id, value)
|
||||
push_data_to_gradio_component(value, elem_id, load_type);
|
||||
}
|
||||
else{
|
||||
if (load_default){
|
||||
else {
|
||||
if (load_default) {
|
||||
console.log('加载cookie的默认值', elem_id, load_default_value)
|
||||
push_data_to_gradio_component(load_default_value, elem_id, load_type);
|
||||
}
|
||||
@@ -897,11 +857,24 @@ function gpt_academic_gradio_saveload(
|
||||
}
|
||||
}
|
||||
|
||||
async function init_frontend_with_cookies(dark, prompt, live2d) {
|
||||
let searchString = "输入清除键";
|
||||
let bool_value = "False";
|
||||
|
||||
////////////////// darkmode ///////////////////
|
||||
async function GptAcademicJavaScriptInit(dark, prompt, live2d, layout) {
|
||||
// 第一部分,布局初始化
|
||||
audio_fn_init();
|
||||
minor_ui_adjustment();
|
||||
chatbotIndicator = gradioApp().querySelector('#gpt-chatbot > div.wrap');
|
||||
var chatbotObserver = new MutationObserver(() => {
|
||||
chatbotContentChanged(1);
|
||||
});
|
||||
chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
|
||||
if (layout === "LEFT-RIGHT") { chatbotAutoHeight(); }
|
||||
if (layout === "LEFT-RIGHT") { limit_scroll_position(); }
|
||||
|
||||
// 第二部分,读取Cookie,初始话界面
|
||||
let searchString = "";
|
||||
let bool_value = "";
|
||||
|
||||
// darkmode 深色模式
|
||||
if (getCookie("js_darkmode_cookie")) {
|
||||
dark = getCookie("js_darkmode_cookie")
|
||||
}
|
||||
@@ -916,12 +889,13 @@ async function init_frontend_with_cookies(dark, prompt, live2d) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////// SysPrompt ///////////////////////////
|
||||
// SysPrompt 系统静默提示词
|
||||
gpt_academic_gradio_saveload("load", "elem_prompt", "js_system_prompt_cookie", null, "str");
|
||||
////////////////////// Temperature ///////////////////////////
|
||||
|
||||
// Temperature 大模型温度参数
|
||||
gpt_academic_gradio_saveload("load", "elem_temperature", "js_temperature_cookie", null, "float");
|
||||
|
||||
////////////////////// clearButton ///////////////////////////
|
||||
// clearButton 自动清除按钮
|
||||
if (getCookie("js_clearbtn_show_cookie")) {
|
||||
// have cookie
|
||||
bool_value = getCookie("js_clearbtn_show_cookie")
|
||||
@@ -949,7 +923,7 @@ async function init_frontend_with_cookies(dark, prompt, live2d) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////// live2d ///////////////////////////
|
||||
// live2d 显示
|
||||
if (getCookie("js_live2d_show_cookie")) {
|
||||
// have cookie
|
||||
searchString = "添加Live2D形象";
|
||||
|
||||
@@ -48,7 +48,7 @@ adjust_theme, advanced_css, theme_declaration, _ = load_dynamic_theme(get_conf("
|
||||
cookie相关工具函数
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
"""
|
||||
def init_cookie(cookies):
|
||||
def assign_user_uuid(cookies):
|
||||
# 为每一位访问的用户赋予一个独一无二的uuid编码
|
||||
cookies.update({"uuid": uuid.uuid4()})
|
||||
return cookies
|
||||
@@ -106,8 +106,8 @@ js_code_for_toggle_darkmode = """() => {
|
||||
}"""
|
||||
|
||||
|
||||
js_code_for_persistent_cookie_init = """(py_pickle_cookie, cookie) => {
|
||||
return [getCookie("py_pickle_cookie"), cookie];
|
||||
js_code_for_persistent_cookie_init = """(web_cookie_cache, cookie) => {
|
||||
return [getCookie("web_cookie_cache"), cookie];
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户