mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Save chat metadata object
This commit is contained in:
@@ -118,6 +118,7 @@ export {
|
|||||||
hideSwipeButtons,
|
hideSwipeButtons,
|
||||||
changeMainAPI,
|
changeMainAPI,
|
||||||
setGenerationProgress,
|
setGenerationProgress,
|
||||||
|
updateChatMetadata,
|
||||||
chat,
|
chat,
|
||||||
this_chid,
|
this_chid,
|
||||||
settings,
|
settings,
|
||||||
@@ -134,6 +135,7 @@ export {
|
|||||||
api_server_textgenerationwebui,
|
api_server_textgenerationwebui,
|
||||||
count_view_mes,
|
count_view_mes,
|
||||||
max_context,
|
max_context,
|
||||||
|
chat_metadata,
|
||||||
default_avatar,
|
default_avatar,
|
||||||
system_message_types,
|
system_message_types,
|
||||||
talkativeness_default,
|
talkativeness_default,
|
||||||
@@ -180,6 +182,7 @@ let optionsPopper = Popper.createPopper(document.getElementById('send_form'), do
|
|||||||
placement: 'top-start'
|
placement: 'top-start'
|
||||||
});
|
});
|
||||||
let dialogueResolve = null;
|
let dialogueResolve = null;
|
||||||
|
let chat_metadata = {};
|
||||||
|
|
||||||
const durationSaveEdit = 200;
|
const durationSaveEdit = 200;
|
||||||
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
||||||
@@ -1906,6 +1909,7 @@ function resetChatState() {
|
|||||||
this_chid = "invalid-safety-id"; //unsets expected chid before reloading (related to getCharacters/printCharacters from using old arrays)
|
this_chid = "invalid-safety-id"; //unsets expected chid before reloading (related to getCharacters/printCharacters from using old arrays)
|
||||||
name2 = systemUserName; // replaces deleted charcter name with system user since it will be displayed next.
|
name2 = systemUserName; // replaces deleted charcter name with system user since it will be displayed next.
|
||||||
chat = [...safetychat]; // sets up system user to tell user about having deleted a character
|
chat = [...safetychat]; // sets up system user to tell user about having deleted a character
|
||||||
|
chat_metadata = {}; // resets chat metadata
|
||||||
characters.length = 0; // resets the characters array, forcing getcharacters to reset
|
characters.length = 0; // resets the characters array, forcing getcharacters to reset
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1957,6 +1961,7 @@ async function saveChat(chat_name) {
|
|||||||
user_name: default_user_name,
|
user_name: default_user_name,
|
||||||
character_name: name2,
|
character_name: name2,
|
||||||
create_date: chat_create_date,
|
create_date: chat_create_date,
|
||||||
|
chat_metadata: chat_metadata,
|
||||||
},
|
},
|
||||||
...chat,
|
...chat,
|
||||||
];
|
];
|
||||||
@@ -2020,6 +2025,7 @@ async function getChat() {
|
|||||||
if (response[0] !== undefined) {
|
if (response[0] !== undefined) {
|
||||||
chat.push(...response);
|
chat.push(...response);
|
||||||
chat_create_date = chat[0]['create_date'];
|
chat_create_date = chat[0]['create_date'];
|
||||||
|
chat_metadata = chat[0]['chat_metadata'] ?? {};
|
||||||
chat.shift();
|
chat.shift();
|
||||||
} else {
|
} else {
|
||||||
chat_create_date = humanizedDateTime();
|
chat_create_date = humanizedDateTime();
|
||||||
@@ -2060,6 +2066,7 @@ async function openCharacterChat(file_name) {
|
|||||||
characters[this_chid]["chat"] = file_name;
|
characters[this_chid]["chat"] = file_name;
|
||||||
clearChat();
|
clearChat();
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
|
chat_metadata = {};
|
||||||
await getChat();
|
await getChat();
|
||||||
$("#selected_chat_pole").val(file_name);
|
$("#selected_chat_pole").val(file_name);
|
||||||
$("#create_button").click();
|
$("#create_button").click();
|
||||||
@@ -2800,6 +2807,10 @@ function setExtensionPrompt(key, value, position, depth) {
|
|||||||
extension_prompts[key] = { value, position, depth };
|
extension_prompts[key] = { value, position, depth };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateChatMetadata(newValues, reset) {
|
||||||
|
chat_metadata = reset? { ...newValues } : { ...chat_metadata, ...newValues };
|
||||||
|
}
|
||||||
|
|
||||||
function callPopup(text, type) {
|
function callPopup(text, type) {
|
||||||
if (type) {
|
if (type) {
|
||||||
popup_type = type;
|
popup_type = type;
|
||||||
@@ -3033,11 +3044,13 @@ window["TavernAI"].getContext = function () {
|
|||||||
chatId: this_chid && characters[this_chid] && characters[this_chid].chat,
|
chatId: this_chid && characters[this_chid] && characters[this_chid].chat,
|
||||||
onlineStatus: online_status,
|
onlineStatus: online_status,
|
||||||
maxContext: Number(max_context),
|
maxContext: Number(max_context),
|
||||||
|
chatMetadata: chat_metadata,
|
||||||
addOneMessage: addOneMessage,
|
addOneMessage: addOneMessage,
|
||||||
generate: Generate,
|
generate: Generate,
|
||||||
encode: encode,
|
encode: encode,
|
||||||
extensionPrompts: extension_prompts,
|
extensionPrompts: extension_prompts,
|
||||||
setExtensionPrompt: setExtensionPrompt,
|
setExtensionPrompt: setExtensionPrompt,
|
||||||
|
updateChatMetadata: updateChatMetadata,
|
||||||
saveChat: saveChatConditional,
|
saveChat: saveChatConditional,
|
||||||
sendSystemMessage: sendSystemMessage,
|
sendSystemMessage: sendSystemMessage,
|
||||||
activateSendButtons,
|
activateSendButtons,
|
||||||
@@ -3371,6 +3384,7 @@ $(document).ready(function () {
|
|||||||
active_character = this_chid;
|
active_character = this_chid;
|
||||||
clearChat();
|
clearChat();
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
|
chat_metadata = {};
|
||||||
getChat();
|
getChat();
|
||||||
|
|
||||||
//console.log('Clicked on '+characters[this_chid].name+' Active_Character set to: '+active_character+' (ChID:'+this_chid+')');
|
//console.log('Clicked on '+characters[this_chid].name+' Active_Character set to: '+active_character+' (ChID:'+this_chid+')');
|
||||||
@@ -3571,6 +3585,7 @@ $(document).ready(function () {
|
|||||||
characters.length = 0; // resets the characters array, forcing getcharacters to reset
|
characters.length = 0; // resets the characters array, forcing getcharacters to reset
|
||||||
name2 = systemUserName; // replaces deleted charcter name with system user since she will be displayed next.
|
name2 = systemUserName; // replaces deleted charcter name with system user since she will be displayed next.
|
||||||
chat = [...safetychat]; // sets up system user to tell user about having deleted a character
|
chat = [...safetychat]; // sets up system user to tell user about having deleted a character
|
||||||
|
chat_metadata = {}; // resets chat metadata
|
||||||
setRightTabSelectedClass() // 'deselects' character's tab panel
|
setRightTabSelectedClass() // 'deselects' character's tab panel
|
||||||
$(document.getElementById("rm_button_selected_ch"))
|
$(document.getElementById("rm_button_selected_ch"))
|
||||||
.children("h2")
|
.children("h2")
|
||||||
@@ -3608,6 +3623,7 @@ $(document).ready(function () {
|
|||||||
//Fix it; New chat doesn't create while open create character menu
|
//Fix it; New chat doesn't create while open create character menu
|
||||||
clearChat();
|
clearChat();
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
|
chat_metadata = {};
|
||||||
characters[this_chid].chat = name2 + " - " + humanizedDateTime(); //RossAscends: added character name to new chat filenames and replaced Date.now() with humanizedDateTime;
|
characters[this_chid].chat = name2 + " - " + humanizedDateTime(); //RossAscends: added character name to new chat filenames and replaced Date.now() with humanizedDateTime;
|
||||||
$("#selected_chat_pole").val(characters[this_chid].chat);
|
$("#selected_chat_pole").val(characters[this_chid].chat);
|
||||||
saveCharacterDebounced();
|
saveCharacterDebounced();
|
||||||
|
@@ -36,6 +36,8 @@ import {
|
|||||||
deleteLastMessage,
|
deleteLastMessage,
|
||||||
showSwipeButtons,
|
showSwipeButtons,
|
||||||
hideSwipeButtons,
|
hideSwipeButtons,
|
||||||
|
chat_metadata,
|
||||||
|
updateChatMetadata,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -115,7 +117,6 @@ async function getGroupChat(id) {
|
|||||||
printMessages();
|
printMessages();
|
||||||
} else {
|
} else {
|
||||||
sendSystemMessage(system_message_types.GROUP);
|
sendSystemMessage(system_message_types.GROUP);
|
||||||
const group = groups.find((x) => x.id === id);
|
|
||||||
if (group && Array.isArray(group.members)) {
|
if (group && Array.isArray(group.members)) {
|
||||||
for (let name of group.members) {
|
for (let name of group.members) {
|
||||||
const character = characters.find((x) => x.name === name);
|
const character = characters.find((x) => x.name === name);
|
||||||
@@ -143,6 +144,12 @@ async function getGroupChat(id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const group = groups.find((x) => x.id === id);
|
||||||
|
if (group) {
|
||||||
|
let metadata = group.chat_metadata ?? {};
|
||||||
|
updateChatMetadata(metadata, true);
|
||||||
|
}
|
||||||
|
|
||||||
await saveGroupChat(id);
|
await saveGroupChat(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +170,7 @@ async function saveGroupChat(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
// response ok
|
await editGroup(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +316,6 @@ async function generateGroupWrapper(by_auto_mode, type=null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
||||||
let activatedMembers = [];
|
let activatedMembers = [];
|
||||||
|
|
||||||
@@ -498,7 +504,8 @@ async function deleteGroup(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function editGroup(id, immediately) {
|
async function editGroup(id, immediately) {
|
||||||
const group = groups.find((x) => x.id == id);
|
let group = groups.find((x) => x.id == id);
|
||||||
|
group = { ...group, chat_metadata };
|
||||||
|
|
||||||
if (!group) {
|
if (!group) {
|
||||||
return;
|
return;
|
||||||
@@ -680,6 +687,7 @@ $(document).ready(() => {
|
|||||||
setCharacterName('');
|
setCharacterName('');
|
||||||
setEditedMessageId(undefined);
|
setEditedMessageId(undefined);
|
||||||
clearChat();
|
clearChat();
|
||||||
|
updateChatMetadata({}, true);
|
||||||
chat.length = 0;
|
chat.length = 0;
|
||||||
await getGroupChat(id);
|
await getGroupChat(id);
|
||||||
}
|
}
|
||||||
@@ -729,6 +737,7 @@ $(document).ready(() => {
|
|||||||
avatar_url: avatar_url,
|
avatar_url: avatar_url,
|
||||||
allow_self_responses: allow_self_responses,
|
allow_self_responses: allow_self_responses,
|
||||||
activation_strategy: activation_strategy,
|
activation_strategy: activation_strategy,
|
||||||
|
chat_metadata: {},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1533,6 +1533,7 @@ app.post('/creategroup', jsonParser, (request, response) => {
|
|||||||
avatar_url: request.body.avatar_url,
|
avatar_url: request.body.avatar_url,
|
||||||
allow_self_responses: !!request.body.allow_self_responses,
|
allow_self_responses: !!request.body.allow_self_responses,
|
||||||
activation_strategy: request.body.activation_strategy ?? 0,
|
activation_strategy: request.body.activation_strategy ?? 0,
|
||||||
|
chat_metadata: request.body.chat_metadata ?? {},
|
||||||
};
|
};
|
||||||
const pathToFile = path.join(directories.groups, `${id}.json`);
|
const pathToFile = path.join(directories.groups, `${id}.json`);
|
||||||
const fileData = JSON.stringify(chatMetadata);
|
const fileData = JSON.stringify(chatMetadata);
|
||||||
|
Reference in New Issue
Block a user