mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Add more scratchpad stuff
This commit is contained in:
12
aiserver.py
12
aiserver.py
@@ -8383,6 +8383,18 @@ def UI_2_update_wi_keys(data):
|
|||||||
# Send to UI
|
# Send to UI
|
||||||
socketio.emit("world_info_entry", koboldai_vars.worldinfo_v2.world_info[uid], broadcast=True, room="UI_2")
|
socketio.emit("world_info_entry", koboldai_vars.worldinfo_v2.world_info[uid], broadcast=True, room="UI_2")
|
||||||
|
|
||||||
|
@socketio.on("scratchpad_prompt")
|
||||||
|
@logger.catch
|
||||||
|
def UI_2_scratchpad_prompt(data):
|
||||||
|
print(data)
|
||||||
|
out_text = raw_generate(
|
||||||
|
data,
|
||||||
|
max_new=80,
|
||||||
|
).decoded
|
||||||
|
print("data", data, "out", out_text)
|
||||||
|
|
||||||
|
socketio.emit("scratchpad_response", out_text, broadcast=True, room="UI_2")
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered when user edits phrase biases
|
# Event triggered when user edits phrase biases
|
||||||
|
@@ -1915,6 +1915,10 @@ body {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#finder-container {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
#finder {
|
#finder {
|
||||||
width: 25%;
|
width: 25%;
|
||||||
background-color: var(--flyout_background_pinned);
|
background-color: var(--flyout_background_pinned);
|
||||||
@@ -1943,6 +1947,31 @@ body {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#finder-scratchpad {
|
||||||
|
width: 25%;
|
||||||
|
background-color: var(--input_background);
|
||||||
|
padding: 10px;
|
||||||
|
border-bottom-left-radius: 4px;
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
#finder-scratchpad-info {
|
||||||
|
opacity: 0.7;
|
||||||
|
font-weight: bold;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#finder-scratchpad-prompt,
|
||||||
|
#finder-scratchpad-response {
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: var(--gamescreen_background);
|
||||||
|
}
|
||||||
|
|
||||||
|
#finder-scratchpad-response {
|
||||||
|
color: var(--text_edit);
|
||||||
|
}
|
||||||
|
|
||||||
.finder-result {
|
.finder-result {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@@ -32,6 +32,7 @@ socket.on("wi_results", updateWISearchListings);
|
|||||||
socket.on("request_prompt_config", configurePrompt);
|
socket.on("request_prompt_config", configurePrompt);
|
||||||
socket.on("log_message", function(data){process_log_message(data)});
|
socket.on("log_message", function(data){process_log_message(data)});
|
||||||
socket.on("debug_message", function(data){console.log(data);});
|
socket.on("debug_message", function(data){console.log(data);});
|
||||||
|
socket.on("scratchpad_response", recieveScratchpadResponse);
|
||||||
//socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});});
|
//socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});});
|
||||||
|
|
||||||
var presets = {};
|
var presets = {};
|
||||||
@@ -54,6 +55,8 @@ var wi_finder_data = [];
|
|||||||
var wi_finder_offset = 0;
|
var wi_finder_offset = 0;
|
||||||
var selected_game_chunk = null;
|
var selected_game_chunk = null;
|
||||||
var log = [];
|
var log = [];
|
||||||
|
var finder_mode = "ui";
|
||||||
|
var finder_waiting_id = null;
|
||||||
|
|
||||||
// name, desc, icon, func
|
// name, desc, icon, func
|
||||||
const finder_actions = [
|
const finder_actions = [
|
||||||
@@ -4126,7 +4129,53 @@ function renderWISearchListings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function recieveScratchpadResponse(data) {
|
||||||
|
const scratchpadResponse = document.querySelector("#finder-scratchpad-response");
|
||||||
|
|
||||||
|
clearInterval(finder_waiting_id);
|
||||||
|
finder_waiting_id = null;
|
||||||
|
|
||||||
|
scratchpadResponse.innerText = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendScratchpadPrompt(prompt) {
|
||||||
|
// Already waiting on prompt...
|
||||||
|
if (finder_waiting_id) return;
|
||||||
|
|
||||||
|
const scratchpad = document.querySelector("#finder-scratchpad");
|
||||||
|
const scratchpadPrompt = document.querySelector("#finder-scratchpad-prompt");
|
||||||
|
const scratchpadResponse = document.querySelector("#finder-scratchpad-response");
|
||||||
|
|
||||||
|
scratchpadPrompt.innerText = prompt;
|
||||||
|
scratchpadResponse.innerText = "...";
|
||||||
|
|
||||||
|
scratchpad.classList.remove("hidden");
|
||||||
|
|
||||||
|
finder_waiting_id = setInterval(function() {
|
||||||
|
// Little loading animation so user doesn't think nothing is happening.
|
||||||
|
// TODO: Replace this with token streaming WHEN AVAILABLE.
|
||||||
|
|
||||||
|
let index = scratchpadResponse.innerText.indexOf("|");
|
||||||
|
if (index === 2) {
|
||||||
|
scratchpadResponse.innerText = "...";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let buf = "";
|
||||||
|
|
||||||
|
index++;
|
||||||
|
|
||||||
|
for (let i=0;i<index;i++) buf += ".";
|
||||||
|
buf += "|";
|
||||||
|
for (let i=0;i<2-index;i++) buf += ".";
|
||||||
|
|
||||||
|
scratchpadResponse.innerText = buf;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
socket.emit("scratchpad_prompt", prompt);
|
||||||
|
}
|
||||||
|
|
||||||
function updateSearchListings() {
|
function updateSearchListings() {
|
||||||
|
if (finder_mode === "scratchpad") return;
|
||||||
if (this.value === finder_last_input) return;
|
if (this.value === finder_last_input) return;
|
||||||
finder_last_input = this.value;
|
finder_last_input = this.value;
|
||||||
finder_selection_index = -1;
|
finder_selection_index = -1;
|
||||||
@@ -4139,15 +4188,13 @@ function updateSearchListings() {
|
|||||||
// TODO: Maybe reuse the element? Would it give better performance?
|
// TODO: Maybe reuse the element? Would it give better performance?
|
||||||
$(".finder-result").remove();
|
$(".finder-result").remove();
|
||||||
|
|
||||||
if (!query || query === ">") return;
|
if (!query) return;
|
||||||
|
|
||||||
if (query.startsWith(">")) {
|
if (finder_mode === "wi") {
|
||||||
wiCarousel.classList.remove("hidden");
|
wiCarousel.classList.remove("hidden");
|
||||||
$(".finder-wi-block").remove();
|
$(".finder-wi-block").remove();
|
||||||
|
socket.emit("search_wi", {query: query});
|
||||||
let wiQuery = query.replace(">", "");
|
} else if (finder_mode === "ui") {
|
||||||
socket.emit("search_wi", {query: wiQuery});
|
|
||||||
} else {
|
|
||||||
updateStandardSearchListings(query)
|
updateStandardSearchListings(query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4163,9 +4210,18 @@ function updateFinderSelection() {
|
|||||||
function updateFinderMode(mode) {
|
function updateFinderMode(mode) {
|
||||||
const finderIcon = document.querySelector("#finder-icon");
|
const finderIcon = document.querySelector("#finder-icon");
|
||||||
const finderInput = document.querySelector("#finder-input");
|
const finderInput = document.querySelector("#finder-input");
|
||||||
|
const finderScratchpad = document.querySelector("#finder-scratchpad");
|
||||||
|
|
||||||
finderIcon.innerText = {ui: "search", wi: "auto_stories", scratchpad: "speaker_notes"}[mode];
|
finderIcon.innerText = {ui: "search", wi: "auto_stories", scratchpad: "speaker_notes"}[mode];
|
||||||
finderInput.placeholder = {ui: "Search for something...", wi: "Search for a World Info entry...", scratchpad: "Prompt the AI..."}[mode];
|
finderInput.placeholder = {ui: "Search for something...", wi: "Search for a World Info entry...", scratchpad: "Prompt the AI..."}[mode];
|
||||||
|
finderScratchpad.classList.add("hidden");
|
||||||
|
|
||||||
|
finder_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cycleFinderMode() {
|
||||||
|
// Initiated by clicking on icon
|
||||||
|
updateFinderMode({ui: "wi", wi: "scratchpad", scratchpad: "ui"}[finder_mode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function open_finder() {
|
function open_finder() {
|
||||||
@@ -4174,6 +4230,7 @@ function open_finder() {
|
|||||||
finderInput.value = "";
|
finderInput.value = "";
|
||||||
$(".finder-result").remove();
|
$(".finder-result").remove();
|
||||||
finder_selection_index = -1;
|
finder_selection_index = -1;
|
||||||
|
updateFinderMode("ui");
|
||||||
|
|
||||||
finderContainer.classList.remove("hidden");
|
finderContainer.classList.remove("hidden");
|
||||||
finderInput.focus();
|
finderInput.focus();
|
||||||
@@ -4355,8 +4412,9 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
const finderContainer = document.getElementById("finder-container");
|
const finderContainer = document.getElementById("finder-container");
|
||||||
const finderInput = document.getElementById("finder-input");
|
const finderInput = document.getElementById("finder-input");
|
||||||
const finder = document.getElementById("finder");
|
const finderIcon = document.getElementById("finder-icon");
|
||||||
|
|
||||||
|
finderIcon.addEventListener("click", cycleFinderMode);
|
||||||
finderInput.addEventListener("keyup", updateSearchListings);
|
finderInput.addEventListener("keyup", updateSearchListings);
|
||||||
finderInput.addEventListener("keydown", function(event) {
|
finderInput.addEventListener("keydown", function(event) {
|
||||||
let delta = 0;
|
let delta = 0;
|
||||||
@@ -4370,8 +4428,13 @@ $(document).ready(function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
|
if (finder_mode === "scratchpad") {
|
||||||
|
sendScratchpadPrompt(finderInput.value);
|
||||||
|
return;
|
||||||
|
} else if (finder_mode === "ui") {
|
||||||
let index = finder_selection_index >= 0 ? finder_selection_index : 0;
|
let index = finder_selection_index >= 0 ? finder_selection_index : 0;
|
||||||
actions[index].click();
|
actions[index].click();
|
||||||
|
}
|
||||||
} else if (event.key === "ArrowUp") {
|
} else if (event.key === "ArrowUp") {
|
||||||
delta = -1;
|
delta = -1;
|
||||||
} else if (event.key === "ArrowDown") {
|
} else if (event.key === "ArrowDown") {
|
||||||
|
@@ -202,6 +202,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="finder-wi-carousel" class="hidden"></div>
|
<div id="finder-wi-carousel" class="hidden"></div>
|
||||||
|
<div id="finder-scratchpad">
|
||||||
|
<span id="finder-scratchpad-info" class="noselect">AI Output:</span>
|
||||||
|
<span id="finder-scratchpad-prompt">
|
||||||
|
A man with 20 fingers is
|
||||||
|
</span>
|
||||||
|
<span id="finder-scratchpad-response">
|
||||||
|
a threat to society
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!---------------- Debug File ---------------------->
|
<!---------------- Debug File ---------------------->
|
||||||
|
Reference in New Issue
Block a user