Add lastMessage macro. Substitute params in CFG negative prompts
This commit is contained in:
parent
d114ebf6fa
commit
f4630f9808
|
@ -1878,6 +1878,20 @@ function getLastMessageId() {
|
|||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last message in the chat.
|
||||
* @returns {string} The last message in the chat.
|
||||
*/
|
||||
function getLastMessage() {
|
||||
const index = chat?.length - 1;
|
||||
|
||||
if (!isNaN(index) && index >= 0) {
|
||||
return chat[index].mes;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes {{macro}} parameters in a string.
|
||||
* @param {string} content - The string to substitute parameters in.
|
||||
|
@ -1920,6 +1934,7 @@ function substituteParams(content, _name1, _name2, _original, _group, _replaceCh
|
|||
content = content.replace(/{{char}}/gi, _name2);
|
||||
content = content.replace(/{{charIfNotGroup}}/gi, _group);
|
||||
content = content.replace(/{{group}}/gi, _group);
|
||||
content = content.replace(/{{lastMessage}}/gi, getLastMessage());
|
||||
content = content.replace(/{{lastMessageId}}/gi, getLastMessageId());
|
||||
|
||||
content = content.replace(/<USER>/gi, _name1);
|
||||
|
|
|
@ -4,7 +4,8 @@ import {
|
|||
getStoppingStrings,
|
||||
novelai_setting_names,
|
||||
saveSettingsDebounced,
|
||||
setGenerationParamsFromPreset
|
||||
setGenerationParamsFromPreset,
|
||||
substituteParams,
|
||||
} from "../script.js";
|
||||
import { getCfgPrompt } from "./cfg-scale.js";
|
||||
import { MAX_CONTEXT_DEFAULT } from "./power-user.js";
|
||||
|
@ -454,7 +455,7 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
|||
"mirostat_lr": Number(nai_settings.mirostat_lr),
|
||||
"mirostat_tau": Number(nai_settings.mirostat_tau),
|
||||
"cfg_scale": cfgValues?.guidanceScale?.value ?? Number(nai_settings.cfg_scale),
|
||||
"cfg_uc": cfgValues?.negativePrompt ?? nai_settings.cfg_uc ?? "",
|
||||
"cfg_uc": cfgValues?.negativePrompt ?? substituteParams(nai_settings.cfg_uc) ?? "",
|
||||
"phrase_rep_pen": nai_settings.phrase_rep_pen,
|
||||
"stop_sequences": stopSequences,
|
||||
"bad_words_ids": badWordIds,
|
||||
|
|
|
@ -11,6 +11,7 @@ System-wide Replacement Macros (in order of evaluation):
|
|||
<li><tt>{{mesExamples}}</tt> – the Character's Dialogue Examples</li>
|
||||
<li><tt>{{user}}</tt> – your current Persona username</li>
|
||||
<li><tt>{{char}}</tt> – the Character's name</li>
|
||||
<li><tt>{{lastMessage}}</tt> - the text of the latest chat message.</li>
|
||||
<li><tt>{{lastMessageId}}</tt> – index # of the latest chat message. Useful for slash command batching.</li>
|
||||
<li><tt>{{// (note)}}</tt> – you can leave a note here, and the macro will be replaced with blank content. Not visible for the AI.</li>
|
||||
<li><tt>{{time}}</tt> – the current time</li>
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
saveSettingsDebounced,
|
||||
setGenerationParamsFromPreset,
|
||||
setOnlineStatus,
|
||||
substituteParams,
|
||||
} from "../script.js";
|
||||
|
||||
import {
|
||||
|
@ -563,7 +564,7 @@ export function getTextGenGenerationData(finalPrompt, this_amount_gen, isImperso
|
|||
'do_sample': textgenerationwebui_settings.do_sample,
|
||||
'seed': textgenerationwebui_settings.seed,
|
||||
'guidance_scale': cfgValues?.guidanceScale?.value ?? textgenerationwebui_settings.guidance_scale ?? 1,
|
||||
'negative_prompt': cfgValues?.negativePrompt ?? textgenerationwebui_settings.negative_prompt ?? '',
|
||||
'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(textgenerationwebui_settings.negative_prompt) ?? '',
|
||||
'grammar_string': textgenerationwebui_settings.grammar_string,
|
||||
}
|
||||
let aphroditeFlags = {
|
||||
|
|
Loading…
Reference in New Issue