From 1de4944d46010e714e51d60d469ca66fef2e9233 Mon Sep 17 00:00:00 2001 From: nolialsea Date: Fri, 25 Mar 2022 20:08:56 +0100 Subject: [PATCH 01/10] Add throttle closure for settings sliders Adds a throttling closure to add a waiting time before calling a callback, Uses this closure to throttle the event fired by socketio on slider value change --- static/application.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/static/application.js b/static/application.js index 88637075..b5d6ba36 100644 --- a/static/application.js +++ b/static/application.js @@ -118,10 +118,32 @@ var adventure = false; // Chatmode var chatmode = false; +var sliders_throttle = getThrottle(250); + //=================================================================// // METHODS //=================================================================// +/** + * Returns a function that will automatically wait for X ms before executing the callback + * The timer is reset each time the returned function is called + * Useful for methods where something is overridden too fast + * @param ms milliseconds to wait before executing the callback + * @return {(function(*): void)|*} function that takes the ms to wait and a callback to execute after the timer + */ +function getThrottle(ms) { + var timer; + + return function (callback) { + if (timer) { + clearTimeout(timer); + } + timer = setTimeout(function () { + callback(); + }, ms); + } +} + function addSetting(ob) { // Add setting block to Settings Menu if(ob.uitype == "slider"){ @@ -153,8 +175,11 @@ function addSetting(ob) { window["label_"+ob.id] = reflb; // Is this still needed? // Add event function to input refin.on("input", function () { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()}); - }); + sliders_throttle(function () { + socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()}); + }); + } + ); } else if(ob.uitype == "toggle"){ settings_menu.append("
\ \ From 6ed50ee1e90c22bffa818e36929c7d4dfceac148 Mon Sep 17 00:00:00 2001 From: Noli Date: Fri, 25 Mar 2022 20:37:45 +0100 Subject: [PATCH 02/10] make the throttle timer a dict to keep track of which slider has been changed --- colab/TPU.ipynb | 374 +++++++++++++++++++++--------------------- static/application.js | 13 +- 2 files changed, 194 insertions(+), 193 deletions(-) diff --git a/colab/TPU.ipynb b/colab/TPU.ipynb index 916012b2..b53af520 100644 --- a/colab/TPU.ipynb +++ b/colab/TPU.ipynb @@ -1,190 +1,190 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "source": [ - "# Welcome to KoboldAI on Google Colab, TPU Edition!\n", - "KoboldAI is a powerful and easy way to use a variety of AI based text generation experiences. You can use it to write stories, blog posts, play a text adventure game, use it like a chatbot and more! In some cases it might even help you with an assignment or programming task (But always make sure the information the AI mentions is correct, it loves to make stuff up).\n", - "\n", - "For more information about KoboldAI check our our Github readme : https://github.com/KoboldAI/KoboldAI-Client/blob/main/readme.md\n", - "\n", - "More (smaller) models are available in the **[GPU edition](https://colab.research.google.com/github/koboldai/KoboldAI-Client/blob/main/colab/GPU.ipynb)**!" - ], - "metadata": { - "id": "zrLGxVCEaqZx" - } - }, - { - "cell_type": "code", - "source": [ - "#@title <-- Tap this if you play on Mobile { display-mode: \"form\" }\n", - "%%html\n", - "Press play on the music player to keep the tab alive, then start KoboldAI below (Uses only 13MB of data)
\n", - "