mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add spec_v2 fields
This commit is contained in:
@ -2314,13 +2314,62 @@
|
||||
<div id="character_popup_text">
|
||||
<h3 id="character_popup_text_h3"></h3> - Advanced Definitions
|
||||
</div>
|
||||
<hr>
|
||||
<hr class="margin-bot-10px">
|
||||
<div id="character_cross" class="fa-solid fa-circle-xmark"></div>
|
||||
|
||||
<div id="creatorcomment_div">
|
||||
Creator's Comment
|
||||
<h5>This is not sent to the AI Prompt.
|
||||
<textarea id="creatorcomment_textarea" name="creatorcomment" placeholder="(Describe the bot to the user, list the chat models it has been tested on, and any other useful tips)" form="form_create" class="text_pole" autocomplete="off" rows="2" maxlength="20000"></textarea>
|
||||
<div class="inline-drawer">
|
||||
<div class="inline-drawer-toggle inline-drawer-header">
|
||||
<h4>
|
||||
AI Prompt Overrides
|
||||
<small>(Affects the generation)</small>
|
||||
</h4>
|
||||
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
||||
</div>
|
||||
<div class="inline-drawer-content">
|
||||
<div>
|
||||
<h4>System Prompt</h4>
|
||||
<textarea id="system_prompt_textarea" name="system_prompt"
|
||||
placeholder="(Overrides the main prompt for OpenAI and/or system prompt for Instruct Mode if not empty)"
|
||||
form="form_create" class="text_pole" autocomplete="off" rows="3" maxlength="20000"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Post History Instructions</h4>
|
||||
<textarea id="post_history_instructions_textarea" name="post_history_instructions" placeholder="(Overrides the default jailbreak for OpenAI if not empty)" form="form_create" class="text_pole"
|
||||
autocomplete="off" rows="3" maxlength="100"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline-drawer">
|
||||
<div class="inline-drawer-toggle inline-drawer-header">
|
||||
<h4>
|
||||
Creator's Metadata
|
||||
<small>(Not sent with the AI Prompt)</small>
|
||||
</h4>
|
||||
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
||||
</div>
|
||||
<div class="inline-drawer-content">
|
||||
<div>
|
||||
<h4>Creator's Name</h4>
|
||||
<textarea id="creator_textarea" name="creator" placeholder="(Botmaker's name / Contact info)" form="form_create" class="text_pole"
|
||||
autocomplete="off" rows="1" maxlength="100"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Creator's Notes</h4>
|
||||
<textarea id="creator_notes_textarea" name="creator_notes"
|
||||
placeholder="(Describe the bot to the user, list the chat models it has been tested on, and any other useful tips)"
|
||||
form="form_create" class="text_pole" autocomplete="off" rows="2" maxlength="20000"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Creators's Tags</h4>
|
||||
<textarea id="tags_textarea" name="tags" placeholder="(List of freeform comma-separated tags)" form="form_create"
|
||||
class="text_pole" autocomplete="off" rows="1" maxlength="2000"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Character Version</h4>
|
||||
<textarea id="character_version_textarea" name="character_version" placeholder="(Optional string to track character versions)"
|
||||
form="form_create" class="text_pole" autocomplete="off" rows="1" maxlength="100"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="personality_div">
|
||||
@ -2358,7 +2407,7 @@
|
||||
<h4>Example Dialogue</h4>
|
||||
<h5>Important to set the character's writing style. <a href="/notes#examplesofdialogue" class="notes-link" target="_blank"><span class="note-link-span">?</span></a></h5>
|
||||
</div>
|
||||
<textarea id="mes_example_textarea" class="flexGrow" name="mes_example" placeholder="(Examples of chat dialog. Begin each example with <start> on a new line.)" form="form_create" maxlength="20000"></textarea>
|
||||
<textarea id="mes_example_textarea" class="flexGrow" name="mes_example" placeholder="(Examples of chat dialog. Begin each example with <start> on a new line.)" form="form_create" maxlength="20000" rows="6"></textarea>
|
||||
</div>
|
||||
<div id="character_popup_ok" class="menu_button">Save</div>
|
||||
|
||||
|
164
public/script.js
164
public/script.js
@ -143,7 +143,6 @@ import {
|
||||
secret_state,
|
||||
writeSecret
|
||||
} from "./scripts/secrets.js";
|
||||
import uniqolor from "./scripts/uniqolor.js";
|
||||
import { EventEmitter } from './scripts/eventemitter.js';
|
||||
import { context_settings, loadContextTemplatesFromSettings } from "./scripts/context-template.js";
|
||||
|
||||
@ -536,39 +535,42 @@ var is_advanced_char_open = false;
|
||||
var menu_type = ""; //what is selected in the menu
|
||||
var selected_button = ""; //which button pressed
|
||||
//create pole save
|
||||
var create_save_name = "";
|
||||
var create_fav_chara = "";
|
||||
var create_save_description = "";
|
||||
var create_save_creatorcomment = "";
|
||||
var create_save_personality = "";
|
||||
var create_save_first_message = "";
|
||||
var create_save_avatar = "";
|
||||
var create_save_scenario = "";
|
||||
var create_save_mes_example = "";
|
||||
var create_save_talkativeness = talkativeness_default;
|
||||
var create_save_json_data = "";
|
||||
let create_save_name = "";
|
||||
let create_save_description = "";
|
||||
let create_save_creator_notes = "";
|
||||
let create_save_post_history_instructions = "";
|
||||
let create_save_character_version = "";
|
||||
let create_save_system_prompt = "";
|
||||
let create_save_tags = "";
|
||||
let create_save_creator = "";
|
||||
let create_save_personality = "";
|
||||
let create_save_first_message = "";
|
||||
let create_save_avatar = "";
|
||||
let create_save_scenario = "";
|
||||
let create_save_mes_example = "";
|
||||
let create_save_talkativeness = talkativeness_default;
|
||||
|
||||
//animation right menu
|
||||
var animation_duration = 250;
|
||||
var animation_easing = "ease-in-out";
|
||||
var popup_type = "";
|
||||
var bg_file_for_del = "";
|
||||
var chat_file_for_del = "";
|
||||
var online_status = "no_connection";
|
||||
let animation_duration = 250;
|
||||
let animation_easing = "ease-in-out";
|
||||
let popup_type = "";
|
||||
let bg_file_for_del = "";
|
||||
let chat_file_for_del = "";
|
||||
let online_status = "no_connection";
|
||||
|
||||
var api_server = "";
|
||||
var api_server_textgenerationwebui = "";
|
||||
let api_server = "";
|
||||
let api_server_textgenerationwebui = "";
|
||||
//var interval_timer = setInterval(getStatus, 2000);
|
||||
var interval_timer_novel = setInterval(getStatusNovel, 90000);
|
||||
var is_get_status = false;
|
||||
var is_get_status_novel = false;
|
||||
var is_api_button_press = false;
|
||||
var is_api_button_press_novel = false;
|
||||
let interval_timer_novel = setInterval(getStatusNovel, 90000);
|
||||
let is_get_status = false;
|
||||
let is_get_status_novel = false;
|
||||
let is_api_button_press = false;
|
||||
let is_api_button_press_novel = false;
|
||||
|
||||
var is_send_press = false; //Send generation
|
||||
var add_mes_without_animation = false;
|
||||
let is_send_press = false; //Send generation
|
||||
let add_mes_without_animation = false;
|
||||
|
||||
var this_del_mes = 0;
|
||||
let this_del_mes = 0;
|
||||
|
||||
//message editing and chat scroll posistion persistence
|
||||
var this_edit_mes_text = "";
|
||||
@ -4321,11 +4323,17 @@ export function select_selected_character(chid) {
|
||||
$("#character_popup_text_h3").text(characters[chid].name);
|
||||
$("#character_name_pole").val(characters[chid].name);
|
||||
$("#description_textarea").val(characters[chid].description);
|
||||
$("#creatorcomment_textarea").val(characters[chid].creatorcomment);
|
||||
$("#creator_notes_textarea").val(characters[chid].data?.creator_notes || characters[chid].creatorcomment);
|
||||
$("#character_version_textarea").val(characters[chid].data?.character_version || '');
|
||||
$("#system_prompt_textarea").val(characters[chid].data?.system_prompt || '');
|
||||
$("#post_history_instructions_textarea").val(characters[chid].data?.post_history_instructions || '');
|
||||
$("#tags_textarea").val(Array.isArray(characters[chid].data?.tags) ? characters[chid].data.tags.join(', ') : '');
|
||||
$("#creator_textarea").val(characters[chid].data?.creator);
|
||||
$("#character_version_textarea").val(characters[chid].data?.character_version || '');
|
||||
$("#personality_textarea").val(characters[chid].personality);
|
||||
$("#firstmessage_textarea").val(characters[chid].first_mes);
|
||||
$("#scenario_pole").val(characters[chid].scenario);
|
||||
$("#talkativeness_slider").val(characters[chid].talkativeness ?? talkativeness_default);
|
||||
$("#talkativeness_slider").val(characters[chid].talkativeness || talkativeness_default);
|
||||
$("#mes_example_textarea").val(characters[chid].mes_example);
|
||||
$("#selected_chat_pole").val(characters[chid].chat);
|
||||
$("#create_date_pole").val(characters[chid].create_date);
|
||||
@ -4376,17 +4384,17 @@ function select_rm_create() {
|
||||
$("#character_popup_text_h3").text("Create character");
|
||||
$("#character_name_pole").val(create_save_name);
|
||||
$("#description_textarea").val(create_save_description);
|
||||
$("#creatorcomment_textarea").val(create_save_creatorcomment);
|
||||
$("#creator_notes_textarea").val(create_save_creator_notes);
|
||||
$("#post_history_instructions_textarea").val(create_save_post_history_instructions);
|
||||
$("#system_prompt_textarea").val(create_save_system_prompt);
|
||||
$("#tags_textarea").val(create_save_tags);
|
||||
$("#creator_textarea").val(create_save_creator);
|
||||
$("#character_version_textarea").val(create_save_character_version);
|
||||
$("#personality_textarea").val(create_save_personality);
|
||||
$("#firstmessage_textarea").val(create_save_first_message);
|
||||
$("#talkativeness_slider").val(create_save_talkativeness);
|
||||
$("#scenario_pole").val(create_save_scenario);
|
||||
if ($.trim(create_save_mes_example).length == 0) {
|
||||
$("#mes_example_textarea").val("<START>");
|
||||
} else {
|
||||
$("#mes_example_textarea").val(create_save_mes_example);
|
||||
}
|
||||
$("#characted_json_data").val(create_save_json_data);
|
||||
$("#mes_example_textarea").val(create_save_mes_example.trim().length === 0 ? '<START>' : create_save_mes_example);
|
||||
$("#avatar_div").css("display", "flex");
|
||||
$("#avatar_load_preview").attr("src", default_avatar);
|
||||
$("#renameCharButton").css('display', 'none');
|
||||
@ -5620,31 +5628,33 @@ $(document).ready(function () {
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: async function (html) {
|
||||
$("#character_cross").click(); //closes the advanced character editing popup
|
||||
$("#character_name_pole").val("");
|
||||
create_save_name = "";
|
||||
$("#description_textarea").val("");
|
||||
create_save_description = "";
|
||||
$("#creatorcomment_textarea").val("");
|
||||
create_save_creatorcomment = "";
|
||||
$("#personality_textarea").val("");
|
||||
create_save_personality = "";
|
||||
$("#firstmessage_textarea").val("");
|
||||
create_save_first_message = "";
|
||||
$("#talkativeness_slider").val(talkativeness_default);
|
||||
create_save_talkativeness = talkativeness_default;
|
||||
$("#character_cross").trigger('click'); //closes the advanced character editing popup
|
||||
const fields = [
|
||||
{ id: '#character_name_pole', callback: value => create_save_name = value },
|
||||
{ id: '#description_textarea', callback: value => create_save_description = value },
|
||||
{ id: '#creator_notes_textarea', callback: value => create_save_creator_notes = value },
|
||||
{ id: '#character_version_textarea', callback: value => create_save_character_version = value },
|
||||
{ id: '#post_history_instructions_textarea', callback: value => create_save_post_history_instructions = value },
|
||||
{ id: '#system_prompt_textarea', callback: value => create_save_system_prompt = value },
|
||||
{ id: '#tags_textarea', callback: value => create_save_tags = value },
|
||||
{ id: '#creator_textarea', callback: value => create_save_creator = value },
|
||||
{ id: '#personality_textarea', callback: value => create_save_personality = value },
|
||||
{ id: '#firstmessage_textarea', callback: value => create_save_first_message = value },
|
||||
{ id: '#talkativeness_slider', callback: value => create_save_talkativeness = value, defaultValue: talkativeness_default },
|
||||
{ id: '#scenario_pole', callback: value => create_save_scenario = value },
|
||||
{ id: '#mes_example_textarea', callback: value => create_save_mes_example = value },
|
||||
{ id: '#character_json_data', callback: () => { } },
|
||||
];
|
||||
|
||||
fields.forEach(field => {
|
||||
const fieldValue = field.defaultValue !== undefined ? field.defaultValue : '';
|
||||
$(field.id).val(fieldValue);
|
||||
field.callback && field.callback(fieldValue);
|
||||
});
|
||||
|
||||
$("#character_popup_text_h3").text("Create character");
|
||||
|
||||
$("#scenario_pole").val("");
|
||||
create_save_scenario = "";
|
||||
$("#mes_example_textarea").val("");
|
||||
create_save_mes_example = "";
|
||||
|
||||
create_save_avatar = "";
|
||||
create_save_json_data = "";
|
||||
|
||||
$("#character_json_data").val("");
|
||||
|
||||
$("#create_button").removeAttr("disabled");
|
||||
$("#add_avatar_button").replaceWith(
|
||||
@ -5765,27 +5775,35 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
$("#description_textarea, #creatorcomment_textarea, #personality_textarea, #scenario_pole, #mes_example_textarea, #firstmessage_textarea")
|
||||
.on("input", function () {
|
||||
const elementsToUpdate = {
|
||||
'#description_textarea': function() { create_save_description = $("#description_textarea").val(); },
|
||||
'#creator_notes_textarea': function() { create_save_creator_notes = $("#creator_notes_textarea").val(); },
|
||||
'#character_version_textarea': function() { create_save_character_version = $("#character_version_textarea").val(); },
|
||||
'#system_prompt_textarea': function() { create_save_system_prompt = $("#system_prompt_textarea").val(); },
|
||||
'#post_history_instructions_textarea': function() { create_save_post_history_instructions = $("#post_history_instructions_textarea").val(); },
|
||||
'#creator_textarea': function() { create_save_creator = $("#creator_textarea").val(); },
|
||||
'#tags_textarea': function() { create_save_tags = $("#tags_textarea").val(); },
|
||||
'#personality_textarea': function() { create_save_personality = $("#personality_textarea").val(); },
|
||||
'#scenario_pole': function() { create_save_scenario = $("#scenario_pole").val(); },
|
||||
'#mes_example_textarea': function() { create_save_mes_example = $("#mes_example_textarea").val(); },
|
||||
'#firstmessage_textarea': function() { create_save_first_message = $("#firstmessage_textarea").val(); },
|
||||
'#talkativeness_slider': function() { create_save_talkativeness = $("#talkativeness_slider").val(); },
|
||||
};
|
||||
|
||||
Object.keys(elementsToUpdate).forEach(function(id) {
|
||||
$(id).on("input", function() {
|
||||
if (menu_type == "create") {
|
||||
create_save_description = $("#description_textarea").val();
|
||||
create_save_creatorcomment = $("#creatorcomment_textarea").val();
|
||||
create_save_personality = $("#personality_textarea").val();
|
||||
create_save_scenario = $("#scenario_pole").val();
|
||||
create_save_mes_example = $("#mes_example_textarea").val();
|
||||
create_save_first_message = $("#firstmessage_textarea").val();
|
||||
create_fav_chara = $("#fav_checkbox").val();
|
||||
create_save_json_data = $("#character_json_data").val();
|
||||
elementsToUpdate[id]();
|
||||
} else {
|
||||
saveCharacterDebounced();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#favorite_button").on('click', function () {
|
||||
updateFavButtonState(!fav_ch_checked);
|
||||
if (menu_type != "create") {
|
||||
saveCharacterDebounced();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -5891,14 +5909,6 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
$("#talkativeness_slider").on("input", function () {
|
||||
if (menu_type == "create") {
|
||||
create_save_talkativeness = $("#talkativeness_slider").val();
|
||||
} else {
|
||||
saveCharacterDebounced();
|
||||
}
|
||||
});
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$("#api_button").click(function (e) {
|
||||
|
52
server.js
52
server.js
@ -686,7 +686,7 @@ function convertToV2(char) {
|
||||
scenario: char.scenario,
|
||||
first_mes: char.first_mes,
|
||||
mes_example: char.mes_example,
|
||||
creatorcomment: char.creatorcomment,
|
||||
creator_notes: char.creatorcomment,
|
||||
talkativeness: char.talkativeness,
|
||||
fav: char.fav,
|
||||
});
|
||||
@ -696,6 +696,40 @@ function convertToV2(char) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function readFromV2(char) {
|
||||
const _ = require('lodash');
|
||||
if (_.isUndefined(char.data)) {
|
||||
console.warn('Spec v2 data missing');
|
||||
return char;
|
||||
}
|
||||
|
||||
const fieldMappings = {
|
||||
name: 'name',
|
||||
description: 'description',
|
||||
personality: 'personality',
|
||||
scenario: 'scenario',
|
||||
first_mes: 'first_mes',
|
||||
mes_example: 'mes_example',
|
||||
talkativeness: 'extensions.talkativeness',
|
||||
fav: 'extensions.fav',
|
||||
};
|
||||
|
||||
_.forEach(fieldMappings, (v2Path, charField) => {
|
||||
//console.log(`Migrating field: ${charField} from ${v2Path}`);
|
||||
const v2Value = _.get(char.data, v2Path);
|
||||
if (_.isUndefined(v2Value)) {
|
||||
console.debug(`Spec v2 data missing for field: ${charField}`);
|
||||
return;
|
||||
}
|
||||
if (!_.isUndefined(char[charField]) && !_.isUndefined(v2Value) && char[charField] !== v2Value) {
|
||||
console.debug(`Spec v2 data mismatch with Spec v1 for field: ${charField}`);
|
||||
}
|
||||
char[charField] = v2Value;
|
||||
});
|
||||
|
||||
return char;
|
||||
}
|
||||
|
||||
//***************** Main functions
|
||||
function charaFormatData(data) {
|
||||
// This is supposed to save all the foreign keys that ST doesn't care about
|
||||
@ -710,8 +744,8 @@ function charaFormatData(data) {
|
||||
_.set(char, 'first_mes', data.first_mes);
|
||||
_.set(char, 'mes_example', data.mes_example);
|
||||
|
||||
// Old ST extension fields (for compatibility, will be deprecated)
|
||||
_.set(char, 'creatorcomment', data.creatorcomment);
|
||||
// Old ST extension fields (for backward compatibility, will be deprecated)
|
||||
_.set(char, 'creatorcomment', data.creator_notes);
|
||||
_.set(char, 'avatar', 'none');
|
||||
_.set(char, 'chat', data.ch_name + ' - ' + humanizedISO8601DateTime());
|
||||
_.set(char, 'talkativeness', data.talkativeness);
|
||||
@ -729,12 +763,13 @@ function charaFormatData(data) {
|
||||
_.set(char, 'data.mes_example', data.mes_example);
|
||||
|
||||
// New V2 fields
|
||||
_.set(char, 'data.creator_notes', data.creatorcomment);
|
||||
_.set(char, 'data.creator_notes', data.creator_notes);
|
||||
_.set(char, 'data.system_prompt', data.system_prompt);
|
||||
_.set(char, 'data.post_history_instructions', data.post_history_instructions);
|
||||
_.set(char, 'data.tags', []);
|
||||
_.set(char, 'data.tags', typeof data.tags == 'string' ? (data.tags.split(',').map(x => x.trim()).filter(x => x)) : []);
|
||||
_.set(char, 'data.creator', data.creator);
|
||||
_.set(char, 'data.character_version', data.character_version);
|
||||
_.set(char, 'data.alternative_greetings', data.alternate_greetings);
|
||||
|
||||
// ST extension fields to V2 object
|
||||
_.set(char, 'data.extensions.talkativeness', data.talkativeness);
|
||||
@ -976,9 +1011,9 @@ app.post("/getcharacters", jsonParser, function (request, response) {
|
||||
let jsonObject = json5.parse(img_data);
|
||||
|
||||
if (jsonObject.spec === undefined) {
|
||||
//console.log('Old character detected, converting to V2: ' + item);
|
||||
jsonObject = convertToV2(jsonObject);
|
||||
//console.log('Conversion complete.', jsonObject);
|
||||
} else {
|
||||
jsonObject = readFromV2(jsonObject);
|
||||
}
|
||||
|
||||
jsonObject.avatar = item;
|
||||
@ -1558,6 +1593,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
|
||||
"create_date": humanizedISO8601DateTime(),
|
||||
"talkativeness": jsonData.talkativeness ?? 0.5
|
||||
};
|
||||
char = convertToV2(char);
|
||||
char = JSON.stringify(char);
|
||||
charaWrite(defaultAvatarPath, char, png_name, response, { file_name: png_name });
|
||||
} else if (jsonData.char_name !== undefined) {//json Pygmalion notepad
|
||||
@ -1577,6 +1613,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
|
||||
"create_date": humanizedISO8601DateTime(),
|
||||
"talkativeness": jsonData.talkativeness ?? 0.5
|
||||
};
|
||||
char = convertToV2(char);
|
||||
char = JSON.stringify(char);
|
||||
charaWrite(defaultAvatarPath, char, png_name, response, { file_name: png_name });
|
||||
} else {
|
||||
@ -1618,6 +1655,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
|
||||
"create_date": humanizedISO8601DateTime(),
|
||||
"talkativeness": jsonData.talkativeness ?? 0.5
|
||||
};
|
||||
char = convertToV2(char);
|
||||
char = JSON.stringify(char);
|
||||
await charaWrite(uploadPath, char, png_name, response, { file_name: png_name });
|
||||
}
|
||||
|
Reference in New Issue
Block a user