mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add counter, fix some bugs
This commit is contained in:
		| @@ -19,7 +19,7 @@ let checkCounter = 0 | |||||||
| const objectivePrompts = { | const objectivePrompts = { | ||||||
|     "createTask": `Pause your roleplay and generate a list of tasks to complete an objective. Your next response must be formatted as a numbered list of plain text entries. Do not include anything but the numbered list. The list must be prioritized in the order that tasks must be completed. |     "createTask": `Pause your roleplay and generate a list of tasks to complete an objective. Your next response must be formatted as a numbered list of plain text entries. Do not include anything but the numbered list. The list must be prioritized in the order that tasks must be completed. | ||||||
|  |  | ||||||
|     The objective that you must make a numbered task list for is: {{objective}}. |     The objective that you must make a numbered task list for is: [{{objective}}]. | ||||||
|     The tasks created should take into account the character traits of {{char}}. These tasks may or may not involve {{user}} |     The tasks created should take into account the character traits of {{char}}. These tasks may or may not involve {{user}} | ||||||
|  |  | ||||||
|     Given an example objective of 'Make me a four course dinner', here is an example output: |     Given an example objective of 'Make me a four course dinner', here is an example output: | ||||||
| @@ -31,7 +31,7 @@ const objectivePrompts = { | |||||||
|     6. Serve the food |     6. Serve the food | ||||||
|     7. Enjoy eating the meal with {{user}} |     7. Enjoy eating the meal with {{user}} | ||||||
|     `, |     `, | ||||||
|     "checkTaskCompleted": `Pause your roleplay. Determine if this task is completed: {{task}}.  |     "checkTaskCompleted": `Pause your roleplay. Determine if this task is completed: [{{task}}].  | ||||||
|     To do this, examine the most recent messages. Your response must only contain either true or false, nothing other words. |     To do this, examine the most recent messages. Your response must only contain either true or false, nothing other words. | ||||||
|     Example output: |     Example output: | ||||||
|     true |     true | ||||||
| @@ -39,7 +39,7 @@ const objectivePrompts = { | |||||||
| } | } | ||||||
|  |  | ||||||
| const injectPrompts = { | const injectPrompts = { | ||||||
|     "task": "Your current task is {{task}}. Balance existing roleplay with completing this task." |     "task": "Your current task is [{{task}}]. Balance existing roleplay with completing this task." | ||||||
| } | } | ||||||
|  |  | ||||||
| // Background prompt generation | // Background prompt generation | ||||||
| @@ -66,6 +66,7 @@ function addTask(description, position=null) { | |||||||
|         "description": description, |         "description": description, | ||||||
|         "completed": false |         "completed": false | ||||||
|     }) |     }) | ||||||
|  |     saveState() | ||||||
| } | } | ||||||
|  |  | ||||||
| // Get a task either by index or task description. Return current task if none specified | // Get a task either by index or task description. Return current task if none specified | ||||||
| @@ -89,6 +90,7 @@ function completeTask(task) { | |||||||
|     console.info(`Task successfully completed: ${JSON.stringify(task)}`) |     console.info(`Task successfully completed: ${JSON.stringify(task)}`) | ||||||
|     setCurrentTask() |     setCurrentTask() | ||||||
|     updateUiTaskList() |     updateUiTaskList() | ||||||
|  |     saveState() | ||||||
| } | } | ||||||
|  |  | ||||||
| // 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. | ||||||
| @@ -117,10 +119,10 @@ async function checkTaskCompleted() { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Check only at specified interval |     // Check only at specified interval | ||||||
|     if (checkCounter <= $('#objective-check-frequency').val()){ |     if (checkCounter >= 0){ | ||||||
|         return |         return | ||||||
|     } |     } | ||||||
|     checkCounter = 0 |     checkCounter = $('#objective-check-frequency').val() | ||||||
|  |  | ||||||
|     const prompt = substituteParams(objectivePrompts["checkTaskCompleted"].replace(/{{task}}/gi, currentTask.description)); |     const prompt = substituteParams(objectivePrompts["checkTaskCompleted"].replace(/{{task}}/gi, currentTask.description)); | ||||||
|     const taskResponse = (await generateQuietPrompt(prompt)).toLowerCase() |     const taskResponse = (await generateQuietPrompt(prompt)).toLowerCase() | ||||||
| @@ -132,7 +134,7 @@ async function checkTaskCompleted() { | |||||||
|     } else if (!(taskResponse.includes("false"))) { |     } else if (!(taskResponse.includes("false"))) { | ||||||
|         console.warn(`checkTaskCompleted response did not contain true or false. taskResponse: ${taskResponse}`) |         console.warn(`checkTaskCompleted response did not contain true or false. taskResponse: ${taskResponse}`) | ||||||
|     } else { |     } else { | ||||||
|         console.debug(`taskResponse: ${taskResponse}`) |         console.debug(`Checked task completion. taskResponse: ${taskResponse}`) | ||||||
|     } |     } | ||||||
|  } |  } | ||||||
|  |  | ||||||
| @@ -159,6 +161,7 @@ function setCurrentTask(index=null) { | |||||||
|         context.setExtensionPrompt(MODULE_NAME,'') |         context.setExtensionPrompt(MODULE_NAME,'') | ||||||
|         console.info(`No current task`) |         console.info(`No current task`) | ||||||
|     } |     } | ||||||
|  |     saveState() | ||||||
| } | } | ||||||
|  |  | ||||||
| //###############################// | //###############################// | ||||||
| @@ -175,23 +178,29 @@ const defaultSettings = { | |||||||
|  |  | ||||||
| // Convenient single call | // Convenient single call | ||||||
| function resetState(){ | function resetState(){ | ||||||
|     checkCounter = 0 |  | ||||||
|     loadSettings(); |     loadSettings(); | ||||||
| } | } | ||||||
|  |  | ||||||
| function debugObjectiveFunction(){ | function saveState(){ | ||||||
|     console.log({ |     extension_settings.objective[currentChatId].objective = globalObjective | ||||||
|         "globalObjective": globalObjective, |     extension_settings.objective[currentChatId].tasks = globalTasks | ||||||
|         "globalTasks": globalTasks, |     extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val() | ||||||
|         "currentChatId": currentChatId, |     extension_settings.objective[currentChatId].chatDepth = $('#objective-chat-depth').val() | ||||||
|         "currentTask": currentTask, |     saveSettingsDebounced() | ||||||
|         "checkCounter": checkCounter, |  | ||||||
|         "currentChatId": currentChatId, |  | ||||||
|         "extension_settings": extension_settings.objective[currentChatId], |  | ||||||
|     }) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| window.debugObjectiveFunction = debugObjectiveFunction | function debugObjectiveExtension(){ | ||||||
|  |     console.log(JSON.stringify({ | ||||||
|  |         "currentTask": currentTask, | ||||||
|  |         "currentChatId": currentChatId, | ||||||
|  |         "checkCounter": checkCounter, | ||||||
|  |         "globalObjective": globalObjective, | ||||||
|  |         "globalTasks": globalTasks, | ||||||
|  |         "extension_settings": extension_settings.objective[currentChatId], | ||||||
|  |     }, null, 2)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | window.debugObjectiveExtension = debugObjectiveExtension | ||||||
|  |  | ||||||
| // Create user-friendly task string | // Create user-friendly task string | ||||||
| function updateUiTaskList() { | function updateUiTaskList() { | ||||||
| @@ -215,9 +224,7 @@ function updateUiTaskList() { | |||||||
| async function onGenerateObjectiveClick() { | async function onGenerateObjectiveClick() { | ||||||
|     globalObjective = $('#objective-text').val() |     globalObjective = $('#objective-text').val() | ||||||
|     await generateTasks() |     await generateTasks() | ||||||
|     extension_settings.objective[currentChatId].objective = globalObjective |     saveState() | ||||||
|     extension_settings.objective[currentChatId].tasks = globalTasks |  | ||||||
|     saveSettingsDebounced() |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Update extension prompts | // Update extension prompts | ||||||
| @@ -225,17 +232,15 @@ function onChatDepthInput() { | |||||||
|     if (currentChatId == ""){ |     if (currentChatId == ""){ | ||||||
|         currentChatId = getContext().chatId |         currentChatId = getContext().chatId | ||||||
|     } |     } | ||||||
|     extension_settings.objective[currentChatId].chatDepth = $('#objective-chat-depth').val() |     saveState() | ||||||
|     setCurrentTask() // Ensure extension prompt is updated |     setCurrentTask() // Ensure extension prompt is updated | ||||||
|     saveSettingsDebounced() |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function onCheckFrequencyInput() { | function onCheckFrequencyInput() { | ||||||
|     if (currentChatId == ""){ |     if (currentChatId == ""){ | ||||||
|         currentChatId = getContext().chatId |         currentChatId = getContext().chatId | ||||||
|     } |     } | ||||||
|     extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val() |     saveState() | ||||||
|     saveSettingsDebounced() |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function loadSettings() { | function loadSettings() { | ||||||
| @@ -254,12 +259,15 @@ function loadSettings() { | |||||||
|     // Update globals |     // Update globals | ||||||
|     globalObjective = extension_settings.objective[currentChatId].objective |     globalObjective = extension_settings.objective[currentChatId].objective | ||||||
|     globalTasks = extension_settings.objective[currentChatId].tasks |     globalTasks = extension_settings.objective[currentChatId].tasks | ||||||
|  |     checkCounter = extension_settings.objective[currentChatId].checkFrequency | ||||||
|  |  | ||||||
|     // Update UI elements |     // Update UI elements | ||||||
|  |     $('#objective-counter').text(checkCounter) | ||||||
|     $("#objective-text").text(globalObjective) |     $("#objective-text").text(globalObjective) | ||||||
|     updateUiTaskList() |     updateUiTaskList() | ||||||
|     $('#objective-chat-depth').val(extension_settings.objective[currentChatId].chatDepth) |     $('#objective-chat-depth').val(extension_settings.objective[currentChatId].chatDepth) | ||||||
|     $('#objective-check-frequency').val(extension_settings.objective[currentChatId].checkFrequency) |     $('#objective-check-frequency').val(extension_settings.objective[currentChatId].checkFrequency) | ||||||
|  |     setCurrentTask() | ||||||
| } | } | ||||||
|  |  | ||||||
| jQuery(() => { | jQuery(() => { | ||||||
| @@ -277,10 +285,10 @@ jQuery(() => { | |||||||
|             <label for="objective-tasks">Objective Tasks</label> |             <label for="objective-tasks">Objective Tasks</label> | ||||||
|             <textarea id="objective-tasks" class="text_pole" rows="8" placeholder="Objective tasks will be generated here..."></textarea> |             <textarea id="objective-tasks" class="text_pole" rows="8" placeholder="Objective tasks will be generated here..."></textarea> | ||||||
|             <label for="objective-chat-depth">In-chat @ Depth</label> |             <label for="objective-chat-depth">In-chat @ Depth</label> | ||||||
|             <input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" /> |             <input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" /><br> | ||||||
|             <label for="objective-check-frequency">Task Check Frequency</label> |             <label for="objective-check-frequency">Task Check Frequency</label>  | ||||||
|             <input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="1" max="99" /> |             <input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="1" max="99" /><br> | ||||||
|              |             <span> Messages until next task completion check <span id="objective-counter">0</span></span> | ||||||
|         </div> |         </div> | ||||||
|     </div>`; |     </div>`; | ||||||
|      |      | ||||||
| @@ -296,7 +304,8 @@ jQuery(() => { | |||||||
|  |  | ||||||
|     eventSource.on(event_types.MESSAGE_RECEIVED, () => { |     eventSource.on(event_types.MESSAGE_RECEIVED, () => { | ||||||
|         checkTaskCompleted(); |         checkTaskCompleted(); | ||||||
|         checkCounter += 1 |         checkCounter -= 1 | ||||||
|         setCurrentTask(); |         setCurrentTask(); | ||||||
|  |         $('#objective-counter').text(checkCounter) | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -0,0 +1,4 @@ | |||||||
|  | #objective-counter { | ||||||
|  |     font-weight: 600; | ||||||
|  |     color: orange; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user