mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add proper processing of streaming aborting
This commit is contained in:
		@@ -436,7 +436,12 @@ function getSystemPrompt(nsfw_toggle_prompt, enhance_definitions_prompt, wiBefor
 | 
			
		||||
    return whole_prompt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function sendOpenAIRequest(openai_msgs_tosend) {
 | 
			
		||||
async function sendOpenAIRequest(openai_msgs_tosend, signal) {
 | 
			
		||||
    // Provide default abort signal
 | 
			
		||||
    if (!signal) {
 | 
			
		||||
        signal = new AbortController().signal;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (oai_settings.reverse_proxy) {
 | 
			
		||||
        validateReverseProxy();
 | 
			
		||||
    }
 | 
			
		||||
@@ -459,7 +464,8 @@ async function sendOpenAIRequest(openai_msgs_tosend) {
 | 
			
		||||
        headers: {
 | 
			
		||||
            'Content-Type': 'application/json',
 | 
			
		||||
            "X-CSRF-Token": token,
 | 
			
		||||
        }
 | 
			
		||||
        },
 | 
			
		||||
        signal: signal,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (oai_settings.stream_openai) {
 | 
			
		||||
 
 | 
			
		||||
@@ -86,7 +86,7 @@ function onBotChange() {
 | 
			
		||||
    saveSettingsDebounced();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function generatePoe(type, finalPrompt) {
 | 
			
		||||
async function generatePoe(type, finalPrompt, signal) {
 | 
			
		||||
    if (poe_settings.auto_purge) {
 | 
			
		||||
        let count_to_delete = -1;
 | 
			
		||||
 | 
			
		||||
@@ -136,7 +136,7 @@ async function generatePoe(type, finalPrompt) {
 | 
			
		||||
        finalPrompt = sentences.join('');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const reply = await sendMessage(finalPrompt, true);
 | 
			
		||||
    const reply = await sendMessage(finalPrompt, true, signal);
 | 
			
		||||
    got_reply = true;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
@@ -160,7 +160,11 @@ async function purgeConversation(count = -1) {
 | 
			
		||||
    return response.ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function sendMessage(prompt, withStreaming) {
 | 
			
		||||
async function sendMessage(prompt, withStreaming, signal) {
 | 
			
		||||
    if (!signal) {
 | 
			
		||||
        signal = new AbortController().signal;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const body = JSON.stringify({
 | 
			
		||||
        bot: poe_settings.bot,
 | 
			
		||||
        token: poe_settings.token,
 | 
			
		||||
@@ -175,6 +179,7 @@ async function sendMessage(prompt, withStreaming) {
 | 
			
		||||
        },
 | 
			
		||||
        body: body,
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        signal: signal,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (withStreaming && poe_settings.streaming) {
 | 
			
		||||
 
 | 
			
		||||
@@ -147,7 +147,7 @@ function setSettingByName(i, value, trigger) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function generateTextGenWithStreaming(generate_data) {
 | 
			
		||||
async function generateTextGenWithStreaming(generate_data, signal) {
 | 
			
		||||
    const response = await fetch('/generate_textgenerationwebui', {
 | 
			
		||||
        headers: {
 | 
			
		||||
            'X-CSRF-Token': token,
 | 
			
		||||
@@ -157,6 +157,7 @@ async function generateTextGenWithStreaming(generate_data) {
 | 
			
		||||
        },
 | 
			
		||||
        body: JSON.stringify(generate_data),
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        signal: signal,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return async function* streamData() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user