mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-10 00:50:43 +01:00
Add images to quiet prompts if inlining enabled
This commit is contained in:
parent
4b4880bf11
commit
323b338cdd
@ -2104,16 +2104,17 @@ function getStoppingStrings(isImpersonate) {
|
|||||||
* @param {string} quiet_prompt Instruction prompt for the AI
|
* @param {string} quiet_prompt Instruction prompt for the AI
|
||||||
* @param {boolean} quietToLoud Whether the message should be sent in a foreground (loud) or background (quiet) mode
|
* @param {boolean} quietToLoud Whether the message should be sent in a foreground (loud) or background (quiet) mode
|
||||||
* @param {boolean} skipWIAN whether to skip addition of World Info and Author's Note into the prompt
|
* @param {boolean} skipWIAN whether to skip addition of World Info and Author's Note into the prompt
|
||||||
|
* @param {string} quietImage Image to use for the quiet prompt
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN) {
|
export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN, quietImage = null) {
|
||||||
console.log('got into genQuietPrompt')
|
console.log('got into genQuietPrompt')
|
||||||
const skipWIANvalue = skipWIAN
|
const skipWIANvalue = skipWIAN
|
||||||
return await new Promise(
|
return await new Promise(
|
||||||
async function promptPromise(resolve, reject) {
|
async function promptPromise(resolve, reject) {
|
||||||
if (quietToLoud === true) {
|
if (quietToLoud === true) {
|
||||||
try {
|
try {
|
||||||
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: true, skipWIAN: skipWIAN, force_name2: true, });
|
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: true, skipWIAN: skipWIAN, force_name2: true, quietImage: quietImage });
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
reject();
|
reject();
|
||||||
@ -2122,7 +2123,7 @@ export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN) {
|
|||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
console.log('going to generate non-QuietToLoud')
|
console.log('going to generate non-QuietToLoud')
|
||||||
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: false, skipWIAN: skipWIAN, force_name2: true, });
|
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: false, skipWIAN: skipWIAN, force_name2: true, quietImage: quietImage });
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
reject();
|
reject();
|
||||||
@ -2671,7 +2672,7 @@ export async function generateRaw(prompt, api) {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal } = {}, dryRun = false) {
|
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage } = {}, dryRun = false) {
|
||||||
console.log('Generate entered');
|
console.log('Generate entered');
|
||||||
setGenerationProgress(0);
|
setGenerationProgress(0);
|
||||||
generation_started = new Date();
|
generation_started = new Date();
|
||||||
@ -2726,7 +2727,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selected_group && !is_group_generating && !dryRun) {
|
if (selected_group && !is_group_generating && !dryRun) {
|
||||||
generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal });
|
generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal, quietImage });
|
||||||
return;
|
return;
|
||||||
} else if (selected_group && !is_group_generating && dryRun) {
|
} else if (selected_group && !is_group_generating && dryRun) {
|
||||||
const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
|
const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
|
||||||
@ -3432,6 +3433,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
bias: promptBias,
|
bias: promptBias,
|
||||||
type: type,
|
type: type,
|
||||||
quietPrompt: quiet_prompt,
|
quietPrompt: quiet_prompt,
|
||||||
|
quietImage: quietImage,
|
||||||
cyclePrompt: cyclePrompt,
|
cyclePrompt: cyclePrompt,
|
||||||
systemPromptOverride: system,
|
systemPromptOverride: system,
|
||||||
jailbreakPromptOverride: jailbreak,
|
jailbreakPromptOverride: jailbreak,
|
||||||
@ -6812,6 +6814,7 @@ window["SillyTavern"].getContext = function () {
|
|||||||
extensionSettings: extension_settings,
|
extensionSettings: extension_settings,
|
||||||
ModuleWorkerWrapper: ModuleWorkerWrapper,
|
ModuleWorkerWrapper: ModuleWorkerWrapper,
|
||||||
getTokenizerModel: getTokenizerModel,
|
getTokenizerModel: getTokenizerModel,
|
||||||
|
generateQuietPrompt: generateQuietPrompt,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
tagMap: tag_map,
|
tagMap: tag_map,
|
||||||
};
|
};
|
||||||
|
@ -103,7 +103,7 @@ class ModuleWorkerWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Called by the extension
|
// Called by the extension
|
||||||
async update() {
|
async update(...args) {
|
||||||
// Don't touch me I'm busy...
|
// Don't touch me I'm busy...
|
||||||
if (this.isBusy) {
|
if (this.isBusy) {
|
||||||
return;
|
return;
|
||||||
@ -112,7 +112,7 @@ class ModuleWorkerWrapper {
|
|||||||
// I'm free. Let's update!
|
// I'm free. Let's update!
|
||||||
try {
|
try {
|
||||||
this.isBusy = true;
|
this.isBusy = true;
|
||||||
await this.callback();
|
await this.callback(...args);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.isBusy = false;
|
this.isBusy = false;
|
||||||
|
@ -303,6 +303,7 @@ window.debugTtsPlayback = debugTtsPlayback
|
|||||||
//##################//
|
//##################//
|
||||||
|
|
||||||
let audioElement = new Audio()
|
let audioElement = new Audio()
|
||||||
|
audioElement.id = 'tts_audio'
|
||||||
audioElement.autoplay = true
|
audioElement.autoplay = true
|
||||||
|
|
||||||
let audioJobQueue = []
|
let audioJobQueue = []
|
||||||
@ -989,4 +990,5 @@ $(document).ready(function () {
|
|||||||
eventSource.on(event_types.MESSAGE_DELETED, onChatDeleted);
|
eventSource.on(event_types.MESSAGE_DELETED, onChatDeleted);
|
||||||
eventSource.on(event_types.GROUP_UPDATED, onChatChanged)
|
eventSource.on(event_types.GROUP_UPDATED, onChatChanged)
|
||||||
registerSlashCommand('speak', onNarrateText, ['narrate', 'tts'], `<span class="monospace">(text)</span> – narrate any text using currently selected character's voice. Use voice="Character Name" argument to set other voice from the voice map, example: <tt>/speak voice="Donald Duck" Quack!</tt>`, true, true);
|
registerSlashCommand('speak', onNarrateText, ['narrate', 'tts'], `<span class="monospace">(text)</span> – narrate any text using currently selected character's voice. Use voice="Character Name" argument to set other voice from the voice map, example: <tt>/speak voice="Donald Duck" Quack!</tt>`, true, true);
|
||||||
|
document.body.appendChild(audioElement);
|
||||||
})
|
})
|
||||||
|
@ -742,9 +742,10 @@ function getPromptPosition(position) {
|
|||||||
* @param {Object} options - An object with optional settings.
|
* @param {Object} options - An object with optional settings.
|
||||||
* @param {string} options.bias - A bias to be added in the conversation.
|
* @param {string} options.bias - A bias to be added in the conversation.
|
||||||
* @param {string} options.quietPrompt - Instruction prompt for extras
|
* @param {string} options.quietPrompt - Instruction prompt for extras
|
||||||
|
* @param {string} options.quietImage - Image prompt for extras
|
||||||
* @param {string} options.type - The type of the chat, can be 'impersonate'.
|
* @param {string} options.type - The type of the chat, can be 'impersonate'.
|
||||||
*/
|
*/
|
||||||
async function populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, type, cyclePrompt } = {}) {
|
async function populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, quietImage, type, cyclePrompt } = {}) {
|
||||||
// Helper function for preparing a prompt, that already exists within the prompt collection, for completion
|
// Helper function for preparing a prompt, that already exists within the prompt collection, for completion
|
||||||
const addToChatCompletion = (source, target = null) => {
|
const addToChatCompletion = (source, target = null) => {
|
||||||
// We need the prompts array to determine a position for the source.
|
// We need the prompts array to determine a position for the source.
|
||||||
@ -781,7 +782,13 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
|||||||
// Add quiet prompt to control prompts
|
// Add quiet prompt to control prompts
|
||||||
// This should always be last, even in control prompts. Add all further control prompts BEFORE this prompt
|
// This should always be last, even in control prompts. Add all further control prompts BEFORE this prompt
|
||||||
const quietPromptMessage = Message.fromPrompt(prompts.get('quietPrompt')) ?? null;
|
const quietPromptMessage = Message.fromPrompt(prompts.get('quietPrompt')) ?? null;
|
||||||
if (quietPromptMessage && quietPromptMessage.content) controlPrompts.add(quietPromptMessage);
|
if (quietPromptMessage && quietPromptMessage.content) {
|
||||||
|
if (isImageInliningSupported() && quietImage) {
|
||||||
|
await quietPromptMessage.addImage(quietImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
controlPrompts.add(quietPromptMessage);
|
||||||
|
}
|
||||||
|
|
||||||
chatCompletion.reserveBudget(controlPrompts);
|
chatCompletion.reserveBudget(controlPrompts);
|
||||||
|
|
||||||
@ -1004,6 +1011,7 @@ export async function prepareOpenAIMessages({
|
|||||||
bias,
|
bias,
|
||||||
type,
|
type,
|
||||||
quietPrompt,
|
quietPrompt,
|
||||||
|
quietImage,
|
||||||
extensionPrompts,
|
extensionPrompts,
|
||||||
cyclePrompt,
|
cyclePrompt,
|
||||||
systemPromptOverride,
|
systemPromptOverride,
|
||||||
@ -1029,6 +1037,7 @@ export async function prepareOpenAIMessages({
|
|||||||
worldInfoAfter,
|
worldInfoAfter,
|
||||||
charDescription,
|
charDescription,
|
||||||
quietPrompt,
|
quietPrompt,
|
||||||
|
quietImage,
|
||||||
bias,
|
bias,
|
||||||
extensionPrompts,
|
extensionPrompts,
|
||||||
systemPromptOverride,
|
systemPromptOverride,
|
||||||
@ -1037,7 +1046,7 @@ export async function prepareOpenAIMessages({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fill the chat completion with as much context as the budget allows
|
// Fill the chat completion with as much context as the budget allows
|
||||||
await populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, type, cyclePrompt });
|
await populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, quietImage, type, cyclePrompt });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof TokenBudgetExceededError) {
|
if (error instanceof TokenBudgetExceededError) {
|
||||||
toastr.error('An error occurred while counting tokens: Token budget exceeded.')
|
toastr.error('An error occurred while counting tokens: Token budget exceeded.')
|
||||||
|
@ -27,7 +27,7 @@ function registerEndpoints(app, jsonParser) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
max_tokens: 300
|
max_tokens: 500
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('OpenAI request', body);
|
console.log('OpenAI request', body);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user