Ceru's chatbot

Ceru made an interface for the Qwen LLM that runs on minecraft. It is interesting how it receives data, since users don’t have access to any fast-cgi capabilities he had to come up with a solution to read user input. Upon sending a message the frontend assigns a sessionID to the message, the backend creates a new html page using the sessionID, redirects and starts to query for the chatbot’s response. This reponse can be found in another html page that is updated as the chatbot spews out new tokens.
Here’s the relevant snippet:

function sendMessage() {
    const userInput = document.getElementById('userInput');
    let message = userInput.value.trim();
    if (message === "") return;
    let session_id = gen_sesh_id();
    addMessage("You: " + message, "user-message");
    chatHistory.push({ role: "user", content: message });
    userInput.value = "";
    const payload = encodeURIComponent(JSON.stringify({ chatHistory, systemPrompt, message }));
    let attempts = 0;
    const maxAttempts = 5;
    fetch(`https://minecraft.poul.org/~ceru/sessions/${session_id}/${payload}`, { method: 'GET', mode: 'cors' })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.text();
        })
    setTimeout(() => {
        makeRequest();
    }, 300);
    function makeRequest() {
        fetch(`https://minecraft.poul.org/~ceru/sessions/${session_id}.html`, { method: 'GET', mode: 'cors' })
            .then(response => {/* grab reply */})
            .then(data => {
                window.open(`https://minecraft.poul.org/~ceru/sessions/${session_id}.html`, '_self');
            })
            .catch(error => {/* stuff */});
    }
}

“But Mroik, you said that users don’t have access to any fast-cgi, how does the backend read user input?”. Well, that’s the interesting part, they just read it from the webserver’s (Caddy) log file. So, to make the data readable the whole state of the chat is encoded in a JSON object, then it is URL encoded so that all the data can be read through the URL. This is necessary because from the logs you only see the resource requested and the HTTP action used on that resource.

As far as I know Ceru got some help from giaco, but I’m not sure how much of it was his work.

I told them that if they needed it I’d add PHP so that they wouldn’t be restricted to using solely static pages, but they said it was already done, so might as well keep it that way. As for the user experience it does work surprisingly well to be honest. Looking forward users doing more wacky stuff on minecraft.