Free ECUST Chatbot

Free and unrestricted ECUST chatbot

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Free ECUST Chatbot
// @namespace    https://ecust.edu.cn/
// @version      0.1.5
// @description  Free and unrestricted ECUST chatbot
// @author       Oborozuki
// @match        *://ai.s.ecust.edu.cn/chatbot/*
// @match        *://ai.s.ecust.edu.cn/academic-qa/*
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

const modelTemperature = 0.5;
const useGPT4oMini = true;
const deleteSystemPrompt = true;

(function () {
    const originFetch = fetch;

    window.unsafeWindow.fetch = async (url, options) => {
        if (url.includes("/chatbot/api/tokenizer") || url.includes("/chatbot/api/paycenter/token/consume") || url.includes("/academic-qa/api/tokenizer") || url.includes("/academic-qa/api/paycenter/token/consume")) {
            return null;
        }

        if ((url.includes("/chatbot/api/chat/") || url.includes("/academic-qa/api/chat/ecust")) && options?.body) {
            const body = JSON.parse(options.body);
            body.chatSettings.temperature = modelTemperature;

            if (url.includes("/chatbot/api/chat/azure") && useGPT4oMini) {
                body.chatSettings.model = "gpt-4o-mini";
            }

            if (body.messages?.length) {
                const firstMessage = body.messages[0];
                if (deleteSystemPrompt && firstMessage.role === "system") {
                    body.messages.shift();
                }
            }
            options.body = JSON.stringify(body);
        }

        return originFetch(url, options).then(async (response) => {
            if (url.includes("/chatbot/api/text/check") || url.includes("/academic-qa/api/text/check")) {
                const res = await response.clone().json();
                res.data.forEach(d => { d.code = 1; });
                return new Response(JSON.stringify(res), response);
            }
            return response;
        });
    };
})();