mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add support for text generation UI (by @im-not-tom)
This commit is contained in:
@ -156,6 +156,7 @@
|
|||||||
var online_status = 'no_connection';
|
var online_status = 'no_connection';
|
||||||
|
|
||||||
var api_server = "";
|
var api_server = "";
|
||||||
|
var api_server_textgenerationwebui = "";
|
||||||
//var interval_timer = setInterval(getStatus, 2000);
|
//var interval_timer = setInterval(getStatus, 2000);
|
||||||
var interval_timer_novel = setInterval(getStatusNovel, 3000);
|
var interval_timer_novel = setInterval(getStatusNovel, 3000);
|
||||||
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
||||||
@ -193,6 +194,16 @@
|
|||||||
var rep_pen = 1;
|
var rep_pen = 1;
|
||||||
var rep_pen_size = 100;
|
var rep_pen_size = 100;
|
||||||
|
|
||||||
|
var textgenerationwebui_settings = {
|
||||||
|
temp: 0.5,
|
||||||
|
top_p: 0.9,
|
||||||
|
top_k: 0,
|
||||||
|
typical_p: 1,
|
||||||
|
rep_pen: 1.1,
|
||||||
|
rep_pen_size: 0,
|
||||||
|
penalty_alpha: 0,
|
||||||
|
}
|
||||||
|
|
||||||
var is_pygmalion = false;
|
var is_pygmalion = false;
|
||||||
var tokens_already_generated = 0;
|
var tokens_already_generated = 0;
|
||||||
var message_already_generated = '';
|
var message_already_generated = '';
|
||||||
@ -353,6 +364,8 @@
|
|||||||
$("#online_status_text2").html(online_status);
|
$("#online_status_text2").html(online_status);
|
||||||
$("#online_status_indicator3").css("background-color", "green");
|
$("#online_status_indicator3").css("background-color", "green");
|
||||||
$("#online_status_text3").html(online_status);
|
$("#online_status_text3").html(online_status);
|
||||||
|
$("#online_status_indicator4").css("background-color", "green");
|
||||||
|
$("#online_status_text4").html(online_status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function getLastVersion(){
|
async function getLastVersion(){
|
||||||
@ -394,7 +407,8 @@
|
|||||||
type: 'POST', //
|
type: 'POST', //
|
||||||
url: '/getstatus', //
|
url: '/getstatus', //
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
api_server: api_server
|
api_server: (main_api == "kobold" ? api_server : api_server_textgenerationwebui),
|
||||||
|
main_api: main_api,
|
||||||
}),
|
}),
|
||||||
beforeSend: function(){
|
beforeSend: function(){
|
||||||
if(is_api_button_press){
|
if(is_api_button_press){
|
||||||
@ -446,6 +460,8 @@
|
|||||||
checkOnlineStatus();
|
checkOnlineStatus();
|
||||||
$("#api_loading").css("display", 'none');
|
$("#api_loading").css("display", 'none');
|
||||||
$("#api_button").css("display", 'inline-block');
|
$("#api_button").css("display", 'inline-block');
|
||||||
|
$("#api_loading_textgenerationwebui").css("display", 'none');
|
||||||
|
$("#api_button_textgenerationwebui").css("display", 'inline-block');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSoftPromptsList() {
|
async function getSoftPromptsList() {
|
||||||
@ -1433,37 +1449,35 @@
|
|||||||
finalPromt = worldInfoBefore+storyString+worldInfoAfter+extension_prompt+mesExmString+mesSendString+generatedPromtCache+promptBias;
|
finalPromt = worldInfoBefore+storyString+worldInfoAfter+extension_prompt+mesExmString+mesSendString+generatedPromtCache+promptBias;
|
||||||
finalPromt = finalPromt.replace(/\r/gm, '');
|
finalPromt = finalPromt.replace(/\r/gm, '');
|
||||||
|
|
||||||
|
//if we aren't using the kobold GUI settings...
|
||||||
|
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(parseInt(amount_gen) >= 50){ // if the max gen setting is > 50...(
|
||||||
|
this_amount_gen = 50; // then only try to make 50 this cycle..
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this_amount_gen = parseInt(amount_gen); // otherwise, make as much as the max amount request.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{ // if we already recieved some generated text...
|
||||||
|
if(parseInt(amount_gen) - tokens_already_generated < tokens_cycle_count){ // if the remaining tokens to be made is less than next potential cycle count
|
||||||
|
this_amount_gen = parseInt(amount_gen) - tokens_already_generated; // subtract already generated amount from the desired max gen amount
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this_amount_gen = tokens_cycle_count; // otherwise make the standard cycle amont (frist 50, and 30 after that)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var generate_data;
|
var generate_data;
|
||||||
if(main_api == 'kobold'){
|
if(main_api == 'kobold'){
|
||||||
var generate_data = {prompt: finalPromt, gui_settings: true,max_length: amount_gen,temperature: temp, max_context_length: max_context};
|
var generate_data = {prompt: finalPromt, gui_settings: true,max_length: amount_gen,temperature: temp, max_context_length: max_context};
|
||||||
if(preset_settings != 'gui'){ //if we aren't using the kobold GUI settings...
|
if(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(parseInt(amount_gen) >= 50){ // if the max gen setting is > 50...(
|
|
||||||
this_amount_gen = 50; // then only try to make 50 this cycle..
|
|
||||||
}else{
|
|
||||||
this_amount_gen = parseInt(amount_gen); // otherwise, make as much as the max amount request.
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log('Max Gen Amount: '+parseInt(amount_gen));
|
|
||||||
|
|
||||||
}else{ // if we already recieved some generated text...
|
|
||||||
if(parseInt(amount_gen) - tokens_already_generated < tokens_cycle_count){ // if the remaining tokens to be made is less than next potential cycle count
|
|
||||||
this_amount_gen = parseInt(amount_gen) - tokens_already_generated; // subtract already generated amount from the desired max gen amount
|
|
||||||
//console.log('Remaining tokens to be requested: '+this_amount_gen);
|
|
||||||
}else{
|
|
||||||
this_amount_gen = tokens_cycle_count; // otherwise make the standard cycle amont (frist 50, and 30 after that)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log('Upcoming token request amt: '+this_amount_gen);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
//console.log('non-pyg model or GUI Settings are being used -- skipping request split');
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_data = {prompt: finalPromt,
|
generate_data = {prompt: finalPromt,
|
||||||
gui_settings: false,
|
gui_settings: false,
|
||||||
@ -1490,6 +1504,35 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(main_api == 'textgenerationwebui'){
|
||||||
|
const doSample = textgenerationwebui_settings.penalty_alpha == 0;
|
||||||
|
var generate_data = {
|
||||||
|
data: [
|
||||||
|
finalPromt,
|
||||||
|
this_amount_gen, // min_length
|
||||||
|
doSample, // do_sample
|
||||||
|
textgenerationwebui_settings.temp, // temperature
|
||||||
|
textgenerationwebui_settings.top_p, // top_p
|
||||||
|
textgenerationwebui_settings.typical_p, // typical_p
|
||||||
|
textgenerationwebui_settings.rep_pen, // repetition_penalty
|
||||||
|
textgenerationwebui_settings.top_k, // top_k
|
||||||
|
0, // min_length
|
||||||
|
textgenerationwebui_settings.rep_pen_size, // no_repeat_ngram_size
|
||||||
|
1, // num_beams
|
||||||
|
textgenerationwebui_settings.penalty_alpha, // penalty_alpha
|
||||||
|
1, // length_penalty
|
||||||
|
false, // early_stopping
|
||||||
|
name1, // name1
|
||||||
|
name2, // name2
|
||||||
|
"", // Context
|
||||||
|
true, // stop at newline
|
||||||
|
1300, // Maximum prompt size in tokens
|
||||||
|
1, // num attempts
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if(main_api == 'novel'){
|
if(main_api == 'novel'){
|
||||||
var this_settings = novelai_settings[novelai_setting_names[preset_settings_novel]];
|
var this_settings = novelai_settings[novelai_setting_names[preset_settings_novel]];
|
||||||
generate_data = {"input": finalPromt,
|
generate_data = {"input": finalPromt,
|
||||||
@ -1516,8 +1559,9 @@
|
|||||||
var generate_url = '';
|
var generate_url = '';
|
||||||
if(main_api == 'kobold'){
|
if(main_api == 'kobold'){
|
||||||
generate_url = '/generate';
|
generate_url = '/generate';
|
||||||
}
|
} else if(main_api == 'textgenerationwebui') {
|
||||||
if(main_api == 'novel'){
|
generate_url = '/generate_textgenerationwebui';
|
||||||
|
} else if(main_api == 'novel'){
|
||||||
generate_url = '/generate_novelai';
|
generate_url = '/generate_novelai';
|
||||||
}
|
}
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
@ -1538,13 +1582,20 @@
|
|||||||
//$("#send_textarea").focus();
|
//$("#send_textarea").focus();
|
||||||
//$("#send_textarea").removeAttr('disabled');
|
//$("#send_textarea").removeAttr('disabled');
|
||||||
is_send_press = false;
|
is_send_press = false;
|
||||||
if(data.error != true){
|
if(!data.error) {
|
||||||
//const getData = await response.json();
|
//const getData = await response.json();
|
||||||
|
var getMessage = "";
|
||||||
if(main_api == 'kobold'){
|
if(main_api == 'kobold'){
|
||||||
var getMessage = data.results[0].text;
|
getMessage = data.results[0].text;
|
||||||
}
|
} else if (main_api == 'textgenerationwebui') {
|
||||||
if(main_api == 'novel'){
|
getMessage = data.data[0];
|
||||||
var getMessage = data.output;
|
if (getMessage == null) {
|
||||||
|
runGenerate("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getMessage = getMessage.substring(finalPromt.length);
|
||||||
|
} else if(main_api == 'novel'){
|
||||||
|
getMessage = data.output;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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
|
||||||
@ -2970,6 +3021,7 @@
|
|||||||
api_server = api_server+"/api";
|
api_server = api_server+"/api";
|
||||||
}
|
}
|
||||||
//console.log("2: "+api_server);
|
//console.log("2: "+api_server);
|
||||||
|
main_api = "kobold";
|
||||||
saveSettings();
|
saveSettings();
|
||||||
is_get_status = true;
|
is_get_status = true;
|
||||||
is_api_button_press = true;
|
is_api_button_press = true;
|
||||||
@ -2980,7 +3032,26 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$(document).on('click', function(event) { // this makes the input bar's option menu disappear when clicked away from
|
$( "#api_button_textgenerationwebui" ).click(function() {
|
||||||
|
if($('#textgenerationwebui_api_url_text').val() != ''){
|
||||||
|
$("#api_loading_textgenerationwebui").css("display", 'inline-block');
|
||||||
|
$("#api_button_textgenerationwebui").css("display", 'none');
|
||||||
|
api_server_textgenerationwebui = $('#textgenerationwebui_api_url_text').val();
|
||||||
|
api_server_textgenerationwebui = $.trim(api_server_textgenerationwebui);
|
||||||
|
if(api_server_textgenerationwebui.substr(api_server_textgenerationwebui.length-1,1) == "/"){
|
||||||
|
api_server_textgenerationwebui = api_server_textgenerationwebui.substr(0,api_server_textgenerationwebui.length-1);
|
||||||
|
}
|
||||||
|
//console.log("2: "+api_server_textgenerationwebui);
|
||||||
|
main_api = "textgenerationwebui";
|
||||||
|
saveSettings();
|
||||||
|
is_get_status = true;
|
||||||
|
is_api_button_press = true;
|
||||||
|
getStatus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$( "body" ).click(function() {
|
||||||
if($("#options").css('opacity') == 1.0){
|
if($("#options").css('opacity') == 1.0){
|
||||||
$('#options').transition({
|
$('#options').transition({
|
||||||
opacity: 0.0,
|
opacity: 0.0,
|
||||||
@ -3231,14 +3302,26 @@
|
|||||||
if($('#main_api').find(":selected").val() == 'kobold'){
|
if($('#main_api').find(":selected").val() == 'kobold'){
|
||||||
$('#kobold_api').css("display", "block");
|
$('#kobold_api').css("display", "block");
|
||||||
$('#novel_api').css("display", "none");
|
$('#novel_api').css("display", "none");
|
||||||
|
$('#textgenerationwebui_api').css("display", "none");
|
||||||
main_api = 'kobold';
|
main_api = 'kobold';
|
||||||
$('#max_context_block').css('display', 'block');
|
$('#max_context_block').css('display', 'block');
|
||||||
$('#amount_gen_block').css('display', 'block');
|
$('#amount_gen_block').css('display', 'block');
|
||||||
$('#softprompt_block').css('display', 'block');
|
$('#softprompt_block').css('display', 'block');
|
||||||
}
|
}
|
||||||
|
if($('#main_api').find(":selected").val() == 'textgenerationwebui'){
|
||||||
|
$('#kobold_api').css("display", "none");
|
||||||
|
$('#novel_api').css("display", "none");
|
||||||
|
$('#textgenerationwebui_api').css("display", "block");
|
||||||
|
main_api = 'textgenerationwebui';
|
||||||
|
$('#max_context_block').css('display', 'block');
|
||||||
|
$('#amount_gen_block').css('display', 'block');
|
||||||
|
$('#softprompt_block').css('display', 'block');
|
||||||
|
}
|
||||||
|
|
||||||
if($('#main_api').find(":selected").val() == 'novel'){
|
if($('#main_api').find(":selected").val() == 'novel'){
|
||||||
$('#kobold_api').css("display", "none");
|
$('#kobold_api').css("display", "none");
|
||||||
$('#novel_api').css("display", "block");
|
$('#novel_api').css("display", "block");
|
||||||
|
$('#textgenerationwebui_api').css("display", "none");
|
||||||
main_api = 'novel';
|
main_api = 'novel';
|
||||||
$('#max_context_block').css('display', 'none');
|
$('#max_context_block').css('display', 'none');
|
||||||
$('#amount_gen_block').css('display', 'none');
|
$('#amount_gen_block').css('display', 'none');
|
||||||
@ -3285,6 +3368,21 @@
|
|||||||
highlightSelectedAvatar();
|
highlightSelectedAvatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i of ["temp", "rep_pen", "rep_pen_size", "top_k", "top_p", "typical_p", "penalty_alpha"]) {
|
||||||
|
$('#' + i + '_textgenerationwebui').attr('x-setting-id', i);
|
||||||
|
$(document).on('input', '#' + i + '_textgenerationwebui', function() {
|
||||||
|
var i = $(this).attr('x-setting-id');
|
||||||
|
var val = $(this).val();
|
||||||
|
if(isInt(val)){
|
||||||
|
$('#' + i + '_counter_textgenerationwebui').html( $(this).val()+".00" );
|
||||||
|
}else{
|
||||||
|
$('#' + i + '_counter_textgenerationwebui').html( $(this).val() );
|
||||||
|
}
|
||||||
|
textgenerationwebui_settings[i] = parseFloat(val);
|
||||||
|
setTimeout(saveSettings, 500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on('input', '#temp', function() {
|
$(document).on('input', '#temp', function() {
|
||||||
temp = $(this).val();
|
temp = $(this).val();
|
||||||
if(isInt(temp)){
|
if(isInt(temp)){
|
||||||
@ -3453,6 +3551,9 @@
|
|||||||
preset_settings = settings.preset_settings;
|
preset_settings = settings.preset_settings;
|
||||||
|
|
||||||
//Load AI model config settings (temp, context length, anchors, and anchor order)
|
//Load AI model config settings (temp, context length, anchors, and anchor order)
|
||||||
|
|
||||||
|
textgenerationwebui_settings = settings.textgenerationwebui_settings || textgenerationwebui_settings;
|
||||||
|
|
||||||
temp = settings.temp;
|
temp = settings.temp;
|
||||||
amount_gen = settings.amount_gen;
|
amount_gen = settings.amount_gen;
|
||||||
if(settings.max_context !== undefined) max_context = parseInt(settings.max_context);
|
if(settings.max_context !== undefined) max_context = parseInt(settings.max_context);
|
||||||
@ -3589,8 +3690,18 @@
|
|||||||
active_character = settings.active_character;
|
active_character = settings.active_character;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
api_server_textgenerationwebui = settings.api_server_textgenerationwebui;
|
||||||
|
$("#textgenerationwebui_api_url_text").val(api_server_textgenerationwebui);
|
||||||
|
|
||||||
|
|
||||||
|
for (var i of ["temp", "rep_pen", "rep_pen_size", "top_k", "top_p", "typical_p", "penalty_alpha"]) {
|
||||||
|
$("#" + i + "_textgenerationwebui")
|
||||||
|
.val(textgenerationwebui_settings[i]);
|
||||||
|
$("#" + i + "_counter_textgenerationwebui")
|
||||||
|
.html(textgenerationwebui_settings[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!is_checked_colab) isColab();
|
if(!is_checked_colab) isColab();
|
||||||
},
|
},
|
||||||
error: function (jqXHR, exception) {
|
error: function (jqXHR, exception) {
|
||||||
@ -3599,8 +3710,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveSettings(type){
|
async function saveSettings(type){
|
||||||
//console.log('saveSettings() -- pinging server to save settings.');
|
//console.log('saveSettings() -- pinging server to save settings.');
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
@ -3609,6 +3720,7 @@
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
username: name1,
|
username: name1,
|
||||||
api_server: api_server,
|
api_server: api_server,
|
||||||
|
api_server_textgenerationwebui: api_server_textgenerationwebui,
|
||||||
preset_settings: preset_settings,
|
preset_settings: preset_settings,
|
||||||
preset_settings_novel: preset_settings_novel,
|
preset_settings_novel: preset_settings_novel,
|
||||||
user_avatar: user_avatar,
|
user_avatar: user_avatar,
|
||||||
@ -3631,7 +3743,8 @@
|
|||||||
world_info: world_info,
|
world_info: world_info,
|
||||||
world_info_depth: world_info_depth,
|
world_info_depth: world_info_depth,
|
||||||
world_info_budget: world_info_budget,
|
world_info_budget: world_info_budget,
|
||||||
active_character: active_character
|
active_character: active_character,
|
||||||
|
textgenerationwebui_settings: textgenerationwebui_settings,
|
||||||
}),
|
}),
|
||||||
beforeSend: function(){
|
beforeSend: function(){
|
||||||
//console.log('saveSettings() -- active_character -- '+active_character);
|
//console.log('saveSettings() -- active_character -- '+active_character);
|
||||||
@ -5019,6 +5132,7 @@
|
|||||||
<h3 id="title_api">API</h3>
|
<h3 id="title_api">API</h3>
|
||||||
<select id="main_api" >
|
<select id="main_api" >
|
||||||
<option value="kobold">KoboldAI</option>
|
<option value="kobold">KoboldAI</option>
|
||||||
|
<option value="textgenerationwebui">Text generation web UI</option>
|
||||||
<option value="novel">NovelAI</option>
|
<option value="novel">NovelAI</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -5076,6 +5190,39 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="textgenerationwebui_api" style="display: none;position: relative;">
|
||||||
|
<div class="oobabooga_logo"><a href="https://github.com/oobabooga/text-generation-webui" target="_blank">
|
||||||
|
oobabooga/text-generation-webui
|
||||||
|
</a></div>
|
||||||
|
<form action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
||||||
|
|
||||||
|
<h4>API url</h4><h5>Example: http://127.0.0.1:7860/ </h5>
|
||||||
|
<input id="textgenerationwebui_api_url_text" name="textgenerationwebui_api_url" class="text_pole" maxlength="500" size="35" value="" autocomplete="off">
|
||||||
|
<input id="api_button_textgenerationwebui" class="menu_button" type="submit" value="Connect">
|
||||||
|
<img id="api_loading_textgenerationwebui" src="img/load.svg" >
|
||||||
|
</form>
|
||||||
|
<div id="online_status4">
|
||||||
|
<div id="online_status_indicator4"></div><div id="online_status_text4">Not connected</div>
|
||||||
|
</div>
|
||||||
|
<div id="range_block">
|
||||||
|
<h4>Temperature </h4><h5 id="temp_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="temp_textgenerationwebui" name="volume" min="0.1" max="2.0" step="0.01">
|
||||||
|
<h4>Repetition Penalty </h4><h5 id="rep_pen_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="rep_pen_textgenerationwebui" name="volume" min="1" max="1.5" step="0.01">
|
||||||
|
<h4>Repetition Penalty Range</h4><h5 id="rep_pen_size_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="rep_pen_size_textgenerationwebui" name="volume" min="0" max="2048" step="1">
|
||||||
|
|
||||||
|
<h4>Top K</h4><h5 id="top_k_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="top_k_textgenerationwebui" name="volume" min="0" max="200" step="1">
|
||||||
|
<h4>Top P</h4><h5 id="top_p_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="top_p_textgenerationwebui" name="volume" min="0" max="1" step="0.1">
|
||||||
|
<h4>Typical P</h4><h5 id="typical_p_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="typical_p_textgenerationwebui" name="volume" min="0" max="1" step="0.1">
|
||||||
|
<h4>Penalty Alpha</h4><h5 id="penalty_alpha_counter_textgenerationwebui">select</h5>
|
||||||
|
<input type="range" id="penalty_alpha_textgenerationwebui" name="volume" min="0" max="1" step="0.1" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="novel_api" style="display: none;position: relative;"> <!-- shows the novel settings -->
|
<div id="novel_api" style="display: none;position: relative;"> <!-- shows the novel settings -->
|
||||||
<div class="API-logo">
|
<div class="API-logo">
|
||||||
<a href="https://novelai.net/" target="_blank">
|
<a href="https://novelai.net/" target="_blank">
|
||||||
|
@ -1 +1 @@
|
|||||||
{"username":"You","api_server":"http://localhost:5000/api","preset_settings":"gui","preset_settings_novel":"Classic-Euterpe","user_avatar":"legat.png","temp":0.43,"amount_gen":90,"max_context":2048,"anchor_order":0,"style_anchor":false,"character_anchor":true,"main_api":"kobold","api_key_novel":"","rep_pen":1.17,"rep_pen_size":1024,"model_novel":"euterpe-v2","temp_novel":1.11,"rep_pen_novel":1.11,"rep_pen_size_novel":320}
|
{"username":"You","api_server":"http://localhost:5000/api","api_server_textgenerationwebui":"http://127.0.0.1:7860","preset_settings":"gui","preset_settings_novel":"Classic-Euterpe","user_avatar":"legat.png","temp":0.43,"amount_gen":90,"max_context":2048,"anchor_order":0,"style_anchor":false,"character_anchor":true,"auto_connect":false,"auto_load_chat":false,"main_api":"textgenerationwebui","api_key_novel":"","rep_pen":1.17,"rep_pen_size":1024,"model_novel":"euterpe-v2","temp_novel":1.11,"rep_pen_novel":1.11,"rep_pen_size_novel":320,"world_info":null,"world_info_depth":2,"world_info_budget":200,"textgenerationwebui_settings":{"temp":0.5,"top_p":0.9,"top_k":0,"typical_p":1,"rep_pen":1.1,"rep_pen_size":0,"penalty_alpha":0}}
|
@ -631,17 +631,22 @@ select option:not(:checked) { /* works to color unselected items */
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
#api_url_text{
|
.oobabooga_logo {
|
||||||
|
margin: 5px auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#api_url_text, #textgenerationwebui_api_url_text{
|
||||||
/*margin-right: 4px;*/
|
/*margin-right: 4px;*/
|
||||||
display:block;
|
display:block;
|
||||||
}
|
}
|
||||||
#api_button, #api_button_novel {
|
#api_button, #api_button_novel, #api_button_textgenerationwebui {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#api_button:hover, #api_button_novel:hover{background-color:green;}
|
#api_button:hover, #api_button_novel:hover{background-color:green;}
|
||||||
|
|
||||||
#api_loading{
|
#api_loading, #api_loading_textgenerationwebui{
|
||||||
width: 25px;
|
width: 25px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
display: none;
|
display: none;
|
||||||
@ -1078,20 +1083,20 @@ width: 103px;
|
|||||||
background-color: red;
|
background-color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
#online_status2{
|
#online_status2, #online_status4{
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
|
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
#online_status_indicator2{
|
#online_status_indicator2, #online_status_indicator4{
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
height: 14px;
|
height: 14px;
|
||||||
background-color: red;
|
background-color: red;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
#online_status_text2{
|
#online_status_text2, #online_status_text4{
|
||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
73
server.js
73
server.js
@ -31,10 +31,9 @@ const enableExtensions = config.enableExtensions;
|
|||||||
var Client = require('node-rest-client').Client;
|
var Client = require('node-rest-client').Client;
|
||||||
var client = new Client();
|
var client = new Client();
|
||||||
|
|
||||||
var api_server = "";//"http://127.0.0.1:5000";
|
var api_server = "http://0.0.0.0:5000";
|
||||||
//var server_port = 8000;
|
|
||||||
|
|
||||||
var api_novelai = "https://api.novelai.net";
|
var api_novelai = "https://api.novelai.net";
|
||||||
|
var main_api = "kobold";
|
||||||
|
|
||||||
var response_get_story;
|
var response_get_story;
|
||||||
var response_generate;
|
var response_generate;
|
||||||
@ -291,6 +290,38 @@ app.post("/generate", jsonParser, function(request, response_generate = response
|
|||||||
response_generate.send({error: true});
|
response_generate.send({error: true});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//************** Text generation web UI
|
||||||
|
app.post("/generate_textgenerationwebui", jsonParser, function(request, response_generate = response){
|
||||||
|
if(!request.body) return response_generate.sendStatus(400);
|
||||||
|
|
||||||
|
console.log(request.body);
|
||||||
|
var args = {
|
||||||
|
data: request.body,
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
};
|
||||||
|
client.post(api_server+"/run/textgen",args, function (data, response) {
|
||||||
|
console.log("####", data);
|
||||||
|
if(response.statusCode == 200){
|
||||||
|
console.log(data);
|
||||||
|
response_generate.send(data);
|
||||||
|
}
|
||||||
|
if(response.statusCode == 422){
|
||||||
|
console.log('Validation error');
|
||||||
|
response_generate.send({error: true});
|
||||||
|
}
|
||||||
|
if(response.statusCode == 501 || response.statusCode == 503 || response.statusCode == 507){
|
||||||
|
console.log(data);
|
||||||
|
response_generate.send({error: true});
|
||||||
|
}
|
||||||
|
}).on('error', function (err) {
|
||||||
|
console.log(err);
|
||||||
|
//console.log('something went wrong on the request', err.request.options);
|
||||||
|
response_generate.send({error: true});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post("/savechat", jsonParser, function(request, response){
|
app.post("/savechat", jsonParser, function(request, response){
|
||||||
//console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
//console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
||||||
//console.log(request.data);
|
//console.log(request.data);
|
||||||
@ -377,19 +408,39 @@ app.post("/getchat", jsonParser, function(request, response){
|
|||||||
app.post("/getstatus", jsonParser, function(request, response_getstatus = response){
|
app.post("/getstatus", jsonParser, function(request, response_getstatus = response){
|
||||||
if(!request.body) return response_getstatus.sendStatus(400);
|
if(!request.body) return response_getstatus.sendStatus(400);
|
||||||
api_server = request.body.api_server;
|
api_server = request.body.api_server;
|
||||||
|
main_api = request.body.main_api;
|
||||||
if(api_server.indexOf('localhost') != -1){
|
if(api_server.indexOf('localhost') != -1){
|
||||||
api_server = api_server.replace('localhost','127.0.0.1');
|
api_server = api_server.replace('localhost','127.0.0.1');
|
||||||
}
|
}
|
||||||
var args = {
|
var args = {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
client.get(api_server+"/v1/model",args, function (data, response) {
|
var url = api_server+"/v1/model";
|
||||||
|
if (main_api == "textgenerationwebui") {
|
||||||
|
url = api_server;
|
||||||
|
args = {}
|
||||||
|
}
|
||||||
|
client.get(url,args, function (data, response) {
|
||||||
if(response.statusCode == 200){
|
if(response.statusCode == 200){
|
||||||
if(data.result != "ReadOnly"){
|
if (main_api == "textgenerationwebui") {
|
||||||
|
// console.log(body);
|
||||||
//response_getstatus.send(data.result);
|
try {
|
||||||
}else{
|
var body = data.toString();
|
||||||
data.result = "no_connection";
|
var response = body.match(/gradio_config[ =]*(\{.*\});/)[1];
|
||||||
|
if (!response)
|
||||||
|
throw "no_connection";
|
||||||
|
data = {result: JSON.parse(response).components.filter( (x) => x.props.label == "Model" )[0].props.value};
|
||||||
|
if (!data)
|
||||||
|
throw "no_connection";
|
||||||
|
} catch {
|
||||||
|
data = {result: "no_connection"};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(data.result != "ReadOnly"){
|
||||||
|
//response_getstatus.send(data.result);
|
||||||
|
}else{
|
||||||
|
data.result = "no_connection";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
data.result = "no_connection";
|
data.result = "no_connection";
|
||||||
@ -400,8 +451,8 @@ app.post("/getstatus", jsonParser, function(request, response_getstatus = respon
|
|||||||
//response_getstatus.send(data);
|
//response_getstatus.send(data);
|
||||||
//data.results[0].text
|
//data.results[0].text
|
||||||
}).on('error', function (err) {
|
}).on('error', function (err) {
|
||||||
//console.log('');
|
//console.log(url);
|
||||||
//console.log('something went wrong on the request', err.request.options);
|
//console.log('something went wrong on the request', err.request.options);
|
||||||
response_getstatus.send({result: "no_connection"});
|
response_getstatus.send({result: "no_connection"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user