mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	#395 Pass AbortSignal down to groupGenerationWrapper
This commit is contained in:
		| @@ -1738,12 +1738,16 @@ class StreamingProcessor { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, force_chid } = {}) { | async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, force_chid, signal } = {}) { | ||||||
|     //console.log('Generate entered'); |     //console.log('Generate entered'); | ||||||
|     setGenerationProgress(0); |     setGenerationProgress(0); | ||||||
|     tokens_already_generated = 0; |     tokens_already_generated = 0; | ||||||
|     generation_started = new Date(); |     generation_started = new Date(); | ||||||
|  |  | ||||||
|  |     // Don't recreate abort controller if signal is passed | ||||||
|  |     if (!(abortController && signal)) { | ||||||
|         abortController = new AbortController(); |         abortController = new AbortController(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const isImpersonate = type == "impersonate"; |     const isImpersonate = type == "impersonate"; | ||||||
|     const isInstruct = power_user.instruct.enabled; |     const isInstruct = power_user.instruct.enabled; | ||||||
| @@ -1794,7 +1798,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (selected_group && !is_group_generating) { |     if (selected_group && !is_group_generating) { | ||||||
|         generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid }); |         generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal }); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -404,6 +404,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     const group = groups.find((x) => x.id === selected_group); |     const group = groups.find((x) => x.id === selected_group); | ||||||
|  |     let typingIndicator = $("#chat .typing_indicator"); | ||||||
|  |  | ||||||
|     if (!group || !Array.isArray(group.members) || !group.members.length) { |     if (!group || !Array.isArray(group.members) || !group.members.length) { | ||||||
|         sendSystemMessage(system_message_types.EMPTY); |         sendSystemMessage(system_message_types.EMPTY); | ||||||
| @@ -417,8 +418,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|         setCharacterId(undefined); |         setCharacterId(undefined); | ||||||
|         const userInput = $("#send_textarea").val(); |         const userInput = $("#send_textarea").val(); | ||||||
|  |  | ||||||
|         let typingIndicator = $("#chat .typing_indicator"); |  | ||||||
|  |  | ||||||
|         if (typingIndicator.length === 0 && !isStreamingEnabled()) { |         if (typingIndicator.length === 0 && !isStreamingEnabled()) { | ||||||
|             typingIndicator = $( |             typingIndicator = $( | ||||||
|                 "#typing_indicator_template .typing_indicator" |                 "#typing_indicator_template .typing_indicator" | ||||||
| @@ -435,6 +434,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|         let activationText = ""; |         let activationText = ""; | ||||||
|         let isUserInput = false; |         let isUserInput = false; | ||||||
|         let isGenerationDone = false; |         let isGenerationDone = false; | ||||||
|  |         let isGenerationAborted = false; | ||||||
|  |  | ||||||
|         if (userInput && userInput.length && !by_auto_mode) { |         if (userInput && userInput.length && !by_auto_mode) { | ||||||
|             isUserInput = true; |             isUserInput = true; | ||||||
| @@ -449,6 +449,16 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|         const resolveOriginal = params.resolve; |         const resolveOriginal = params.resolve; | ||||||
|         const rejectOriginal = params.reject; |         const rejectOriginal = params.reject; | ||||||
|  |  | ||||||
|  |         if (params.signal instanceof AbortSignal) { | ||||||
|  |             if (params.signal.aborted) { | ||||||
|  |                 throw new Error('Already aborted signal passed. Group generation stopped'); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             params.signal.onabort = () => { | ||||||
|  |                 isGenerationAborted = true; | ||||||
|  |             }; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (typeof params.resolve === 'function') { |         if (typeof params.resolve === 'function') { | ||||||
|             params.resolve = function () { |             params.resolve = function () { | ||||||
|                 isGenerationDone = true; |                 isGenerationDone = true; | ||||||
| @@ -517,6 +527,10 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|  |  | ||||||
|             // TODO: This is awful. Refactor this |             // TODO: This is awful. Refactor this | ||||||
|             while (true) { |             while (true) { | ||||||
|  |                 if (isGenerationAborted) { | ||||||
|  |                     throw new Error('Group generation aborted'); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 // if not swipe - check if message generated already |                 // if not swipe - check if message generated already | ||||||
|                 if (type !== "swipe" && !isMultigenEnabled() && chat.length == messagesBefore) { |                 if (type !== "swipe" && !isMultigenEnabled() && chat.length == messagesBefore) { | ||||||
|                     await delay(100); |                     await delay(100); | ||||||
| @@ -593,11 +607,12 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } finally { | ||||||
|         // hide and reapply the indicator to the bottom of the list |         // hide and reapply the indicator to the bottom of the list | ||||||
|         typingIndicator.hide(250); |         typingIndicator.hide(250); | ||||||
|         $("#chat").append(typingIndicator); |         $("#chat").append(typingIndicator); | ||||||
|         } |  | ||||||
|     } finally { |  | ||||||
|         is_group_generating = false; |         is_group_generating = false; | ||||||
|         $("#send_textarea").attr("disabled", false); |         $("#send_textarea").attr("disabled", false); | ||||||
|         setSendButtonState(false); |         setSendButtonState(false); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user