LLaMA 8B Floating Chat

Adds a draggable ChatGPT button to Discord with an inbuilt ChatGPT chatbox

目前為 2025-08-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         LLaMA 8B Floating Chat
// @version      0.45
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// @namespace https://gf.qytechs.cn/
// @description Adds a draggable ChatGPT button to Discord with an inbuilt ChatGPT chatbox
// ==/UserScript==

(function() {
    'use strict';

    // Add floating button
    const btn = document.createElement("img");
    btn.src = "file:///mnt/data/1000009292.jpg"; // Replace with a hosted URL if needed
    btn.style.position = "fixed";
    btn.style.bottom = "20px";
    btn.style.right = "20px";
    btn.style.width = "60px";
    btn.style.height = "60px";
    btn.style.borderRadius = "50%";
    btn.style.cursor = "pointer";
    btn.style.zIndex = 10000;
    btn.style.boxShadow = "0 4px 8px rgba(0,0,0,0.3)";
    document.body.appendChild(btn);

    // Add chat box
    const chatBox = document.createElement("div");
    chatBox.style.position = "fixed";
    chatBox.style.bottom = "90px";
    chatBox.style.right = "20px";
    chatBox.style.width = "300px";
    chatBox.style.height = "400px";
    chatBox.style.background = "#fff";
    chatBox.style.border = "1px solid #ccc";
    chatBox.style.borderRadius = "10px";
    chatBox.style.padding = "10px";
    chatBox.style.display = "none";
    chatBox.style.flexDirection = "column";
    chatBox.style.zIndex = 10000;
    chatBox.style.overflowY = "auto";
    chatBox.style.fontFamily = "sans-serif";
    document.body.appendChild(chatBox);

    const input = document.createElement("input");
    input.type = "text";
    input.placeholder = "Type your message...";
    input.style.width = "100%";
    input.style.padding = "5px";
    input.style.marginTop = "auto";
    chatBox.appendChild(input);

    // Toggle chat box
    btn.addEventListener("click", () => {
        chatBox.style.display = chatBox.style.display === "none" ? "flex" : "none";
    });

    // Send message
    input.addEventListener("keypress", function(e) {
        if (e.key === "Enter" && input.value.trim() !== "") {
            const userMessage = input.value;
            input.value = "";
            
            const messageDiv = document.createElement("div");
            messageDiv.textContent = "You: " + userMessage;
            chatBox.appendChild(messageDiv);
            
            GM_xmlhttpRequest({
                method: "POST",
                url: "https://api-inference.huggingface.co/models/meta-llama/Llama-3.1-8B-Instruct",
                headers: {
                    "Authorization": "Bearer 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",
                    "Content-Type": "application/json"
                },
                data: JSON.stringify({ inputs: userMessage, options: { wait_for_model: true } }),
                onload: function(response) {
                    try {
                        const data = JSON.parse(response.responseText);
                        const llamaResponse = (Array.isArray(data) && data[0].generated_text) ? data[0].generated_text : "Error getting response";
                        const responseDiv = document.createElement("div");
                        responseDiv.textContent = "LLaMA: " + llamaResponse;
                        chatBox.appendChild(responseDiv);
                        chatBox.scrollTop = chatBox.scrollHeight;
                    } catch(e) {
                        alert("Failed to parse response");
                    }
                },
                onerror: function(err) {
                    alert("Request failed");
                }
            });
        }
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址