mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-23 16:02:06 +01:00
Merge pull request #828 from ouoertheo/ouoertheo/objective-qol-improvements
This commit is contained in:
commit
41a08fed2b
@ -69,10 +69,17 @@ function getTaskByIdRecurse(taskId, task) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function substituteParamsPrompts(content) {
|
||||||
|
content = content.replace(/{{objective}}/gi, currentObjective.description)
|
||||||
|
content = content.replace(/{{task}}/gi, currentTask.description)
|
||||||
|
content = substituteParams(content)
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
// Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much.
|
// Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much.
|
||||||
async function generateTasks() {
|
async function generateTasks() {
|
||||||
|
|
||||||
const prompt = substituteParams(objectivePrompts.createTask.replace(/{{objective}}/gi, currentObjective.description));
|
const prompt = substituteParamsPrompts(objectivePrompts.createTask);
|
||||||
console.log(`Generating tasks for objective with prompt`)
|
console.log(`Generating tasks for objective with prompt`)
|
||||||
toastr.info('Generating tasks for objective', 'Please wait...');
|
toastr.info('Generating tasks for objective', 'Please wait...');
|
||||||
const taskResponse = await generateQuietPrompt(prompt)
|
const taskResponse = await generateQuietPrompt(prompt)
|
||||||
@ -101,7 +108,7 @@ async function checkTaskCompleted() {
|
|||||||
}
|
}
|
||||||
checkCounter = $('#objective-check-frequency').val()
|
checkCounter = $('#objective-check-frequency').val()
|
||||||
|
|
||||||
const prompt = substituteParams(objectivePrompts.checkTaskCompleted.replace(/{{task}}/gi, currentTask.description));
|
const prompt = substituteParamsPrompts(objectivePrompts.checkTaskCompleted);
|
||||||
const taskResponse = (await generateQuietPrompt(prompt)).toLowerCase()
|
const taskResponse = (await generateQuietPrompt(prompt)).toLowerCase()
|
||||||
|
|
||||||
// Check response if task complete
|
// Check response if task complete
|
||||||
@ -149,7 +156,7 @@ function setCurrentTask(taskId = null) {
|
|||||||
// Don't just check for a current task, check if it has data
|
// Don't just check for a current task, check if it has data
|
||||||
const description = currentTask.description || null;
|
const description = currentTask.description || null;
|
||||||
if (description) {
|
if (description) {
|
||||||
const extensionPromptText = objectivePrompts.currentTask.replace(/{{task}}/gi, description);
|
const extensionPromptText = substituteParamsPrompts(objectivePrompts.currentTask);
|
||||||
|
|
||||||
// Remove highlights
|
// Remove highlights
|
||||||
$('.objective-task').css({'border-color':'','border-width':''})
|
$('.objective-task').css({'border-color':'','border-width':''})
|
||||||
@ -163,7 +170,6 @@ function setCurrentTask(taskId = null) {
|
|||||||
highlightTask = parent
|
highlightTask = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update the extension prompt
|
// Update the extension prompt
|
||||||
context.setExtensionPrompt(MODULE_NAME, extensionPromptText, 1, $('#objective-chat-depth').val());
|
context.setExtensionPrompt(MODULE_NAME, extensionPromptText, 1, $('#objective-chat-depth').val());
|
||||||
console.info(`Current task in context.extensionPrompts.Objective is ${JSON.stringify(context.extensionPrompts.Objective)}`);
|
console.info(`Current task in context.extensionPrompts.Objective is ${JSON.stringify(context.extensionPrompts.Objective)}`);
|
||||||
@ -369,6 +375,8 @@ function onEditPromptClick() {
|
|||||||
let popupText = ''
|
let popupText = ''
|
||||||
popupText += `
|
popupText += `
|
||||||
<div class="objective_prompt_modal">
|
<div class="objective_prompt_modal">
|
||||||
|
<small>Edit prompts used by Objective for this session. You can use {{objective}} or {{task}} plus any other standard template variables. Save template to persist changes.</small>
|
||||||
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<label for="objective-prompt-generate">Generation Prompt</label>
|
<label for="objective-prompt-generate">Generation Prompt</label>
|
||||||
<textarea id="objective-prompt-generate" type="text" class="text_pole textarea_compact" rows="8"></textarea>
|
<textarea id="objective-prompt-generate" type="text" class="text_pole textarea_compact" rows="8"></textarea>
|
||||||
@ -378,12 +386,12 @@ function onEditPromptClick() {
|
|||||||
<textarea id="objective-prompt-extension-prompt" type="text" class="text_pole textarea_compact" rows="8"></textarea>
|
<textarea id="objective-prompt-extension-prompt" type="text" class="text_pole textarea_compact" rows="8"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="objective_prompt_block">
|
<div class="objective_prompt_block">
|
||||||
<input id="objective-custom-prompt-name" style="flex-grow:2" type="text" class="flex1 heightFitContent text_pole widthNatural" maxlength="250" placeholder="Custom Prompt Name">
|
<label for="objective-custom-prompt-select">Custom Prompt Select</label>
|
||||||
<input id="objective-custom-prompt-save" style="flex-grow:1" class="menu_button" type="submit" value="Save Prompt" />
|
<select id="objective-custom-prompt-select"><select>
|
||||||
</div>
|
</div>
|
||||||
<div class="objective_prompt_block">
|
<div class="objective_prompt_block">
|
||||||
<label for="objective-prompt-load">Load Prompt</label>
|
<input id="objective-custom-prompt-new" class="menu_button" type="submit" value="New Prompt" />
|
||||||
<select id="objective-prompt-load"><select>
|
<input id="objective-custom-prompt-save" class="menu_button" type="submit" value="Save Prompt" />
|
||||||
<input id="objective-custom-prompt-delete" class="menu_button" type="submit" value="Delete Prompt" />
|
<input id="objective-custom-prompt-delete" class="menu_button" type="submit" value="Delete Prompt" />
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
@ -406,22 +414,27 @@ function onEditPromptClick() {
|
|||||||
objectivePrompts.currentTask = $('#objective-prompt-extension-prompt').val()
|
objectivePrompts.currentTask = $('#objective-prompt-extension-prompt').val()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Handle new
|
||||||
|
$('#objective-custom-prompt-new').on('click', () => {
|
||||||
|
newCustomPrompt()
|
||||||
|
})
|
||||||
|
|
||||||
// Handle save
|
// Handle save
|
||||||
$('#objective-custom-prompt-save').on('click', () => {
|
$('#objective-custom-prompt-save').on('click', () => {
|
||||||
saveCustomPrompt($('#objective-custom-prompt-name').val(), objectivePrompts)
|
saveCustomPrompt()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle delete
|
// Handle delete
|
||||||
$('#objective-custom-prompt-delete').on('click', () => {
|
$('#objective-custom-prompt-delete').on('click', () => {
|
||||||
const optionSelected = $("#objective-prompt-load").find(':selected').val()
|
deleteCustomPrompt()
|
||||||
deleteCustomPrompt(optionSelected)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle load
|
// Handle load
|
||||||
$('#objective-prompt-load').on('change', loadCustomPrompt)
|
$('#objective-custom-prompt-select').on('change', loadCustomPrompt)
|
||||||
}
|
}
|
||||||
|
async function newCustomPrompt() {
|
||||||
|
const customPromptName = await callPopup('<h3>Custom Prompt name:</h3>', 'input');
|
||||||
|
|
||||||
function saveCustomPrompt(customPromptName, customPrompts) {
|
|
||||||
if (customPromptName == "") {
|
if (customPromptName == "") {
|
||||||
toastr.warning("Please set custom prompt name to save.")
|
toastr.warning("Please set custom prompt name to save.")
|
||||||
return
|
return
|
||||||
@ -431,12 +444,25 @@ function saveCustomPrompt(customPromptName, customPrompts) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
extension_settings.objective.customPrompts[customPromptName] = {}
|
extension_settings.objective.customPrompts[customPromptName] = {}
|
||||||
Object.assign(extension_settings.objective.customPrompts[customPromptName], customPrompts)
|
Object.assign(extension_settings.objective.customPrompts[customPromptName], objectivePrompts)
|
||||||
saveSettingsDebounced()
|
saveSettingsDebounced()
|
||||||
populateCustomPrompts()
|
populateCustomPrompts()
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteCustomPrompt(customPromptName){
|
function saveCustomPrompt() {
|
||||||
|
const customPromptName = $("#objective-custom-prompt-select").find(':selected').val()
|
||||||
|
if (customPromptName == "default"){
|
||||||
|
toastr.error("Cannot save over default prompt")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Object.assign(extension_settings.objective.customPrompts[customPromptName], objectivePrompts)
|
||||||
|
saveSettingsDebounced()
|
||||||
|
populateCustomPrompts()
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCustomPrompt(){
|
||||||
|
const customPromptName = $("#objective-custom-prompt-select").find(':selected').val()
|
||||||
|
|
||||||
if (customPromptName == "default"){
|
if (customPromptName == "default"){
|
||||||
toastr.error("Cannot delete default prompt")
|
toastr.error("Cannot delete default prompt")
|
||||||
return
|
return
|
||||||
@ -448,8 +474,7 @@ function deleteCustomPrompt(customPromptName){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadCustomPrompt(){
|
function loadCustomPrompt(){
|
||||||
const optionSelected = $("#objective-prompt-load").find(':selected').val()
|
const optionSelected = $("#objective-custom-prompt-select").find(':selected').val()
|
||||||
console.log(optionSelected)
|
|
||||||
Object.assign(objectivePrompts, extension_settings.objective.customPrompts[optionSelected])
|
Object.assign(objectivePrompts, extension_settings.objective.customPrompts[optionSelected])
|
||||||
|
|
||||||
$('#objective-prompt-generate').val(objectivePrompts.createTask)
|
$('#objective-prompt-generate').val(objectivePrompts.createTask)
|
||||||
@ -459,13 +484,13 @@ function loadCustomPrompt(){
|
|||||||
|
|
||||||
function populateCustomPrompts(){
|
function populateCustomPrompts(){
|
||||||
// Populate saved prompts
|
// Populate saved prompts
|
||||||
$('#objective-prompt-load').empty()
|
$('#objective-custom-prompt-select').empty()
|
||||||
for (const customPromptName in extension_settings.objective.customPrompts){
|
for (const customPromptName in extension_settings.objective.customPrompts){
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.innerText = customPromptName;
|
option.innerText = customPromptName;
|
||||||
option.value = customPromptName;
|
option.value = customPromptName;
|
||||||
option.selected = customPromptName
|
option.selected = customPromptName
|
||||||
$('#objective-prompt-load').append(option)
|
$('#objective-custom-prompt-select').append(option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,8 +599,10 @@ function onChatDepthInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onObjectiveTextFocusOut(){
|
function onObjectiveTextFocusOut(){
|
||||||
|
if (currentObjective){
|
||||||
currentObjective.description = $('#objective-text').val()
|
currentObjective.description = $('#objective-text').val()
|
||||||
saveState()
|
saveState()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update how often we check for task completion
|
// Update how often we check for task completion
|
||||||
@ -752,7 +779,7 @@ jQuery(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
eventSource.on(event_types.MESSAGE_RECEIVED, () => {
|
eventSource.on(event_types.MESSAGE_RECEIVED, () => {
|
||||||
if (currentChatId == undefined) {
|
if (currentChatId == undefined || currentTask == undefined) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ($("#objective-check-frequency").val() > 0) {
|
if ($("#objective-check-frequency").val() > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user