mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Deduplicate code for substitution in the story and the first message
This commit is contained in:
@ -1214,14 +1214,7 @@ function getExtensionPrompt(position = 0, depth = undefined, separator = "\n") {
|
|||||||
|
|
||||||
function baseChatReplace(value, name1, name2) {
|
function baseChatReplace(value, name1, name2) {
|
||||||
if (value !== undefined && value.length > 0) {
|
if (value !== undefined && value.length > 0) {
|
||||||
if (is_pygmalion) {
|
value = substituteParams(value, is_pygmalion ? "You:" : name1, name2);
|
||||||
value = value.replace(/{{user}}:/gi, "You:");
|
|
||||||
value = value.replace(/<USER>:/gi, "You:");
|
|
||||||
}
|
|
||||||
value = value.replace(/{{user}}/gi, name1);
|
|
||||||
value = value.replace(/{{char}}/gi, name2);
|
|
||||||
value = value.replace(/<USER>/gi, name1);
|
|
||||||
value = value.replace(/<BOT>/gi, name2);
|
|
||||||
|
|
||||||
if (power_user.collapse_newlines) {
|
if (power_user.collapse_newlines) {
|
||||||
value = collapseNewlines(value);
|
value = collapseNewlines(value);
|
||||||
@ -1544,6 +1537,11 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
is_pygmalion ? '<START>' : `This is how ${name2} should talk`;
|
is_pygmalion ? '<START>' : `This is how ${name2} should talk`;
|
||||||
let mesExamplesArray = mesExamples.split(/<START>/gi).slice(1).map(block => `${blockHeading}\n${block.trim()}\n`);
|
let mesExamplesArray = mesExamples.split(/<START>/gi).slice(1).map(block => `${blockHeading}\n${block.trim()}\n`);
|
||||||
|
|
||||||
|
// First message in fresh 1-on-1 chat reacts to user/character settings changes
|
||||||
|
if (chat.length) {
|
||||||
|
chat[0].mes = substituteParams(chat[0].mes);
|
||||||
|
}
|
||||||
|
|
||||||
if (main_api === 'openai') {
|
if (main_api === 'openai') {
|
||||||
const oai_chat = chat.filter(x => !x.is_system);
|
const oai_chat = chat.filter(x => !x.is_system);
|
||||||
|
|
||||||
@ -1587,12 +1585,6 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
console.log('pre-replace chat.length = ' + chat.length);
|
console.log('pre-replace chat.length = ' + chat.length);
|
||||||
for (let i = chat.length - 1, j = 0; i >= 0; i--, j++) {
|
for (let i = chat.length - 1, j = 0; i >= 0; i--, j++) {
|
||||||
let charName = selected_group ? chat[j].name : name2;
|
let charName = selected_group ? chat[j].name : name2;
|
||||||
if (j == 0) {
|
|
||||||
chat[j]['mes'] = chat[j]['mes'].replace(/{{user}}/gi, name1);
|
|
||||||
chat[j]['mes'] = chat[j]['mes'].replace(/{{char}}/gi, charName);
|
|
||||||
chat[j]['mes'] = chat[j]['mes'].replace(/<USER>/gi, name1);
|
|
||||||
chat[j]['mes'] = chat[j]['mes'].replace(/<BOT>/gi, charName);
|
|
||||||
}
|
|
||||||
let this_mes_ch_name = '';
|
let this_mes_ch_name = '';
|
||||||
if (chat[j]['is_user']) {
|
if (chat[j]['is_user']) {
|
||||||
this_mes_ch_name = name1;
|
this_mes_ch_name = name1;
|
||||||
|
@ -148,10 +148,6 @@ function setOpenAIMessages(chat) {
|
|||||||
// clean openai msgs
|
// clean openai msgs
|
||||||
openai_msgs = [];
|
openai_msgs = [];
|
||||||
for (let i = chat.length - 1; i >= 0; i--) {
|
for (let i = chat.length - 1; i >= 0; i--) {
|
||||||
// first greeting message
|
|
||||||
if (j == 0) {
|
|
||||||
chat[j]['mes'] = substituteParams(chat[j]['mes']);
|
|
||||||
}
|
|
||||||
let role = chat[j]['is_user'] ? 'user' : 'assistant';
|
let role = chat[j]['is_user'] ? 'user' : 'assistant';
|
||||||
let content = chat[j]['mes'];
|
let content = chat[j]['mes'];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user