Merge branch 'main' of https://github.com/Cohee1207/SillyTavern into mark-favorite-filter-by-favorite

This commit is contained in:
Wilfred Chen
2023-04-23 02:38:34 +08:00
24 changed files with 151 additions and 75 deletions

View File

@ -158,15 +158,15 @@ export {
}
// API OBJECT FOR EXTERNAL WIRING
window["TavernAI"] = {};
window["SillyTavern"] = {};
let converter = new showdown.Converter({ emoji: "true" });
const gpt3 = new GPT3BrowserTokenizer({ type: 'gpt3' });
/* let bg_menu_toggle = false; */
const systemUserName = "TavernAI";
const systemUserName = "SillyTavern";
let default_user_name = "You";
let name1 = default_user_name;
let name2 = "TavernAI";
let name2 = "SillyTavern";
let chat = [];
let safetychat = [
{
@ -250,7 +250,7 @@ const system_messages = {
is_user: false,
is_name: true,
mes: [
'Welcome to TavernAI! In order to begin chatting:',
'Welcome to SillyTavern! In order to begin chatting:',
'<ul>',
'<li>Connect to one of the supported generation APIs</li>',
'<li>Create or pick a character from the list</li>',
@ -1233,6 +1233,7 @@ class StreamingProcessor {
let formattedText = messageFormating(processedText, chat[messageId].name, chat[messageId].is_system, chat[messageId].force_avatar);
const mesText = $(`#chat .mes[mesid="${messageId}"] .mes_text`);
mesText.html(formattedText);
this.setFirstSwipe(messageId);
}
scrollChatToBottom();
@ -1259,6 +1260,14 @@ class StreamingProcessor {
showSwipeButtons();
}
setFirstSwipe(messageId) {
if (this.type !== 'swipe' && this.type !== 'impersonate') {
if (Array.isArray(chat[messageId]['swipes']) && chat[messageId]['swipes'].length === 1 && chat[messageId]['swipe_id'] === 0) {
chat[messageId]['swipes'][0] = chat[messageId]['mes'];
}
}
}
onStopStreaming() {
this.onErrorStreaming();
}
@ -1276,11 +1285,12 @@ class StreamingProcessor {
this.isFinished = false;
this.generator = this.nullStreamingGeneration;
this.abortController = new AbortController();
this.firstMessageText = '...';
}
async generate() {
if (this.messageId == -1) {
this.messageId = this.onStartStreaming('...');
this.messageId = this.onStartStreaming(this.firstMessageText);
await delay(1); // delay for message to be rendered
}
@ -1329,6 +1339,7 @@ async function Generate(type, automatic_trigger, force_name2) {
if (isStreamingEnabled()) {
streamingProcessor = new StreamingProcessor(type, force_name2);
hideSwipeButtons();
}
else {
streamingProcessor = false;
@ -1568,8 +1579,6 @@ async function Generate(type, automatic_trigger, force_name2) {
hordeAmountGen = adjustedParams.maxLength;
}
let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2);
// Extension added strings
const allAnchors = getAllExtensionPrompts();
const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.AFTER_SCENARIO);
@ -1577,12 +1586,13 @@ async function Generate(type, automatic_trigger, force_name2) {
/////////////////////// swipecode
if (type == 'swipe') {
console.log('pre swipe shift: ' + chat2.length);
console.log('shifting swipe chat2');
chat2.shift();
}
let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2);
console.log('post swipe shift:' + chat2.length);
var i = 0;
@ -3449,7 +3459,7 @@ function isHordeGenerationNotAllowed() {
return false;
}
window["TavernAI"].getContext = function () {
window["SillyTavern"].getContext = function () {
return {
chat: chat,
characters: characters,