mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into persona-improvements
This commit is contained in:
@@ -5719,14 +5719,15 @@ function parseAndSaveLogprobs(data, continueFrom) {
|
||||
/**
|
||||
* Extracts the message from the response data.
|
||||
* @param {object} data Response data
|
||||
* @param {string} activeApi If it's set, ignores active API
|
||||
* @returns {string} Extracted message
|
||||
*/
|
||||
function extractMessageFromData(data) {
|
||||
export function extractMessageFromData(data, activeApi = null) {
|
||||
if (typeof data === 'string') {
|
||||
return data;
|
||||
}
|
||||
|
||||
switch (main_api) {
|
||||
switch (activeApi ?? main_api) {
|
||||
case 'kobold':
|
||||
return data.results[0].text;
|
||||
case 'koboldhorde':
|
||||
@@ -5736,7 +5737,7 @@ function extractMessageFromData(data) {
|
||||
case 'novel':
|
||||
return data.output;
|
||||
case 'openai':
|
||||
return data?.choices?.[0]?.message?.content ?? data?.choices?.[0]?.text ?? data?.text ?? data?.message?.content?.[0]?.text ?? data?.message?.tool_plan ?? '';
|
||||
return data?.content?.find(p => p.type === 'text')?.text ?? data?.choices?.[0]?.message?.content ?? data?.choices?.[0]?.text ?? data?.text ?? data?.message?.content?.[0]?.text ?? data?.message?.tool_plan ?? '';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
@@ -6096,17 +6097,52 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
|
||||
return { type, getMessage };
|
||||
}
|
||||
|
||||
export function syncCurrentSwipeInfoExtras() {
|
||||
/**
|
||||
* Syncs the current message and all its data into the swipe data at the given message ID (or the last message if no ID is given).
|
||||
*
|
||||
* If the swipe data is invalid in some way, this function will exit out without doing anything.
|
||||
* @param {number?} [messageId=null] - The ID of the message to sync with the swipe data. If no ID is given, the last message is used.
|
||||
* @returns {boolean} Whether the message was successfully synced
|
||||
*/
|
||||
export function syncMesToSwipe(messageId = null) {
|
||||
if (!chat.length) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const currentMessage = chat[chat.length - 1];
|
||||
if (currentMessage && Array.isArray(currentMessage.swipe_info) && typeof currentMessage.swipe_id === 'number') {
|
||||
const swipeInfo = currentMessage.swipe_info[currentMessage.swipe_id];
|
||||
if (swipeInfo && typeof swipeInfo === 'object') {
|
||||
swipeInfo.extra = structuredClone(currentMessage.extra);
|
||||
}
|
||||
|
||||
const targetMessageId = messageId ?? chat.length - 1;
|
||||
if (chat.length > targetMessageId || targetMessageId < 0) {
|
||||
console.warn(`[syncMesToSwipe] Invalid message ID: ${messageId}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const targetMessage = chat[targetMessageId];
|
||||
|
||||
// No swipe data there yet, exit out
|
||||
if (typeof targetMessage.swipe_id !== 'number') {
|
||||
return false;
|
||||
}
|
||||
// If swipes structure is invalid, exit out (for now?)
|
||||
if (!Array.isArray(targetMessage.swipe_info) || !Array.isArray(targetMessage.swipes)) {
|
||||
return false;
|
||||
}
|
||||
// If the swipe is not present yet, exit out (will likely be copied later)
|
||||
if (!targetMessage.swipes[targetMessage.swipe_id] || !targetMessage.swipe_info[targetMessage.swipe_id]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const targetSwipeInfo = targetMessage.swipe_info[targetMessage.swipe_id];
|
||||
if (typeof targetSwipeInfo !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
targetMessage.swipes[targetMessage.swipe_id] = targetMessage.mes;
|
||||
|
||||
targetSwipeInfo.send_date = targetMessage.send_date;
|
||||
targetSwipeInfo.gen_started = targetMessage.gen_started;
|
||||
targetSwipeInfo.gen_finished = targetMessage.gen_finished;
|
||||
targetSwipeInfo.extra = structuredClone(targetMessage.extra);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function saveImageToMessage(img, mes) {
|
||||
@@ -6411,6 +6447,7 @@ export function saveChatDebounced() {
|
||||
if (chatSaveTimeout) {
|
||||
console.debug('Clearing chat save timeout');
|
||||
clearTimeout(chatSaveTimeout);
|
||||
chatSaveTimeout = null;
|
||||
}
|
||||
|
||||
chatSaveTimeout = setTimeout(async () => {
|
||||
@@ -6427,7 +6464,7 @@ export function saveChatDebounced() {
|
||||
console.debug('Chat save timeout triggered');
|
||||
await saveChatConditional();
|
||||
console.debug('Chat saved');
|
||||
}, 1000);
|
||||
}, DEFAULT_SAVE_EDIT_TIMEOUT);
|
||||
}
|
||||
|
||||
export async function saveChat(chatName, withMetadata, mesId) {
|
||||
@@ -8048,6 +8085,12 @@ export async function saveChatConditional() {
|
||||
}
|
||||
|
||||
try {
|
||||
if (chatSaveTimeout) {
|
||||
console.debug('Debounced chat save canceled');
|
||||
clearTimeout(chatSaveTimeout);
|
||||
chatSaveTimeout = null;
|
||||
}
|
||||
|
||||
isChatSaving = true;
|
||||
|
||||
if (selected_group) {
|
||||
@@ -8584,7 +8627,7 @@ function swipe_left() { // when we swipe left..but no generation.
|
||||
}
|
||||
|
||||
// Make sure ad-hoc changes to extras are saved before swiping away
|
||||
syncCurrentSwipeInfoExtras();
|
||||
syncMesToSwipe();
|
||||
|
||||
const swipe_duration = 120;
|
||||
const swipe_range = '700px';
|
||||
@@ -8722,7 +8765,7 @@ const swipe_right = () => {
|
||||
}
|
||||
|
||||
// Make sure ad-hoc changes to extras are saved before swiping away
|
||||
syncCurrentSwipeInfoExtras();
|
||||
syncMesToSwipe();
|
||||
|
||||
const swipe_duration = 200;
|
||||
const swipe_range = 700;
|
||||
@@ -8890,7 +8933,7 @@ const swipe_right = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const CONNECT_API_MAP = {
|
||||
export const CONNECT_API_MAP = {
|
||||
// Default APIs not contined inside text gen / chat gen
|
||||
'kobold': {
|
||||
selected: 'kobold',
|
||||
|
Reference in New Issue
Block a user