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,
|
||||
changeMainAPI,
|
||||
setGenerationProgress,
|
||||
updateChatMetadata,
|
||||
chat,
|
||||
this_chid,
|
||||
settings,
|
||||
@@ -134,6 +135,7 @@ export {
|
||||
api_server_textgenerationwebui,
|
||||
count_view_mes,
|
||||
max_context,
|
||||
chat_metadata,
|
||||
default_avatar,
|
||||
system_message_types,
|
||||
talkativeness_default,
|
||||
@@ -180,6 +182,7 @@ let optionsPopper = Popper.createPopper(document.getElementById('send_form'), do
|
||||
placement: 'top-start'
|
||||
});
|
||||
let dialogueResolve = null;
|
||||
let chat_metadata = {};
|
||||
|
||||
const durationSaveEdit = 200;
|
||||
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)
|
||||
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_metadata = {}; // resets chat metadata
|
||||
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,
|
||||
character_name: name2,
|
||||
create_date: chat_create_date,
|
||||
chat_metadata: chat_metadata,
|
||||
},
|
||||
...chat,
|
||||
];
|
||||
@@ -2020,6 +2025,7 @@ async function getChat() {
|
||||
if (response[0] !== undefined) {
|
||||
chat.push(...response);
|
||||
chat_create_date = chat[0]['create_date'];
|
||||
chat_metadata = chat[0]['chat_metadata'] ?? {};
|
||||
chat.shift();
|
||||
} else {
|
||||
chat_create_date = humanizedDateTime();
|
||||
@@ -2060,6 +2066,7 @@ async function openCharacterChat(file_name) {
|
||||
characters[this_chid]["chat"] = file_name;
|
||||
clearChat();
|
||||
chat.length = 0;
|
||||
chat_metadata = {};
|
||||
await getChat();
|
||||
$("#selected_chat_pole").val(file_name);
|
||||
$("#create_button").click();
|
||||
@@ -2800,6 +2807,10 @@ function setExtensionPrompt(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) {
|
||||
if (type) {
|
||||
popup_type = type;
|
||||
@@ -3033,11 +3044,13 @@ window["TavernAI"].getContext = function () {
|
||||
chatId: this_chid && characters[this_chid] && characters[this_chid].chat,
|
||||
onlineStatus: online_status,
|
||||
maxContext: Number(max_context),
|
||||
chatMetadata: chat_metadata,
|
||||
addOneMessage: addOneMessage,
|
||||
generate: Generate,
|
||||
encode: encode,
|
||||
extensionPrompts: extension_prompts,
|
||||
setExtensionPrompt: setExtensionPrompt,
|
||||
updateChatMetadata: updateChatMetadata,
|
||||
saveChat: saveChatConditional,
|
||||
sendSystemMessage: sendSystemMessage,
|
||||
activateSendButtons,
|
||||
@@ -3371,6 +3384,7 @@ $(document).ready(function () {
|
||||
active_character = this_chid;
|
||||
clearChat();
|
||||
chat.length = 0;
|
||||
chat_metadata = {};
|
||||
getChat();
|
||||
|
||||
//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
|
||||
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_metadata = {}; // resets chat metadata
|
||||
setRightTabSelectedClass() // 'deselects' character's tab panel
|
||||
$(document.getElementById("rm_button_selected_ch"))
|
||||
.children("h2")
|
||||
@@ -3608,6 +3623,7 @@ $(document).ready(function () {
|
||||
//Fix it; New chat doesn't create while open create character menu
|
||||
clearChat();
|
||||
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;
|
||||
$("#selected_chat_pole").val(characters[this_chid].chat);
|
||||
saveCharacterDebounced();
|
||||
|
@@ -36,6 +36,8 @@ import {
|
||||
deleteLastMessage,
|
||||
showSwipeButtons,
|
||||
hideSwipeButtons,
|
||||
chat_metadata,
|
||||
updateChatMetadata,
|
||||
} from "../script.js";
|
||||
|
||||
export {
|
||||
@@ -115,7 +117,6 @@ async function getGroupChat(id) {
|
||||
printMessages();
|
||||
} else {
|
||||
sendSystemMessage(system_message_types.GROUP);
|
||||
const group = groups.find((x) => x.id === id);
|
||||
if (group && Array.isArray(group.members)) {
|
||||
for (let name of group.members) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +170,7 @@ async function saveGroupChat(id) {
|
||||
});
|
||||
|
||||
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);
|
||||
let activatedMembers = [];
|
||||
|
||||
@@ -498,7 +504,8 @@ async function deleteGroup(id) {
|
||||
}
|
||||
|
||||
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) {
|
||||
return;
|
||||
@@ -680,6 +687,7 @@ $(document).ready(() => {
|
||||
setCharacterName('');
|
||||
setEditedMessageId(undefined);
|
||||
clearChat();
|
||||
updateChatMetadata({}, true);
|
||||
chat.length = 0;
|
||||
await getGroupChat(id);
|
||||
}
|
||||
@@ -729,6 +737,7 @@ $(document).ready(() => {
|
||||
avatar_url: avatar_url,
|
||||
allow_self_responses: allow_self_responses,
|
||||
activation_strategy: activation_strategy,
|
||||
chat_metadata: {},
|
||||
}),
|
||||
});
|
||||
|
||||
|
@@ -1533,6 +1533,7 @@ app.post('/creategroup', jsonParser, (request, response) => {
|
||||
avatar_url: request.body.avatar_url,
|
||||
allow_self_responses: !!request.body.allow_self_responses,
|
||||
activation_strategy: request.body.activation_strategy ?? 0,
|
||||
chat_metadata: request.body.chat_metadata ?? {},
|
||||
};
|
||||
const pathToFile = path.join(directories.groups, `${id}.json`);
|
||||
const fileData = JSON.stringify(chatMetadata);
|
||||
|
Reference in New Issue
Block a user