mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix swipes
This commit is contained in:
@ -1304,10 +1304,11 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
if (main_api === 'extension') {
|
if (main_api === 'extension') {
|
||||||
if (typeof extension_generation_function !== 'function') {
|
if (typeof extension_generation_function !== 'function') {
|
||||||
callPopup('No extensions are hooked up to a generation process. Check you extension settings!', 'text');
|
callPopup('No extensions are hooked up to a generation process. Check you extension settings!', 'text');
|
||||||
|
activateSendButtons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await extension_generation_function(chat2, storyString, mesExamplesArray, promptBias, extension_prompt, worldInfoBefore, worldInfoAfter);
|
await extension_generation_function(type, chat2, storyString, mesExamplesArray, promptBias, extension_prompt, worldInfoBefore, worldInfoAfter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1734,47 +1735,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
if (force_name2) this_mes_is_name = true;
|
if (force_name2) this_mes_is_name = true;
|
||||||
//getMessage = getMessage.replace(/^\s+/g, '');
|
//getMessage = getMessage.replace(/^\s+/g, '');
|
||||||
if (getMessage.length > 0) {
|
if (getMessage.length > 0) {
|
||||||
if (chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
|
({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name));
|
||||||
chat[chat.length - 1]['is_user'])) {
|
|
||||||
type = 'normal';
|
|
||||||
}
|
|
||||||
if (type === 'swipe') {
|
|
||||||
|
|
||||||
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
|
|
||||||
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
|
||||||
//console.log(getMessage);
|
|
||||||
chat[chat.length - 1]['mes'] = getMessage;
|
|
||||||
// console.log('runGenerate calls addOneMessage for swipe');
|
|
||||||
addOneMessage(chat[chat.length - 1], 'swipe');
|
|
||||||
} else {
|
|
||||||
chat[chat.length - 1]['mes'] = getMessage;
|
|
||||||
}
|
|
||||||
is_send_press = false;
|
|
||||||
} else {
|
|
||||||
console.log('entering chat update routine for non-swipe post');
|
|
||||||
is_send_press = false;
|
|
||||||
chat[chat.length] = {};
|
|
||||||
chat[chat.length - 1]['name'] = name2;
|
|
||||||
chat[chat.length - 1]['is_user'] = false;
|
|
||||||
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
|
||||||
chat[chat.length - 1]['send_date'] = humanizedDateTime();
|
|
||||||
getMessage = $.trim(getMessage);
|
|
||||||
chat[chat.length - 1]['mes'] = getMessage;
|
|
||||||
|
|
||||||
if (selected_group) {
|
|
||||||
console.log('entering chat update for groups');
|
|
||||||
let avatarImg = 'img/ai4.png';
|
|
||||||
if (characters[this_chid].avatar != 'none') {
|
|
||||||
avatarImg = `/thumbnail?type=avatar&file=${encodeURIComponent(characters[this_chid].avatar)}&${Date.now()}`;
|
|
||||||
}
|
|
||||||
chat[chat.length - 1]['is_name'] = true;
|
|
||||||
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
|
||||||
}
|
|
||||||
//console.log('runGenerate calls addOneMessage');
|
|
||||||
addOneMessage(chat[chat.length - 1]);
|
|
||||||
|
|
||||||
activateSendButtons();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// regenerate with character speech reenforced
|
// regenerate with character speech reenforced
|
||||||
// to make sure we leave on swipe type while also adding the name2 appendage
|
// to make sure we leave on swipe type while also adding the name2 appendage
|
||||||
@ -1818,6 +1779,51 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
console.log('generate ending');
|
console.log('generate ending');
|
||||||
} //generate ends
|
} //generate ends
|
||||||
|
|
||||||
|
function saveReply(type, getMessage, this_mes_is_name) {
|
||||||
|
if (chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
|
||||||
|
chat[chat.length - 1]['is_user'])) {
|
||||||
|
type = 'normal';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'swipe') {
|
||||||
|
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
|
||||||
|
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
||||||
|
//console.log(getMessage);
|
||||||
|
chat[chat.length - 1]['mes'] = getMessage;
|
||||||
|
// console.log('runGenerate calls addOneMessage for swipe');
|
||||||
|
addOneMessage(chat[chat.length - 1], 'swipe');
|
||||||
|
} else {
|
||||||
|
chat[chat.length - 1]['mes'] = getMessage;
|
||||||
|
}
|
||||||
|
is_send_press = false;
|
||||||
|
} else {
|
||||||
|
console.log('entering chat update routine for non-swipe post');
|
||||||
|
is_send_press = false;
|
||||||
|
chat[chat.length] = {};
|
||||||
|
chat[chat.length - 1]['name'] = name2;
|
||||||
|
chat[chat.length - 1]['is_user'] = false;
|
||||||
|
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
||||||
|
chat[chat.length - 1]['send_date'] = humanizedDateTime();
|
||||||
|
getMessage = $.trim(getMessage);
|
||||||
|
chat[chat.length - 1]['mes'] = getMessage;
|
||||||
|
|
||||||
|
if (selected_group) {
|
||||||
|
console.log('entering chat update for groups');
|
||||||
|
let avatarImg = 'img/ai4.png';
|
||||||
|
if (characters[this_chid].avatar != 'none') {
|
||||||
|
avatarImg = `/thumbnail?type=avatar&file=${encodeURIComponent(characters[this_chid].avatar)}&${Date.now()}`;
|
||||||
|
}
|
||||||
|
chat[chat.length - 1]['is_name'] = true;
|
||||||
|
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
||||||
|
}
|
||||||
|
//console.log('runGenerate calls addOneMessage');
|
||||||
|
addOneMessage(chat[chat.length - 1]);
|
||||||
|
|
||||||
|
activateSendButtons();
|
||||||
|
}
|
||||||
|
return { type, getMessage };
|
||||||
|
}
|
||||||
|
|
||||||
function isMultigenEnabled() {
|
function isMultigenEnabled() {
|
||||||
return multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
return multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
||||||
}
|
}
|
||||||
@ -2094,6 +2100,7 @@ function changeMainAPI() {
|
|||||||
|
|
||||||
if (main_api == "extension") {
|
if (main_api == "extension") {
|
||||||
online_status = "Connected";
|
online_status = "Connected";
|
||||||
|
checkOnlineStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2934,6 +2941,7 @@ window["TavernAI"].getContext = function () {
|
|||||||
generationFunction: extension_generation_function,
|
generationFunction: extension_generation_function,
|
||||||
activateSendButtons,
|
activateSendButtons,
|
||||||
deactivateSendButtons,
|
deactivateSendButtons,
|
||||||
|
saveReply,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { getContext, getApiUrl } from "../../extensions.js";
|
import { getContext, getApiUrl } from "../../extensions.js";
|
||||||
import { delay } from "../../utils.js";
|
import { delay } from "../../utils.js";
|
||||||
|
import { showSwipeButtons, hideSwipeButtons } from "../../../script.js";
|
||||||
|
|
||||||
const TOKEN_KEY = 'extensions_poe_token';
|
const TOKEN_KEY = 'extensions_poe_token';
|
||||||
const BOT_KEY = 'extensions_poe_bot';
|
const BOT_KEY = 'extensions_poe_bot';
|
||||||
@ -73,10 +74,12 @@ function onBotChange() {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generate(chat2, storyString, mesExamplesArray, promptBias, extension_prompt, worldInfoBefore, worldInfoAfter) {
|
async function generate(type, chat2, storyString, mesExamplesArray, promptBias, extension_prompt, worldInfoBefore, worldInfoAfter) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
context.deactivateSendButtons();
|
context.deactivateSendButtons();
|
||||||
|
hideSwipeButtons();
|
||||||
|
|
||||||
|
try {
|
||||||
await purgeConversation();
|
await purgeConversation();
|
||||||
|
|
||||||
let jailbroken = false;
|
let jailbroken = false;
|
||||||
@ -111,18 +114,16 @@ async function generate(chat2, storyString, mesExamplesArray, promptBias, extens
|
|||||||
const finalPrompt = [prompt, messageSendString, `[Write the next reply as ${context.name2} only]`].join('\n');
|
const finalPrompt = [prompt, messageSendString, `[Write the next reply as ${context.name2} only]`].join('\n');
|
||||||
const reply = await sendMessage(finalPrompt);
|
const reply = await sendMessage(finalPrompt);
|
||||||
|
|
||||||
const message = {
|
context.saveReply(type, reply, true);
|
||||||
name: context.name2,
|
|
||||||
is_user: false,
|
|
||||||
is_name: true,
|
|
||||||
send_date: Date.now(),
|
|
||||||
mes: reply,
|
|
||||||
};
|
|
||||||
|
|
||||||
context.chat.push(message);
|
|
||||||
context.addOneMessage(message);
|
|
||||||
context.saveChat();
|
context.saveChat();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
context.activateSendButtons();
|
context.activateSendButtons();
|
||||||
|
showSwipeButtons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function purgeConversation() {
|
async function purgeConversation() {
|
||||||
|
Reference in New Issue
Block a user