Merge branch 'staging' into contentEditablew-AF-Panel
| @@ -3441,12 +3441,14 @@ | ||
| 3441 | 3441 | </div> |
| 3442 | 3442 | <div id="WorldInfo" class="drawer-content closedDrawer"> |
| 3443 | 3443 | <div id="WorldInfoheader" class="fa-solid fa-grip drag-grabber"></div> |
| 3444 | - <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"> | |
| 3444 | + <div class="flex-container alignitemscenter gap10px"> | |
| 3445 | - <input type="checkbox" id="WI_panel_pin"> | |
| 3445 | + <div id="WI_panel_pin_div" title="Locked = World Editor will stay open" data-i18n="[title]Locked = World Editor will stay open"> | |
| 3446 | 3446 | <labelinput fortype="checkbox" id="WI_panel_pin"> |
| 3447 | - <div class="unchecked fa-solid fa-unlock "></div> | |
| 3447 | + <label for="WI_panel_pin"> | |
| 3448 | 3448 | <div class="checkedunchecked fa-solid fa-lockunlock "></div> |
| 3449 | - </label> | |
| 3449 | + <div class="checked fa-solid fa-lock "></div> | |
| 3450 | + </label> | |
| 3451 | + </div> | |
| 3450 | 3452 | <h3 class="margin0"> |
| 3451 | 3453 | <span data-i18n="Worlds/Lorebooks">Worlds/Lorebooks</span> |
| 3452 | 3454 | <a href="https://docs.sillytavern.app/usage/core-concepts/worldinfo/" class="notes-link" target="_blank"> |
| @@ -454,7 +454,9 @@ export const event_types = { | ||
| 454 | 454 | // TODO: Naming convention is inconsistent with other events |
| 455 | 455 | CHARACTER_DELETED: 'characterDeleted', |
| 456 | 456 | CHARACTER_DUPLICATED: 'character_duplicated', |
| 457 | - SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received', | |
| 457 | + /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */ | |
| 458 | + SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received', | |
| 459 | + STREAM_TOKEN_RECEIVED: 'stream_token_received', | |
| 458 | 460 | FILE_ATTACHMENT_DELETED: 'file_attachment_deleted', |
| 459 | 461 | WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate', |
| 460 | 462 | OPEN_CHARACTER_LIBRARY: 'open_character_library', |
| @@ -3122,6 +3124,7 @@ class StreamingProcessor { | ||
| 3122 | 3124 | if (logprobs) { |
| 3123 | 3125 | this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs])); |
| 3124 | 3126 | } |
| 3127 | + await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text); | |
| 3125 | 3128 | await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text)); |
| 3126 | 3129 | } |
| 3127 | 3130 | const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000; |
| @@ -15,6 +15,7 @@ import { | ||
| 15 | 15 | generateRaw, |
| 16 | 16 | getMaxContextSize, |
| 17 | 17 | setExtensionPrompt, |
| 18 | + streamingProcessor, | |
| 18 | 19 | } from '../../../script.js'; |
| 19 | 20 | import { is_group_generating, selected_group } from '../../group-chats.js'; |
| 20 | 21 | import { loadMovingUIState } from '../../power-user.js'; |
| @@ -408,8 +409,8 @@ async function onChatEvent() { | ||
| 408 | 409 | return; |
| 409 | 410 | } |
| 410 | 411 | |
| 411 | 412 | // Generation isStreaming in -progress, summary prevented |
| 412 | 413 | if (is_send_pressstreamingProcessor && !streamingProcessor.isFinished) { |
| 413 | 414 | return; |
| 414 | 415 | } |
| 415 | 416 | |
| @@ -446,15 +447,9 @@ async function onChatEvent() { | ||
| 446 | 447 | delete chat[chat.length - 1].extra.memory; |
| 447 | 448 | } |
| 448 | 449 | |
| 449 | - try { | |
| 450 | + summarizeChat(context) | |
| 450 | - await summarizeChat(context); | |
| 451 | + .catch(console.error) | |
| 451 | - } | |
| 452 | + .finally(saveLastValues); | |
| 452 | - catch (error) { | |
| 453 | - console.log(error); | |
| 454 | - } | |
| 455 | - finally { | |
| 456 | - saveLastValues(); | |
| 457 | - } | |
| 458 | 453 | } |
| 459 | 454 | |
| 460 | 455 | /** |
| @@ -567,7 +562,7 @@ async function getSummaryPromptForNow(context, force) { | ||
| 567 | 562 | await waitUntilCondition(() => is_group_generating === false, 1000, 10); |
| 568 | 563 | } |
| 569 | 564 | // Wait for the send button to be released |
| 570 | 565 | await waitUntilCondition(() => is_send_press === false, 30000, 100); |
| 571 | 566 | } catch { |
| 572 | 567 | console.debug('Timeout waiting for is_send_press'); |
| 573 | 568 | return ''; |
| @@ -650,19 +645,29 @@ async function summarizeChatWebLLM(context, force) { | ||
| 650 | 645 | params.max_tokens = extension_settings.memory.overrideResponseLength; |
| 651 | 646 | } |
| 652 | 647 | |
| 653 | - const summary = await generateWebLlmChatPrompt(messages, params); | |
| 648 | + try { | |
| 654 | - const newContext = getContext(); | |
| 649 | + inApiCall = true; | |
| 650 | + const summary = await generateWebLlmChatPrompt(messages, params); | |
| 651 | + const newContext = getContext(); | |
| 655 | 652 | |
| 656 | - // something changed during summarization request | |
| 653 | + if (!summary) { | |
| 657 | - if (newContext.groupId !== context.groupId || | |
| 654 | + console.warn('Empty summary received'); | |
| 658 | - newContext.chatId !== context.chatId || | |
| 655 | + return; | |
| 659 | - (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 656 | + } | |
| 660 | - console.log('Context changed, summary discarded'); | |
| 661 | - return; | |
| 662 | - } | |
| 663 | 657 | |
| 664 | - setMemoryContext(summary, true, lastUsedIndex); | |
| 658 | + // something changed during summarization request | |
| 665 | - return summary; | |
| 659 | + if (newContext.groupId !== context.groupId || | |
| 660 | + newContext.chatId !== context.chatId || | |
| 661 | + (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 662 | + console.log('Context changed, summary discarded'); | |
| 663 | + return; | |
| 664 | + } | |
| 665 | + | |
| 666 | + setMemoryContext(summary, true, lastUsedIndex); | |
| 667 | + return summary; | |
| 668 | + } finally { | |
| 669 | + inApiCall = false; | |
| 670 | + } | |
| 666 | 671 | } |
| 667 | 672 | |
| 668 | 673 | async function summarizeChatMain(context, force, skipWIAN) { |
| @@ -677,12 +682,18 @@ async function summarizeChatMain(context, force, skipWIAN) { | ||
| 677 | 682 | let index = null; |
| 678 | 683 | |
| 679 | 684 | if (prompt_builders.DEFAULT === extension_settings.memory.prompt_builder) { |
| 680 | - summary = await generateQuietPrompt(prompt, false, skipWIAN, '', '', extension_settings.memory.overrideResponseLength); | |
| 685 | + try { | |
| 686 | + inApiCall = true; | |
| 687 | + summary = await generateQuietPrompt(prompt, false, skipWIAN, '', '', extension_settings.memory.overrideResponseLength); | |
| 688 | + } finally { | |
| 689 | + inApiCall = false; | |
| 690 | + } | |
| 681 | 691 | } |
| 682 | 692 | |
| 683 | 693 | if ([prompt_builders.RAW_BLOCKING, prompt_builders.RAW_NON_BLOCKING].includes(extension_settings.memory.prompt_builder)) { |
| 684 | 694 | const lock = extension_settings.memory.prompt_builder === prompt_builders.RAW_BLOCKING; |
| 685 | 695 | try { |
| 696 | + inApiCall = true; | |
| 686 | 697 | if (lock) { |
| 687 | 698 | deactivateSendButtons(); |
| 688 | 699 | } |
| @@ -700,12 +711,18 @@ async function summarizeChatMain(context, force, skipWIAN) { | ||
| 700 | 711 | summary = await generateRaw(rawPrompt, '', false, false, prompt, extension_settings.memory.overrideResponseLength); |
| 701 | 712 | index = lastUsedIndex; |
| 702 | 713 | } finally { |
| 714 | + inApiCall = false; | |
| 703 | 715 | if (lock) { |
| 704 | 716 | activateSendButtons(); |
| 705 | 717 | } |
| 706 | 718 | } |
| 707 | 719 | } |
| 708 | 720 | |
| 721 | + if (!summary) { | |
| 722 | + console.warn('Empty summary received'); | |
| 723 | + return; | |
| 724 | + } | |
| 725 | + | |
| 709 | 726 | const newContext = getContext(); |
| 710 | 727 | |
| 711 | 728 | // something changed during summarization request |
| @@ -840,6 +857,11 @@ async function summarizeChatExtras(context) { | ||
| 840 | 857 | const summary = await callExtrasSummarizeAPI(resultingString); |
| 841 | 858 | const newContext = getContext(); |
| 842 | 859 | |
| 860 | + if (!summary) { | |
| 861 | + console.warn('Empty summary received'); | |
| 862 | + return; | |
| 863 | + } | |
| 864 | + | |
| 843 | 865 | // something changed during summarization request |
| 844 | 866 | if (newContext.groupId !== context.groupId |
| 845 | 867 | || newContext.chatId !== context.chatId |
| @@ -1,4 +1,3 @@ | ||
| 1 | -import { eventSource, event_types } from '../script.js'; | |
| 2 | 1 | import { power_user } from './power-user.js'; |
| 3 | 2 | import { delay } from './utils.js'; |
| 4 | 3 | |
| @@ -268,7 +267,6 @@ export class SmoothEventSourceStream extends EventSourceStream { | ||
| 268 | 267 | hasFocus && await delay(getDelay(lastStr)); |
| 269 | 268 | controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) })); |
| 270 | 269 | lastStr = parsed.chunk; |
| 271 | - hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk); | |
| 272 | 270 | } |
| 273 | 271 | } catch (error) { |
| 274 | 272 | console.debug('Smooth Streaming parsing error', error); |