mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	force output sequence (first or last)
This commit is contained in:
		| @@ -164,6 +164,7 @@ import { getRegexedString, regex_placement } from "./scripts/extensions/regex/en | |||||||
| import { FILTER_TYPES, FilterHelper } from "./scripts/filters.js"; | import { FILTER_TYPES, FilterHelper } from "./scripts/filters.js"; | ||||||
| import { getCfgPrompt, getGuidanceScale } from "./scripts/extensions/cfg/util.js"; | import { getCfgPrompt, getGuidanceScale } from "./scripts/extensions/cfg/util.js"; | ||||||
| import { | import { | ||||||
|  |     force_output_sequence, | ||||||
|     formatInstructModeChat, |     formatInstructModeChat, | ||||||
|     formatInstructModePrompt, |     formatInstructModePrompt, | ||||||
|     formatInstructModeExamples, |     formatInstructModeExamples, | ||||||
| @@ -2434,15 +2435,15 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, | |||||||
|             chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false); |             chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false); | ||||||
|  |  | ||||||
|             if (j === 0 && isInstruct) { |             if (j === 0 && isInstruct) { | ||||||
|                 // Reformat with the first output line (if any) |                 // Reformat with the first output sequence (if any) | ||||||
|                 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, true); |                 chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.FIRST); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Do not suffix the message for continuation |             // Do not suffix the message for continuation | ||||||
|             if (i === 0 && isContinue) { |             if (i === 0 && isContinue) { | ||||||
|                 if (isInstruct) { |                 if (isInstruct) { | ||||||
|                     // Reformat with the last output line (if any) |                     // Reformat with the last output sequence (if any) | ||||||
|                     chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, true); |                     chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length); |                 chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length); | ||||||
| @@ -3235,9 +3236,9 @@ export function getBiasStrings(textareaText, type) { | |||||||
| /** | /** | ||||||
|  * @param {Object} chatItem Message history item. |  * @param {Object} chatItem Message history item. | ||||||
|  * @param {boolean} isInstruct Whether instruct mode is enabled. |  * @param {boolean} isInstruct Whether instruct mode is enabled. | ||||||
|  * @param {boolean} forceLastOutputSequence Whether to force the last output sequence for instruct mode. |  * @param {boolean|number} forceOutputSequence Whether to force the first/last output sequence for instruct mode. | ||||||
|  */ |  */ | ||||||
| function formatMessageHistoryItem(chatItem, isInstruct, forceLastOutputSequence) { | function formatMessageHistoryItem(chatItem, isInstruct, forceOutputSequence) { | ||||||
|     const isNarratorType = chatItem?.extra?.type === system_message_types.NARRATOR; |     const isNarratorType = chatItem?.extra?.type === system_message_types.NARRATOR; | ||||||
|     const characterName = (selected_group || chatItem.force_avatar) ? chatItem.name : name2; |     const characterName = (selected_group || chatItem.force_avatar) ? chatItem.name : name2; | ||||||
|     const itemName = chatItem.is_user ? chatItem['name'] : characterName; |     const itemName = chatItem.is_user ? chatItem['name'] : characterName; | ||||||
| @@ -3246,7 +3247,7 @@ function formatMessageHistoryItem(chatItem, isInstruct, forceLastOutputSequence) | |||||||
|     let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`; |     let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`; | ||||||
|  |  | ||||||
|     if (isInstruct) { |     if (isInstruct) { | ||||||
|         textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceLastOutputSequence); |         textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceOutputSequence); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     textResult = replaceBiasMarkup(textResult); |     textResult = replaceBiasMarkup(textResult); | ||||||
|   | |||||||
| @@ -217,6 +217,11 @@ export function getInstructStoppingSequences() { | |||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export const force_output_sequence = { | ||||||
|  |     FIRST: 1, | ||||||
|  |     LAST: 2, | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Formats instruct mode chat message. |  * Formats instruct mode chat message. | ||||||
|  * @param {string} name Character name. |  * @param {string} name Character name. | ||||||
| @@ -226,10 +231,10 @@ export function getInstructStoppingSequences() { | |||||||
|  * @param {string} forceAvatar Force avatar string. |  * @param {string} forceAvatar Force avatar string. | ||||||
|  * @param {string} name1 User name. |  * @param {string} name1 User name. | ||||||
|  * @param {string} name2 Character name. |  * @param {string} name2 Character name. | ||||||
|  * @param {boolean} forceLastOutputSequence Force to use last outline sequence (if configured). |  * @param {boolean|number} forceOutputSequence Force to use first/last output sequence (if configured). | ||||||
|  * @returns {string} Formatted instruct mode chat message. |  * @returns {string} Formatted instruct mode chat message. | ||||||
|  */ |  */ | ||||||
| export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2, forceLastOutputSequence) { | export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2, forceOutputSequence) { | ||||||
|     let includeNames = isNarrator ? false : power_user.instruct.names; |     let includeNames = isNarrator ? false : power_user.instruct.names; | ||||||
|  |  | ||||||
|     if (!isNarrator && power_user.instruct.names_force_groups && (selected_group || forceAvatar)) { |     if (!isNarrator && power_user.instruct.names_force_groups && (selected_group || forceAvatar)) { | ||||||
| @@ -238,10 +243,10 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata | |||||||
|  |  | ||||||
|     let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence; |     let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence; | ||||||
|  |  | ||||||
|     if (forceLastOutputSequence) { |     if (forceOutputSequence && sequence === power_user.instruct.output_sequence) { | ||||||
|         if (sequence === power_user.instruct.output_sequence && power_user.instruct.first_output_sequence) { |         if (forceOutputSequence === force_output_sequence.FIRST && power_user.instruct.first_output_sequence) { | ||||||
|             sequence = power_user.instruct.first_output_sequence; |             sequence = power_user.instruct.first_output_sequence; | ||||||
|         } else if (sequence === power_user.instruct.output_sequence && power_user.instruct.last_output_sequence) { |         } else if (forceOutputSequence === force_output_sequence.LAST && power_user.instruct.last_output_sequence) { | ||||||
|             sequence = power_user.instruct.last_output_sequence; |             sequence = power_user.instruct.last_output_sequence; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user