mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Togglable multigen
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
<title>Tavern.AI</title>
|
<title>Tavern.AI</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body class="no-blur">
|
||||||
|
|
||||||
<div id="bg1"></div>
|
<div id="bg1"></div>
|
||||||
<div id="bg2"></div>
|
<div id="bg2"></div>
|
||||||
@@ -808,9 +808,19 @@
|
|||||||
<input id="always-force-name2-checkbox" type="checkbox" />
|
<input id="always-force-name2-checkbox" type="checkbox" />
|
||||||
Always add character's name to prompt
|
Always add character's name to prompt
|
||||||
</label>
|
</label>
|
||||||
<label class="checkbox_label" for="force-pygmalion-formatting-checkbox"><input id="force-pygmalion-formatting-checkbox" type="checkbox" />
|
<label class="checkbox_label" for="force-pygmalion-formatting-checkbox">
|
||||||
|
<input id="force-pygmalion-formatting-checkbox" type="checkbox" />
|
||||||
Pygmalion Formatting for All Models
|
Pygmalion Formatting for All Models
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox_label" for="multigen">
|
||||||
|
<input id="multigen" type="checkbox" />
|
||||||
|
<span>
|
||||||
|
Multigen
|
||||||
|
<a href="/notes/multigen" class="notes-link" target="_blank">
|
||||||
|
<span class="note-link-span">?</span>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
<label class="checkbox_label" for="pin-examples-checkbox"><input id="pin-examples-checkbox" type="checkbox" />
|
<label class="checkbox_label" for="pin-examples-checkbox"><input id="pin-examples-checkbox" type="checkbox" />
|
||||||
Keep Example Messages in Prompt
|
Keep Example Messages in Prompt
|
||||||
</label>
|
</label>
|
||||||
|
33
public/notes/multigen.html
Normal file
33
public/notes/multigen.html
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Multigen</title>
|
||||||
|
<link rel="stylesheet" href="/css/notes.css">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
|
||||||
|
<link
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
|
||||||
|
rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="main">
|
||||||
|
<div id="content">
|
||||||
|
<h2>Multigen</h2>
|
||||||
|
<p>TavernAI tries to create longer responses by chaining the generation using smaller batches.</p>
|
||||||
|
<h3>Algorithm:</h3>
|
||||||
|
<p>1. If amount of generation is more than 50 tokens, then generate first 50 tokens.</p>
|
||||||
|
<p>2. Generate by 30 tokens until one of the stopping conditions is reached.</p>
|
||||||
|
<p>3. Append the generated batch to the next cycle's prompt.</p>
|
||||||
|
<h3>Stopping conditions:</h3>
|
||||||
|
<p>1. Generated enough text.</p>
|
||||||
|
<p>2. Character starts speaking for You.</p>
|
||||||
|
<p>3. <tt><|endoftext|></tt> token reached.</p>
|
||||||
|
<p>4. No text generated.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@@ -47,6 +47,7 @@ import {
|
|||||||
disable_scenario_formatting,
|
disable_scenario_formatting,
|
||||||
always_force_name2,
|
always_force_name2,
|
||||||
custom_chat_separator,
|
custom_chat_separator,
|
||||||
|
multigen,
|
||||||
} from "./scripts/power-user.js";
|
} from "./scripts/power-user.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -129,7 +130,6 @@ export {
|
|||||||
// API OBJECT FOR EXTERNAL WIRING
|
// API OBJECT FOR EXTERNAL WIRING
|
||||||
window["TavernAI"] = {};
|
window["TavernAI"] = {};
|
||||||
|
|
||||||
const VERSION = "1.2.0";
|
|
||||||
let converter = new showdown.Converter({ emoji: "true" });
|
let converter = new showdown.Converter({ emoji: "true" });
|
||||||
/* let bg_menu_toggle = false; */
|
/* let bg_menu_toggle = false; */
|
||||||
const systemUserName = "TavernAI";
|
const systemUserName = "TavernAI";
|
||||||
@@ -385,7 +385,6 @@ $.get("/csrf-token").then((data) => {
|
|||||||
token = data.token;
|
token = data.token;
|
||||||
getCharacters();
|
getCharacters();
|
||||||
getSettings("def");
|
getSettings("def");
|
||||||
getLastVersion();
|
|
||||||
sendSystemMessage(system_message_types.WELCOME);
|
sendSystemMessage(system_message_types.WELCOME);
|
||||||
getBackgrounds();
|
getBackgrounds();
|
||||||
getUserAvatars();
|
getUserAvatars();
|
||||||
@@ -424,34 +423,6 @@ function checkOnlineStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///// DO WE STILL NEED THIS?
|
|
||||||
async function getLastVersion() {
|
|
||||||
jQuery.ajax({
|
|
||||||
type: "POST", //
|
|
||||||
url: "/getlastversion", //
|
|
||||||
data: JSON.stringify({
|
|
||||||
"": "",
|
|
||||||
}),
|
|
||||||
beforeSend: function () { },
|
|
||||||
cache: false,
|
|
||||||
dataType: "json",
|
|
||||||
contentType: "application/json",
|
|
||||||
//processData: false,
|
|
||||||
success: function (data) {
|
|
||||||
var getVersion = data.version;
|
|
||||||
if (getVersion !== "error" && getVersion != undefined) {
|
|
||||||
if (compareVersions(getVersion, VERSION) === 1) {
|
|
||||||
$("#verson").append(" <span>(v." + getVersion + ")</span>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function (jqXHR, exception) {
|
|
||||||
console.log(exception);
|
|
||||||
console.log(jqXHR);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getStatus() {
|
async function getStatus() {
|
||||||
if (is_get_status) {
|
if (is_get_status) {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
@@ -1473,7 +1444,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
|
|
||||||
const zeroDepthAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, 0, ' ');
|
const zeroDepthAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, 0, ' ');
|
||||||
if (zeroDepthAnchor && zeroDepthAnchor.length) {
|
if (zeroDepthAnchor && zeroDepthAnchor.length) {
|
||||||
if (!is_pygmalion || tokens_already_generated == 0) {
|
if (!isMultigenEnabled() || tokens_already_generated == 0) {
|
||||||
const trimBothEnds = !force_name2 && !is_pygmalion;
|
const trimBothEnds = !force_name2 && !is_pygmalion;
|
||||||
finalPromt += (trimBothEnds ? zeroDepthAnchor.trim() : zeroDepthAnchor.trimEnd());
|
finalPromt += (trimBothEnds ? zeroDepthAnchor.trim() : zeroDepthAnchor.trimEnd());
|
||||||
}
|
}
|
||||||
@@ -1486,13 +1457,10 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
}
|
}
|
||||||
|
|
||||||
//console.log('final prompt decided');
|
//console.log('final prompt decided');
|
||||||
|
let this_amount_gen = parseInt(amount_gen); // how many tokens the AI will be requested to generate
|
||||||
|
let this_settings = koboldai_settings[koboldai_setting_names[preset_settings]];
|
||||||
|
|
||||||
//if we aren't using the kobold GUI settings...
|
if (isMultigenEnabled()) {
|
||||||
if (main_api == 'textgenerationwebui' || main_api == 'kobold' && preset_settings != 'gui') {
|
|
||||||
var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]];
|
|
||||||
|
|
||||||
var this_amount_gen = parseInt(amount_gen); // how many tokens the AI will be requested to generate
|
|
||||||
if (is_pygmalion) { // if we are using a pygmalion model...
|
|
||||||
if (tokens_already_generated === 0) { // if nothing has been generated yet..
|
if (tokens_already_generated === 0) { // if nothing has been generated yet..
|
||||||
if (parseInt(amount_gen) >= 50) { // if the max gen setting is > 50...(
|
if (parseInt(amount_gen) >= 50) { // if the max gen setting is > 50...(
|
||||||
this_amount_gen = 50; // then only try to make 50 this cycle..
|
this_amount_gen = 50; // then only try to make 50 this cycle..
|
||||||
@@ -1510,7 +1478,6 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var generate_data;
|
var generate_data;
|
||||||
if (main_api == 'kobold') {
|
if (main_api == 'kobold') {
|
||||||
@@ -1666,25 +1633,25 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
getMessage = collapseNewlines(getMessage);
|
getMessage = collapseNewlines(getMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Pygmalion run again // to make it continue generating so long as it's under max_amount and hasn't signaled
|
//Pygmalion run again
|
||||||
|
// to make it continue generating so long as it's under max_amount and hasn't signaled
|
||||||
// an end to the character's response via typing "You:" or adding "<endoftext>"
|
// an end to the character's response via typing "You:" or adding "<endoftext>"
|
||||||
if (is_pygmalion) {
|
if (isMultigenEnabled()) {
|
||||||
if_typing_text = false;
|
if_typing_text = false;
|
||||||
message_already_generated += getMessage;
|
message_already_generated += getMessage;
|
||||||
promptBias = '';
|
promptBias = '';
|
||||||
//console.log('AI Response so far: '+message_already_generated);
|
|
||||||
if (message_already_generated.indexOf('You:') === -1 && //if there is no 'You:' in the response msg
|
if (message_already_generated.indexOf('You:') === -1 && //if there is no 'You:' in the response msg
|
||||||
message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no <endoftext> stamp in the response msg
|
message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no <endoftext> stamp in the response msg
|
||||||
tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length..
|
tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length..
|
||||||
getMessage.length > 0) { //if we actually have gen'd text at all...
|
getMessage.length > 0) { //if we actually have gen'd text at all...
|
||||||
runGenerate(getMessage);
|
runGenerate(getMessage);
|
||||||
console.log('returning to make pyg generate again'); //generate again with the 'GetMessage' argument..
|
console.log('returning to make generate again'); //generate again with the 'GetMessage' argument..
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessage = message_already_generated;
|
getMessage = message_already_generated;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Formating
|
//Formating
|
||||||
getMessage = $.trim(getMessage);
|
getMessage = $.trim(getMessage);
|
||||||
if (is_pygmalion) {
|
if (is_pygmalion) {
|
||||||
@@ -1796,6 +1763,10 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
console.log('generate ending');
|
console.log('generate ending');
|
||||||
} //generate ends
|
} //generate ends
|
||||||
|
|
||||||
|
function isMultigenEnabled() {
|
||||||
|
return multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
||||||
|
}
|
||||||
|
|
||||||
function activateSendButtons() {
|
function activateSendButtons() {
|
||||||
is_send_press = false;
|
is_send_press = false;
|
||||||
$("#send_but").css("display", "inline");
|
$("#send_but").css("display", "inline");
|
||||||
|
@@ -9,6 +9,7 @@ export {
|
|||||||
always_force_name2,
|
always_force_name2,
|
||||||
custom_chat_separator,
|
custom_chat_separator,
|
||||||
fast_ui_mode,
|
fast_ui_mode,
|
||||||
|
multigen,
|
||||||
};
|
};
|
||||||
|
|
||||||
let collapse_newlines = false;
|
let collapse_newlines = false;
|
||||||
@@ -19,6 +20,7 @@ let disable_scenario_formatting = false;
|
|||||||
let disable_personality_formatting = false;
|
let disable_personality_formatting = false;
|
||||||
let always_force_name2 = false;
|
let always_force_name2 = false;
|
||||||
let fast_ui_mode = false;
|
let fast_ui_mode = false;
|
||||||
|
let multigen = false;
|
||||||
let custom_chat_separator = '';
|
let custom_chat_separator = '';
|
||||||
|
|
||||||
const storage_keys = {
|
const storage_keys = {
|
||||||
@@ -31,6 +33,7 @@ const storage_keys = {
|
|||||||
always_force_name2: "TavernAI_always_force_name2",
|
always_force_name2: "TavernAI_always_force_name2",
|
||||||
custom_chat_separator: "TavernAI_custom_chat_separator",
|
custom_chat_separator: "TavernAI_custom_chat_separator",
|
||||||
fast_ui_mode: "TavernAI_fast_ui_mode",
|
fast_ui_mode: "TavernAI_fast_ui_mode",
|
||||||
|
multigen: "TavernAI_multigen",
|
||||||
};
|
};
|
||||||
|
|
||||||
function collapseNewlines(x) {
|
function collapseNewlines(x) {
|
||||||
@@ -59,6 +62,7 @@ function loadPowerUserSettings() {
|
|||||||
always_force_name2 = localStorage.getItem(storage_keys.always_force_name2) == "true";
|
always_force_name2 = localStorage.getItem(storage_keys.always_force_name2) == "true";
|
||||||
custom_chat_separator = localStorage.getItem(storage_keys.custom_chat_separator);
|
custom_chat_separator = localStorage.getItem(storage_keys.custom_chat_separator);
|
||||||
fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
fast_ui_mode = localStorage.getItem(storage_keys.fast_ui_mode) == "true";
|
||||||
|
multigen = localStorage.getItem(storage_keys.multigen) == "true";
|
||||||
|
|
||||||
$("#force-pygmalion-formatting-checkbox").prop("checked", force_pygmalion_formatting);
|
$("#force-pygmalion-formatting-checkbox").prop("checked", force_pygmalion_formatting);
|
||||||
$("#collapse-newlines-checkbox").prop("checked", collapse_newlines);
|
$("#collapse-newlines-checkbox").prop("checked", collapse_newlines);
|
||||||
@@ -69,6 +73,7 @@ function loadPowerUserSettings() {
|
|||||||
$("#always-force-name2-checkbox").prop("checked", always_force_name2);
|
$("#always-force-name2-checkbox").prop("checked", always_force_name2);
|
||||||
$("#custom_chat_separator").val(custom_chat_separator);
|
$("#custom_chat_separator").val(custom_chat_separator);
|
||||||
$("#fast_ui_mode").prop("checked", fast_ui_mode);
|
$("#fast_ui_mode").prop("checked", fast_ui_mode);
|
||||||
|
$("#multigen").prop("checked", multigen);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
@@ -120,4 +125,9 @@ $(document).ready(() => {
|
|||||||
localStorage.setItem(storage_keys.fast_ui_mode, fast_ui_mode);
|
localStorage.setItem(storage_keys.fast_ui_mode, fast_ui_mode);
|
||||||
switchUiMode();
|
switchUiMode();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#multigen").change(function () {
|
||||||
|
multigen = $(this).prop("checked");
|
||||||
|
localStorage.setItem(storage_keys.multigen, multigen);
|
||||||
|
});
|
||||||
});
|
});
|
28
server.js
28
server.js
@@ -215,34 +215,6 @@ app.get("/notes/*", function (request, response) {
|
|||||||
response.sendFile(__dirname + "/public" + request.url + ".html");
|
response.sendFile(__dirname + "/public" + request.url + ".html");
|
||||||
//response.send("<h1>Главная страница</h1>");
|
//response.send("<h1>Главная страница</h1>");
|
||||||
});
|
});
|
||||||
app.post("/getlastversion", jsonParser, function (request, response_getlastversion = response) {
|
|
||||||
if (!request.body) return response_getlastversion.sendStatus(400);
|
|
||||||
|
|
||||||
const repo = 'SillyLossy/TavernAI';
|
|
||||||
let req;
|
|
||||||
req = https.request({
|
|
||||||
hostname: 'github.com',
|
|
||||||
path: `/${repo}/releases/latest`,
|
|
||||||
method: 'HEAD'
|
|
||||||
}, (res) => {
|
|
||||||
if (res.statusCode === 302) {
|
|
||||||
const glocation = res.headers.location;
|
|
||||||
const versionStartIndex = glocation.lastIndexOf('/tag/') + 5;
|
|
||||||
const version = glocation.substring(versionStartIndex);
|
|
||||||
//console.log(version);
|
|
||||||
response_getlastversion.send({ version: version });
|
|
||||||
} else {
|
|
||||||
response_getlastversion.send({ version: 'error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
|
||||||
console.error(error);
|
|
||||||
response_getlastversion.send({ version: 'error' });
|
|
||||||
});
|
|
||||||
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
//**************Kobold api
|
//**************Kobold api
|
||||||
app.post("/generate", jsonParser, async function (request, response_generate = response) {
|
app.post("/generate", jsonParser, async function (request, response_generate = response) {
|
||||||
|
Reference in New Issue
Block a user