Merge branch 'staging' into contentEditablew-AF-Panel

This commit is contained in:
Cohee 2024-09-01 19:34:18 +03:00
commit c21f59ca7a
4 changed files with 58 additions and 33 deletions

View File

@ -3441,12 +3441,14 @@
</div> </div>
<div id="WorldInfo" class="drawer-content closedDrawer"> <div id="WorldInfo" class="drawer-content closedDrawer">
<div id="WorldInfoheader" class="fa-solid fa-grip drag-grabber"></div> <div id="WorldInfoheader" class="fa-solid fa-grip drag-grabber"></div>
<div id="WI_panel_pin_div" class="flex-container alignitemscenter gap10px" title="Locked = World Editor will stay open" data-i18n="[title]Locked = World Editor will stay open"> <div class="flex-container alignitemscenter gap10px">
<input type="checkbox" id="WI_panel_pin"> <div id="WI_panel_pin_div" title="Locked = World Editor will stay open" data-i18n="[title]Locked = World Editor will stay open">
<label for="WI_panel_pin"> <input type="checkbox" id="WI_panel_pin">
<div class="unchecked fa-solid fa-unlock "></div> <label for="WI_panel_pin">
<div class="checked fa-solid fa-lock "></div> <div class="unchecked fa-solid fa-unlock "></div>
</label> <div class="checked fa-solid fa-lock "></div>
</label>
</div>
<h3 class="margin0"> <h3 class="margin0">
<span data-i18n="Worlds/Lorebooks">Worlds/Lorebooks</span> <span data-i18n="Worlds/Lorebooks">Worlds/Lorebooks</span>
<a href="https://docs.sillytavern.app/usage/core-concepts/worldinfo/" class="notes-link" target="_blank"> <a href="https://docs.sillytavern.app/usage/core-concepts/worldinfo/" class="notes-link" target="_blank">

View File

@ -454,7 +454,9 @@ export const event_types = {
// TODO: Naming convention is inconsistent with other events // TODO: Naming convention is inconsistent with other events
CHARACTER_DELETED: 'characterDeleted', CHARACTER_DELETED: 'characterDeleted',
CHARACTER_DUPLICATED: 'character_duplicated', CHARACTER_DUPLICATED: 'character_duplicated',
SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received', /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
STREAM_TOKEN_RECEIVED: 'stream_token_received',
FILE_ATTACHMENT_DELETED: 'file_attachment_deleted', FILE_ATTACHMENT_DELETED: 'file_attachment_deleted',
WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate', WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate',
OPEN_CHARACTER_LIBRARY: 'open_character_library', OPEN_CHARACTER_LIBRARY: 'open_character_library',
@ -3122,6 +3124,7 @@ class StreamingProcessor {
if (logprobs) { if (logprobs) {
this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs])); this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
} }
await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text);
await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text)); await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text));
} }
const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000; const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000;

View File

