mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Chat2 werk
This commit is contained in:
@@ -598,6 +598,24 @@ gensettingstf = [
|
|||||||
"classname": "user",
|
"classname": "user",
|
||||||
"name": "privacy_password"
|
"name": "privacy_password"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"UI_V2_Only": True,
|
||||||
|
"uitype": "dropdown",
|
||||||
|
"unit": "text",
|
||||||
|
"label": "Chat Style",
|
||||||
|
"id": "chat_style",
|
||||||
|
"default": 0,
|
||||||
|
"tooltip": "How to represent chat messages in the UI",
|
||||||
|
"menu_path": "Interface",
|
||||||
|
"sub_path": "UI",
|
||||||
|
"classname": "story",
|
||||||
|
"name": "chat_style",
|
||||||
|
"children": [
|
||||||
|
{"text": "Legacy", "value": 0},
|
||||||
|
{"text": "Messages", "value": 1},
|
||||||
|
{"text": "Chat", "value": 2}
|
||||||
|
],
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
gensettingsik =[{
|
gensettingsik =[{
|
||||||
|
@@ -796,6 +796,7 @@ class story_settings(settings):
|
|||||||
# bias experiment
|
# bias experiment
|
||||||
self.memory_attn_bias = 1
|
self.memory_attn_bias = 1
|
||||||
self.an_attn_bias = 1
|
self.an_attn_bias = 1
|
||||||
|
self.chat_style = 0
|
||||||
|
|
||||||
|
|
||||||
################### must be at bottom #########################
|
################### must be at bottom #########################
|
||||||
|
@@ -1,8 +1,3 @@
|
|||||||
// PLACEHOLDER TEST!!
|
|
||||||
const chatv2 = true;
|
|
||||||
let chatv2LastEdit = null;
|
|
||||||
// PLACEHOLDER TEST!!
|
|
||||||
|
|
||||||
var socket;
|
var socket;
|
||||||
socket = io.connect(window.location.origin, {transports: ['polling', 'websocket'], closeOnBeforeunload: false, query:{"ui": "2"}});
|
socket = io.connect(window.location.origin, {transports: ['polling', 'websocket'], closeOnBeforeunload: false, query:{"ui": "2"}});
|
||||||
|
|
||||||
@@ -124,6 +119,24 @@ const shortcuts = [
|
|||||||
{key: "l", desc: '"Lock" screen (Not secure)', func: () => socket.emit("privacy_mode", {'enabled': true})},
|
{key: "l", desc: '"Lock" screen (Not secure)', func: () => socket.emit("privacy_mode", {'enabled': true})},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const chat = {
|
||||||
|
STYLES: {LEGACY: 0, MESSAGES: 1, CHAT: 2},
|
||||||
|
style: "legacy",
|
||||||
|
lastEdit: null,
|
||||||
|
|
||||||
|
get useV2() {
|
||||||
|
return [
|
||||||
|
this.STYLES.MESSAGES,
|
||||||
|
this.STYLES.CHAT
|
||||||
|
].includes(this.style) && story.mode === story.MODES.CHAT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const story = {
|
||||||
|
MODES: {STORY: 0, ADVENTURE: 1, CHAT: 2},
|
||||||
|
mode: null,
|
||||||
|
}
|
||||||
|
|
||||||
function $el(selector) {
|
function $el(selector) {
|
||||||
// We do not preemptively fetch all elements upon execution (wall of consts)
|
// We do not preemptively fetch all elements upon execution (wall of consts)
|
||||||
// due to the layer of mental overhead it adds to debugging and reading
|
// due to the layer of mental overhead it adds to debugging and reading
|
||||||
@@ -219,6 +232,9 @@ function reset_story() {
|
|||||||
document.getElementById("welcome_text").innerText = text;
|
document.getElementById("welcome_text").innerText = text;
|
||||||
document.getElementById("welcome_container").classList.remove("hidden");
|
document.getElementById("welcome_container").classList.remove("hidden");
|
||||||
document.getElementById('main-grid').setAttribute('option_length', 0);
|
document.getElementById('main-grid').setAttribute('option_length', 0);
|
||||||
|
|
||||||
|
$(".chat-message").remove();
|
||||||
|
addInitChatMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fix_text(val) {
|
function fix_text(val) {
|
||||||
@@ -381,7 +397,6 @@ function process_actions_data(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseChatMessages(text) {
|
function parseChatMessages(text) {
|
||||||
console.log("hehe", text)
|
|
||||||
let messages = []
|
let messages = []
|
||||||
|
|
||||||
for (const line of text.split("\n")) {
|
for (const line of text.split("\n")) {
|
||||||
@@ -389,7 +404,6 @@ function parseChatMessages(text) {
|
|||||||
if (!author && !text) continue;
|
if (!author && !text) continue;
|
||||||
messages.push({author: author, text: text});
|
messages.push({author: author, text: text});
|
||||||
}
|
}
|
||||||
console.log("oute", messages)
|
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
@@ -398,17 +412,23 @@ function do_story_text_updates(action) {
|
|||||||
story_area = document.getElementById('Selected Text');
|
story_area = document.getElementById('Selected Text');
|
||||||
current_chunk_number = action.id;
|
current_chunk_number = action.id;
|
||||||
let item = null;
|
let item = null;
|
||||||
console.log("ancient mesage")
|
|
||||||
|
|
||||||
if (chatv2) {
|
if (chat.useV2()) {
|
||||||
if (action.id === chatv2LastEdit) {
|
console.log(`[story_text_update] ${action.id}`)
|
||||||
|
if (action.id === chat.lastEdit) {
|
||||||
// Swallow update if we just caused it
|
// Swallow update if we just caused it
|
||||||
chatv2LastEdit = null;
|
chat.lastEdit = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteChatPromptIfEmpty();
|
||||||
|
|
||||||
const messageEl = $el(`[action-id="${action.id}"]`);
|
const messageEl = $el(`[action-id="${action.id}"]`);
|
||||||
let previous = messageEl ? messageEl.previousElementSibling : null;
|
let previous = messageEl ? messageEl.previousElementSibling : null;
|
||||||
|
|
||||||
|
// Remove old ones
|
||||||
|
$(`[action-id="${action.id}"]`).remove();
|
||||||
|
|
||||||
for (const message of parseChatMessages(action.action["Selected Text"])) {
|
for (const message of parseChatMessages(action.action["Selected Text"])) {
|
||||||
addMessage(message.author, message.text, action.id, previous);
|
addMessage(message.author, message.text, action.id, previous);
|
||||||
}
|
}
|
||||||
@@ -457,7 +477,7 @@ function do_story_text_updates(action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function do_prompt(data) {
|
function do_prompt(data) {
|
||||||
console.log(data);
|
console.log("[prompt]", data);
|
||||||
var elements_to_change = document.getElementsByClassName("var_sync_story_prompt");
|
var elements_to_change = document.getElementsByClassName("var_sync_story_prompt");
|
||||||
for (item of elements_to_change) {
|
for (item of elements_to_change) {
|
||||||
//clear out the item first
|
//clear out the item first
|
||||||
@@ -466,11 +486,14 @@ function do_prompt(data) {
|
|||||||
}
|
}
|
||||||
let full_text = "";
|
let full_text = "";
|
||||||
|
|
||||||
if (chatv2) {
|
if (chat.useV2) {
|
||||||
for (chunk of data.value) {
|
for (chunk of data.value) {
|
||||||
full_text += chunk['text'];
|
full_text += chunk['text'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We run do_prompt multiple times; delete old prompt messages
|
||||||
|
$(".chat-message").remove();
|
||||||
|
|
||||||
let previous = null
|
let previous = null
|
||||||
for (const message of parseChatMessages(full_text)) {
|
for (const message of parseChatMessages(full_text)) {
|
||||||
addMessage(message.author, message.text, -1, previous);
|
addMessage(message.author, message.text, -1, previous);
|
||||||
@@ -505,6 +528,7 @@ function do_prompt(data) {
|
|||||||
document.getElementById('input_text').placeholder = "Enter Prompt Here (shift+enter for new line)";
|
document.getElementById('input_text').placeholder = "Enter Prompt Here (shift+enter for new line)";
|
||||||
document.getElementById('input_text').disabled = false;
|
document.getElementById('input_text').disabled = false;
|
||||||
document.getElementById('themerow').classList.remove("hidden");
|
document.getElementById('themerow').classList.remove("hidden");
|
||||||
|
addInitChatMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -727,12 +751,18 @@ function var_changed(data) {
|
|||||||
update_context(data.value);
|
update_context(data.value);
|
||||||
//special case for story_actionmode
|
//special case for story_actionmode
|
||||||
} else if (data.classname == "story" && data.name == "actionmode") {
|
} else if (data.classname == "story" && data.name == "actionmode") {
|
||||||
|
story.mode = data.value;
|
||||||
|
|
||||||
const button = document.getElementById('adventure_mode');
|
const button = document.getElementById('adventure_mode');
|
||||||
if (data.value == 1) {
|
if (data.value == 1) {
|
||||||
button.childNodes[1].textContent = "Adventure";
|
button.childNodes[1].textContent = "Adventure";
|
||||||
} else {
|
} else {
|
||||||
button.childNodes[1].textContent = "Story";
|
button.childNodes[1].textContent = "Story";
|
||||||
}
|
}
|
||||||
|
// Special case for chat style
|
||||||
|
} else if (data.classname == "story" && data.name == "chat_style") {
|
||||||
|
chat.style = data.value;
|
||||||
|
updateChatStyle();
|
||||||
//Special Case for story picture
|
//Special Case for story picture
|
||||||
} else if (data.classname == "story" && data.name == "picture") {
|
} else if (data.classname == "story" && data.name == "picture") {
|
||||||
image_area = document.getElementById("action image");
|
image_area = document.getElementById("action image");
|
||||||
@@ -5868,15 +5898,43 @@ function addMessage(author, content, actionId, afterMsgEl=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addAfterButton.addEventListener("click", function() {
|
addAfterButton.addEventListener("click", function() {
|
||||||
addMessage("", "", actionId, message)
|
addMessage(null, null, actionId, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteButton.addEventListener("click", function() {
|
deleteButton.addEventListener("click", function() {
|
||||||
message.remove();
|
message.remove();
|
||||||
computeChatGametext(actionId);
|
computeChatGametext(actionId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addInitChatMessage() {
|
||||||
|
if (!chat.useV2) return;
|
||||||
|
|
||||||
|
// Already exists!
|
||||||
|
if ($el("#init-message")) return;
|
||||||
|
|
||||||
|
let message = addMessage(null, null, -1);
|
||||||
|
message.id = "init-message";
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteChatPromptIfEmpty() {
|
||||||
|
if (!chat.useV2) return;
|
||||||
|
|
||||||
|
const prompt = $el("#init-message");
|
||||||
|
if (!prompt) return;
|
||||||
|
|
||||||
|
let author = prompt.getElementsByClassName("chat-author")[0].innerText;
|
||||||
|
let content = prompt.getElementsByClassName("chat-text")[0].innerText;
|
||||||
|
if (author || content) return;
|
||||||
|
|
||||||
|
prompt.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial message
|
||||||
|
//addMessage(null, null, -1);
|
||||||
|
|
||||||
function computeChatGametext(actionId) {
|
function computeChatGametext(actionId) {
|
||||||
// TODO: Customizable format?
|
// TODO: Customizable format?
|
||||||
let lines = [];
|
let lines = [];
|
||||||
@@ -5889,5 +5947,9 @@ function computeChatGametext(actionId) {
|
|||||||
let text = lines.join("\n");
|
let text = lines.join("\n");
|
||||||
console.log(actionId, text);
|
console.log(actionId, text);
|
||||||
socket.emit("Set Selected Text", {id: actionId, text: text});
|
socket.emit("Set Selected Text", {id: actionId, text: text});
|
||||||
chatv2LastEdit = actionId;
|
chat.lastEdit = actionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateChatStyle() {
|
||||||
|
console.log("hehehohohohihihihi")
|
||||||
}
|
}
|
Reference in New Issue
Block a user