@ -15,6 +15,7 @@ import {
generateRaw, generateRaw,
getMaxContextSize, getMaxContextSize,
setExtensionPrompt, setExtensionPrompt,
streamingProcessor,
} from '../../../script.js'; } from '../../../script.js';
import { is_group_generating, selected_group } from '../../group-chats.js'; import { is_group_generating, selected_group } from '../../group-chats.js';
import { loadMovingUIState } from '../../power-user.js'; import { loadMovingUIState } from '../../power-user.js';
@ -408,8 +409,8 @@ async function onChatEvent() {
return; return;
} }
// Generation is in progress, summary prevented // Streaming in-progress
if (is_send_press) { if (streamingProcessor && !streamingProcessor.isFinished) {
return; return;
} }
@ -446,15 +447,9 @@ async function onChatEvent() {
delete chat[chat.length - 1].extra.memory; delete chat[chat.length - 1].extra.memory;
} }
try { summarizeChat(context)
await summarizeChat(context); .catch(console.error)
} .finally(saveLastValues);
catch (error) {
console.log(error);
}
finally {
saveLastValues();
}
} }
/** /**
@ -567,7 +562,7 @@ async function getSummaryPromptForNow(context, force) {
await waitUntilCondition(() => is_group_generating === false, 1000, 10); await waitUntilCondition(() => is_group_generating === false, 1000, 10);
} }
// Wait for the send button to be released // Wait for the send button to be released
waitUntilCondition(() => is_send_press === false, 30000, 100); await waitUntilCondition(() => is_send_press === false, 30000, 100);
} catch { } catch {
console.debug('Timeout waiting for is_send_press'); console.debug('Timeout waiting for is_send_press');
return ''; return '';
@ -650,19 +645,29 @@ async function summarizeChatWebLLM(context, force) {
params.max_tokens = extension_settings.memory.overrideResponseLength; params.max_tokens = extension_settings.memory.overrideResponseLength;
} }
const summary = await generateWebLlmChatPrompt(messages, params); try {
const newContext = getContext(); inApiCall = true;
const summary = await generateWebLlmChatPrompt(messages, params);
const newContext = getContext();
// something changed during summarization request if (!summary) {
if (newContext.groupId !== context.groupId || console.warn('Empty summary received');
newContext.chatId !== context.chatId || return;
(!newContext.groupId && (newContext.characterId !== context.characterId))) { }
console.log('Context changed, summary discarded');
return; // something changed during summarization request
if (newContext.groupId !== context.groupId ||
newContext.chatId !== context.chatId ||
(!newContext.groupId && (newContext.characterId !== context.characterId))) {
console.log('Context changed, summary discarded');
return;
}
setMemoryContext(summary, true, lastUsedIndex);
return summary;
} finally {
inApiCall = false;
} }
setMemoryContext(summary, true, lastUsedIndex);
return summary;
} }
async function summarizeChatMain(context, force, skipWIAN) { async function summarizeChatMain(context, force, skipWIAN) {
@ -677,12 +682,18 @@ async function summarizeChatMain(context, force, skipWIAN) {
let index = null; let index = null;
if (prompt_builders.DEFAULT === extension_settings.memory.prompt_builder) { if (prompt_builders.DEFAULT === extension_settings.memory.prompt_builder) {
summary = await generateQuietPrompt(prompt, false, skipWIAN, '', '', extension_settings.memory.overrideResponseLength); try {
inApiCall = true;
summary = await generateQuietPrompt(prompt, false, skipWIAN, '', '', extension_settings.memory.overrideResponseLength);
} finally {
inApiCall = false;
}
} }
if ([prompt_builders.RAW_BLOCKING, prompt_builders.RAW_NON_BLOCKING].includes(extension_settings.memory.prompt_builder)) { if ([prompt_builders.RAW_BLOCKING, prompt_builders.RAW_NON_BLOCKING].includes(extension_settings.memory.prompt_builder)) {
const lock = extension_settings.memory.prompt_builder === prompt_builders.RAW_BLOCKING; const lock = extension_settings.memory.prompt_builder === prompt_builders.RAW_BLOCKING;
try { try {
inApiCall = true;
if (lock) { if (lock) {
deactivateSendButtons(); deactivateSendButtons();
} }
@ -700,12 +711,18 @@ async function summarizeChatMain(context, force, skipWIAN) {
summary = await generateRaw(rawPrompt, '', false, false, prompt, extension_settings.memory.overrideResponseLength); summary = await generateRaw(rawPrompt, '', false, false, prompt, extension_settings.memory.overrideResponseLength);
index = lastUsedIndex; index = lastUsedIndex;
} finally { } finally {
inApiCall = false;
if (lock) { if (lock) {
activateSendButtons(); activateSendButtons();
} }
} }
} }
if (!summary) {
console.warn('Empty summary received');
return;
}
const newContext = getContext(); const newContext = getContext();
// something changed during summarization request // something changed during summarization request
@ -840,6 +857,11 @@ async function summarizeChatExtras(context) {
const summary = await callExtrasSummarizeAPI(resultingString); const summary = await callExtrasSummarizeAPI(resultingString);
const newContext = getContext(); const newContext = getContext();
if (!summary) {
console.warn('Empty summary received');
return;
}
// something changed during summarization request // something changed during summarization request
if (newContext.groupId !== context.groupId if (newContext.groupId !== context.groupId
|| newContext.chatId !== context.chatId || newContext.chatId !== context.chatId

View File

@ -1,4 +1,3 @@
import { eventSource, event_types } from '../script.js';
import { power_user } from './power-user.js'; import { power_user } from './power-user.js';
import { delay } from './utils.js'; import { delay } from './utils.js';
@ -268,7 +267,6 @@ export class SmoothEventSourceStream extends EventSourceStream {
hasFocus && await delay(getDelay(lastStr)); hasFocus && await delay(getDelay(lastStr));
controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) })); controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));
lastStr = parsed.chunk; lastStr = parsed.chunk;
hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
} }
} catch (error) { } catch (error) {
console.debug('Smooth Streaming parsing error', error); console.debug('Smooth Streaming parsing error', error);