mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' of http://github.com/cohee1207/SillyTavern into staging
This commit is contained in:
18
public/NovelAI Settings/Asper-Kayra.settings
Normal file
18
public/NovelAI Settings/Asper-Kayra.settings
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"order": [5, 0, 1, 3],
|
||||||
|
"temperature": 1.23,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 200,
|
||||||
|
"typical_p": 0.966,
|
||||||
|
"tail_free_sampling": 0.982,
|
||||||
|
"repetition_penalty": 1.74,
|
||||||
|
"repetition_penalty_range": 4000,
|
||||||
|
"repetition_penalty_frequency": 0,
|
||||||
|
"repetition_penalty_presence": 0.02,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "aggressive",
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
19
public/NovelAI Settings/Blended-Coffee-Kayra.settings
Normal file
19
public/NovelAI Settings/Blended-Coffee-Kayra.settings
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 0, 1, 2, 3],
|
||||||
|
"temperature": 1,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 25,
|
||||||
|
"top_p": 1,
|
||||||
|
"tail_free_sampling": 0.925,
|
||||||
|
"repetition_penalty": 1.6,
|
||||||
|
"repetition_penalty_frequency": 0.001,
|
||||||
|
"repetition_penalty_range": 0,
|
||||||
|
"repetition_penalty_presence": 0,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "medium",
|
||||||
|
"cfg_scale": 1.55,
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
20
public/NovelAI Settings/Blook-Kayra.settings
Normal file
20
public/NovelAI Settings/Blook-Kayra.settings
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 2, 3, 1, 0],
|
||||||
|
"temperature": 1,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 0,
|
||||||
|
"top_p": 0.96,
|
||||||
|
"tail_free_sampling": 0.96,
|
||||||
|
"repetition_penalty": 2,
|
||||||
|
"repetition_penalty_slope": 1,
|
||||||
|
"repetition_penalty_frequency": 0.02,
|
||||||
|
"repetition_penalty_range": 0,
|
||||||
|
"repetition_penalty_presence": 0.3,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "very_aggressive",
|
||||||
|
"cfg_scale": 1.3,
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"order": [2, 3, 0, 4, 1],
|
"order": [2, 3, 0, 4, 1],
|
||||||
"temperature": 1.05,
|
"temperature": 1.35,
|
||||||
"max_length": 300,
|
"max_length": 300,
|
||||||
"min_length": 1,
|
"min_length": 1,
|
||||||
"top_k": 12,
|
"top_k": 12,
|
||||||
"top_p": 0.85,
|
"top_p": 0.85,
|
||||||
"top_a": 0.1,
|
"top_a": 0.1,
|
||||||
"typical_p": 1,
|
|
||||||
"tail_free_sampling": 0.915,
|
"tail_free_sampling": 0.915,
|
||||||
"repetition_penalty": 2.8,
|
"repetition_penalty": 2.8,
|
||||||
"repetition_penalty_range": 2048,
|
"repetition_penalty_range": 2048,
|
||||||
"repetition_penalty_slope": 0.02,
|
"repetition_penalty_slope": 0.02,
|
||||||
"repetition_penalty_frequency": 0.03,
|
"repetition_penalty_frequency": 0.02,
|
||||||
"repetition_penalty_presence": 0.0,
|
"repetition_penalty_presence": 0,
|
||||||
"use_cache": false,
|
"use_cache": false,
|
||||||
"return_full_text": false,
|
"return_full_text": false,
|
||||||
"prefix": "vanilla",
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "aggressive",
|
||||||
"max_context": 8192
|
"max_context": 8192
|
||||||
}
|
}
|
||||||
|
20
public/NovelAI Settings/Edgewise-Clio.settings
Normal file
20
public/NovelAI Settings/Edgewise-Clio.settings
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"order": [4, 0, 5, 3, 2],
|
||||||
|
"temperature": 1.09,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_p": 0.969,
|
||||||
|
"top_a": 0.09,
|
||||||
|
"typical_p": 0.99,
|
||||||
|
"tail_free_sampling": 0.969,
|
||||||
|
"repetition_penalty": 1.09,
|
||||||
|
"repetition_penalty_range": 8192,
|
||||||
|
"repetition_penalty_slope": 0.069,
|
||||||
|
"repetition_penalty_frequency": 0.006,
|
||||||
|
"repetition_penalty_presence": 0.009,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "very_light",
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
19
public/NovelAI Settings/Fresh-Coffee-Kayra.settings
Normal file
19
public/NovelAI Settings/Fresh-Coffee-Kayra.settings
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 0, 1, 2, 3],
|
||||||
|
"temperature": 1,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 25,
|
||||||
|
"top_p": 1,
|
||||||
|
"tail_free_sampling": 0.925,
|
||||||
|
"repetition_penalty": 1.9,
|
||||||
|
"repetition_penalty_range": 768,
|
||||||
|
"repetition_penalty_slope": 1,
|
||||||
|
"repetition_penalty_frequency": 0.0025,
|
||||||
|
"repetition_penalty_presence": 0.001,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "off",
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
19
public/NovelAI Settings/Green-Active-Writer-Kayra.settings
Normal file
19
public/NovelAI Settings/Green-Active-Writer-Kayra.settings
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 1, 0, 5, 3],
|
||||||
|
"temperature": 1.25,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 70,
|
||||||
|
"typical_p": 0.9,
|
||||||
|
"tail_free_sampling": 0.925,
|
||||||
|
"repetition_penalty": 2,
|
||||||
|
"repetition_penalty_range": 1632,
|
||||||
|
"repetition_penalty_frequency": 0,
|
||||||
|
"repetition_penalty_presence": 0,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "aggressive",
|
||||||
|
"cfg_scale": 1.825,
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
22
public/NovelAI Settings/Pilotfish-Kayra.settings
Normal file
22
public/NovelAI Settings/Pilotfish-Kayra.settings
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 0, 4, 1, 2, 5, 3],
|
||||||
|
"temperature": 1.31,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 25,
|
||||||
|
"top_p": 0.97,
|
||||||
|
"top_a": 0.18,
|
||||||
|
"typical_p": 0.98,
|
||||||
|
"tail_free_sampling": 1,
|
||||||
|
"repetition_penalty": 1.55,
|
||||||
|
"repetition_penalty_frequency": 0.00075,
|
||||||
|
"repetition_penalty_presence": 0.00085,
|
||||||
|
"repetition_penalty_range": 8192,
|
||||||
|
"repetition_penalty_slope": 1.8,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "medium",
|
||||||
|
"cfg_scale": 1.35,
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
17
public/NovelAI Settings/Stelenes-Kayra.settings
Normal file
17
public/NovelAI Settings/Stelenes-Kayra.settings
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"order": [3, 0, 5],
|
||||||
|
"temperature": 2.5,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"typical_p": 0.966,
|
||||||
|
"tail_free_sampling": 0.933,
|
||||||
|
"repetition_penalty": 1,
|
||||||
|
"repetition_penalty_range": 2048,
|
||||||
|
"repetition_penalty_frequency": 0,
|
||||||
|
"repetition_penalty_presence": 0,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "aggressive",
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
@@ -1,20 +1,21 @@
|
|||||||
{
|
{
|
||||||
"order": [1, 3, 4, 0, 2],
|
"order": [1, 5, 0, 2, 3, 4],
|
||||||
"temperature": 1.05,
|
"temperature": 1.5,
|
||||||
"max_length": 40,
|
"max_length": 300,
|
||||||
"min_length": 1,
|
"min_length": 1,
|
||||||
"top_k": 79,
|
"top_k": 10,
|
||||||
"top_p": 0.95,
|
"top_p": 0.75,
|
||||||
"top_a": 0.075,
|
"top_a": 0.08,
|
||||||
"typical_p": 1,
|
"typical_p": 0.975,
|
||||||
"tail_free_sampling": 0.989,
|
"tail_free_sampling": 0.967,
|
||||||
"repetition_penalty": 1.5,
|
"repetition_penalty": 2.25,
|
||||||
"repetition_penalty_range": 8192,
|
"repetition_penalty_range": 8192,
|
||||||
"repetition_penalty_slope": 3.33,
|
"repetition_penalty_slope": 0.09,
|
||||||
"repetition_penalty_frequency": 0.03,
|
"repetition_penalty_frequency": 0,
|
||||||
"repetition_penalty_presence": 0.005,
|
"repetition_penalty_presence": 0.005,
|
||||||
"use_cache": false,
|
"use_cache": false,
|
||||||
"return_full_text": false,
|
"return_full_text": false,
|
||||||
"prefix": "vanilla",
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "very_light",
|
||||||
"max_context": 8192
|
"max_context": 8192
|
||||||
}
|
}
|
||||||
|
18
public/NovelAI Settings/Tesseract-Kayra.settings
Normal file
18
public/NovelAI Settings/Tesseract-Kayra.settings
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 0, 5],
|
||||||
|
"temperature": 0.895,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"typical_p": 0.9,
|
||||||
|
"repetition_penalty": 2,
|
||||||
|
"repetition_penalty_slope": 3.2,
|
||||||
|
"repetition_penalty_frequency": 0,
|
||||||
|
"repetition_penalty_presence": 0,
|
||||||
|
"repetition_penalty_range": 4048,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "aggressive",
|
||||||
|
"cfg_scale": 1.3,
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
19
public/NovelAI Settings/Writers-Daemon-Kayra.settings
Normal file
19
public/NovelAI Settings/Writers-Daemon-Kayra.settings
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"order": [6, 1, 0, 5, 3, 2],
|
||||||
|
"temperature": 1.5,
|
||||||
|
"max_length": 300,
|
||||||
|
"min_length": 1,
|
||||||
|
"top_k": 70,
|
||||||
|
"top_p": 0.95,
|
||||||
|
"typical_p": 0.95,
|
||||||
|
"tail_free_sampling": 0.95,
|
||||||
|
"repetition_penalty": 1.6,
|
||||||
|
"repetition_penalty_range": 2016,
|
||||||
|
"repetition_penalty_frequency": 0,
|
||||||
|
"repetition_penalty_presence": 0,
|
||||||
|
"use_cache": false,
|
||||||
|
"return_full_text": false,
|
||||||
|
"prefix": "vanilla",
|
||||||
|
"phrase_rep_pen": "very_aggressive",
|
||||||
|
"max_context": 8192
|
||||||
|
}
|
@@ -867,6 +867,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="range-block">
|
||||||
|
<div class="range-block-title" data-i18n="CFG Scale">
|
||||||
|
CFG Scale
|
||||||
|
</div>
|
||||||
|
<div class="range-block-range-and-counter">
|
||||||
|
<div class="range-block-range">
|
||||||
|
<input type="range" id="cfg_scale_novel" name="volume" min="1" max="3" step="0.05">
|
||||||
|
</div>
|
||||||
|
<div class="range-block-counter">
|
||||||
|
<div contenteditable="true" data-for="cfg_scale_novel" id="cfg_scale_counter_novel">
|
||||||
|
select
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="range-block">
|
||||||
|
<div class="range-block-title" data-i18n="Phrase Repetition Penalty">
|
||||||
|
Phrase Repetition Penalty
|
||||||
|
</div>
|
||||||
|
<div class="range-block-range-and-counter">
|
||||||
|
<div class="range-block-range">
|
||||||
|
<input type="range" id="phrase_rep_pen_novel" name="volume" min="0" max="5" step="1">
|
||||||
|
</div>
|
||||||
|
<div class="range-block-counter">
|
||||||
|
<div contenteditable="true" data-for="phrase_rep_pen_novel" id="phrase_rep_pen_counter_novel">
|
||||||
|
select
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="range-block">
|
<div class="range-block">
|
||||||
<div class="range-block-title" data-i18n="Min Length">
|
<div class="range-block-title" data-i18n="Min Length">
|
||||||
Min Length
|
Min Length
|
||||||
|
@@ -239,7 +239,6 @@ $("#rm_ch_create_block").on("input", function () { countTokensDebounced(); });
|
|||||||
$("#character_popup").on("input", function () { countTokensDebounced(); });
|
$("#character_popup").on("input", function () { countTokensDebounced(); });
|
||||||
//function:
|
//function:
|
||||||
export function RA_CountCharTokens() {
|
export function RA_CountCharTokens() {
|
||||||
$("#result_info").html("");
|
|
||||||
//console.log('RA_TC -- starting with this_chid = ' + this_chid);
|
//console.log('RA_TC -- starting with this_chid = ' + this_chid);
|
||||||
if (menu_type === "create") { //if new char
|
if (menu_type === "create") { //if new char
|
||||||
function saveFormVariables() {
|
function saveFormVariables() {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { chat_metadata, callPopup, saveSettingsDebounced } from "../../../script.js";
|
import { chat_metadata, callPopup, saveSettingsDebounced, getCurrentChatId } from "../../../script.js";
|
||||||
import { getContext, extension_settings, saveMetadataDebounced } from "../../extensions.js";
|
import { getContext, extension_settings, saveMetadataDebounced } from "../../extensions.js";
|
||||||
import {
|
import {
|
||||||
substituteParams,
|
substituteParams,
|
||||||
@@ -11,9 +11,10 @@ import { registerSlashCommand } from "../../slash-commands.js";
|
|||||||
const MODULE_NAME = "Objective"
|
const MODULE_NAME = "Objective"
|
||||||
|
|
||||||
|
|
||||||
let globalObjective = ""
|
let taskTree = null
|
||||||
let globalTasks = []
|
let globalTasks = []
|
||||||
let currentChatId = ""
|
let currentChatId = ""
|
||||||
|
let currentObjective = null
|
||||||
let currentTask = null
|
let currentTask = null
|
||||||
let checkCounter = 0
|
let checkCounter = 0
|
||||||
|
|
||||||
@@ -47,56 +48,48 @@ let objectivePrompts = defaultPrompts
|
|||||||
//# Task Management #//
|
//# Task Management #//
|
||||||
//###############################//
|
//###############################//
|
||||||
|
|
||||||
// Accepts optional index. Defaults to adding to end of list.
|
|
||||||
function addTask(description, index = null) {
|
|
||||||
index = index != null ? index: index = globalTasks.length
|
|
||||||
globalTasks.splice(index, 0, new ObjectiveTask(
|
|
||||||
{description: description}
|
|
||||||
))
|
|
||||||
saveState()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the task and index or throw an error
|
// Return the task and index or throw an error
|
||||||
function getTaskById(taskId){
|
function getTaskById(taskId){
|
||||||
if (taskId == null) {
|
if (taskId == null) {
|
||||||
throw `Null task id`
|
throw `Null task id`
|
||||||
}
|
}
|
||||||
const index = globalTasks.findIndex((task) => task.id === taskId);
|
return getTaskByIdRecurse(taskId, taskTree)
|
||||||
if (index !== -1) {
|
|
||||||
return { task: globalTasks[index], index: index };
|
|
||||||
} else {
|
|
||||||
throw `Cannot find task with ${taskId}`
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTask(taskId){
|
function getTaskByIdRecurse(taskId, task) {
|
||||||
const { task, index } = getTaskById(taskId)
|
if (task.id == taskId){
|
||||||
|
return task
|
||||||
globalTasks.splice(index, 1)
|
}
|
||||||
setCurrentTask()
|
for (const childTask of task.children) {
|
||||||
updateUiTaskList()
|
const foundTask = getTaskByIdRecurse(taskId, childTask);
|
||||||
|
if (foundTask != null) {
|
||||||
|
return foundTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, globalObjective));
|
|
||||||
|
const prompt = substituteParams(objectivePrompts.createTask.replace(/{{objective}}/gi, currentObjective.description));
|
||||||
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)
|
||||||
|
|
||||||
// Clear all existing global tasks when generating
|
// Clear all existing objective tasks when generating
|
||||||
globalTasks = []
|
currentObjective.children = []
|
||||||
const numberedListPattern = /^\d+\./
|
const numberedListPattern = /^\d+\./
|
||||||
|
|
||||||
// Create tasks from generated task list
|
// Create tasks from generated task list
|
||||||
for (const task of taskResponse.split('\n').map(x => x.trim())) {
|
for (const task of taskResponse.split('\n').map(x => x.trim())) {
|
||||||
if (task.match(numberedListPattern) != null) {
|
if (task.match(numberedListPattern) != null) {
|
||||||
addTask(task.replace(numberedListPattern,"").trim())
|
currentObjective.addTask(task.replace(numberedListPattern,"").trim())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateUiTaskList()
|
updateUiTaskList();
|
||||||
console.info(`Response for Objective: '${globalObjective}' was \n'${taskResponse}', \nwhich created tasks \n${JSON.stringify(globalTasks.map(v => {return v.toSaveState()}), null, 2)} `)
|
setCurrentTask();
|
||||||
|
console.info(`Response for Objective: '${taskTree.description}' was \n'${taskResponse}', \nwhich created tasks \n${JSON.stringify(globalTasks.map(v => {return v.toSaveState()}), null, 2)} `)
|
||||||
toastr.success(`Generated ${globalTasks.length} tasks`, 'Done!');
|
toastr.success(`Generated ${globalTasks.length} tasks`, 'Done!');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +106,7 @@ async function checkTaskCompleted() {
|
|||||||
|
|
||||||
// Check response if task complete
|
// Check response if task complete
|
||||||
if (taskResponse.includes("true")) {
|
if (taskResponse.includes("true")) {
|
||||||
console.info(`Character determined task '${JSON.stringify(currentTask.toSaveState())} is completed.`)
|
console.info(`Character determined task '${currentTask.description} is completed.`)
|
||||||
currentTask.completeTask()
|
currentTask.completeTask()
|
||||||
} 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}`)
|
||||||
@@ -122,29 +115,56 @@ async function checkTaskCompleted() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNextIncompleteTaskRecurse(task){
|
||||||
|
// Skip tasks with children, as they will have subtasks to determine completeness
|
||||||
|
if (task.completed === false && task.children.length === 0){
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
for (const childTask of task.children) {
|
||||||
|
if (childTask.completed === true){ // Don't recurse into completed tasks
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const foundTask = getNextIncompleteTaskRecurse(childTask);
|
||||||
|
if (foundTask != null) {
|
||||||
|
return foundTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Set a task in extensionPrompt context. Defaults to first incomplete
|
// Set a task in extensionPrompt context. Defaults to first incomplete
|
||||||
function setCurrentTask(taskId = null) {
|
function setCurrentTask(taskId = null) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
|
|
||||||
|
// TODO: Should probably null this rather than set empty object
|
||||||
currentTask = {};
|
currentTask = {};
|
||||||
|
|
||||||
// Set current task to either the next incomplete task, or the index
|
// Find the task, either next incomplete, or by provided taskId
|
||||||
if (taskId === null) {
|
if (taskId === null) {
|
||||||
currentTask = globalTasks.find(task => !task.completed) || {};
|
currentTask = getNextIncompleteTaskRecurse(taskTree) || {};
|
||||||
} else {
|
} else {
|
||||||
const { _, index } = getTaskById(taskId)
|
currentTask = getTaskById(taskId);
|
||||||
currentTask = globalTasks[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the task description and add to extension prompt
|
// Don't just check for a current task, check if it has data
|
||||||
const description = currentTask.description || null;
|
const description = currentTask.description || null;
|
||||||
|
|
||||||
// Now update the extension prompt
|
|
||||||
|
|
||||||
if (description) {
|
if (description) {
|
||||||
const extensionPromptText = objectivePrompts.currentTask.replace(/{{task}}/gi, description);
|
const extensionPromptText = objectivePrompts.currentTask.replace(/{{task}}/gi, description);
|
||||||
$('.objective-task').css({'border-color':'','border-width':''}) // Clear highlights
|
|
||||||
currentTask.descriptionSpan.css({'border-color':'yellow','border-width':'2px'}); // Highlight current task
|
// Remove highlights
|
||||||
|
$('.objective-task').css({'border-color':'','border-width':''})
|
||||||
|
// Highlight current task
|
||||||
|
let highlightTask = currentTask
|
||||||
|
while (highlightTask.parentId !== ""){
|
||||||
|
if (highlightTask.descriptionSpan){
|
||||||
|
highlightTask.descriptionSpan.css({'border-color':'yellow','border-width':'2px'});
|
||||||
|
}
|
||||||
|
const parent = getTaskById(highlightTask.parentId)
|
||||||
|
highlightTask = parent
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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)}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -155,22 +175,26 @@ function setCurrentTask(taskId = null) {
|
|||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
let taskIdCounter = 0
|
function getHighestTaskIdRecurse(task) {
|
||||||
function getNextTaskId(){
|
let nextId = task.id;
|
||||||
// Make sure id does not exist
|
|
||||||
while (globalTasks.find(task => task.id == taskIdCounter) != undefined) {
|
for (const childTask of task.children) {
|
||||||
taskIdCounter += 1
|
const childId = getHighestTaskIdRecurse(childTask);
|
||||||
|
if (childId > nextId) {
|
||||||
|
nextId = childId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const nextId = taskIdCounter
|
return nextId;
|
||||||
console.log(`TaskID assigned: ${nextId}`)
|
|
||||||
taskIdCounter += 1
|
|
||||||
return nextId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//###############################//
|
||||||
|
//# Task Class #//
|
||||||
|
//###############################//
|
||||||
class ObjectiveTask {
|
class ObjectiveTask {
|
||||||
id
|
id
|
||||||
description
|
description
|
||||||
completed
|
completed
|
||||||
parent
|
parentId
|
||||||
children
|
children
|
||||||
|
|
||||||
// UI Elements
|
// UI Elements
|
||||||
@@ -180,25 +204,67 @@ class ObjectiveTask {
|
|||||||
deleteTaskButton
|
deleteTaskButton
|
||||||
addTaskButton
|
addTaskButton
|
||||||
|
|
||||||
constructor ({id=undefined, description, completed=false, parent=null}) {
|
constructor ({id=undefined, description, completed=false, parentId=""}) {
|
||||||
this.description = description
|
this.description = description
|
||||||
this.parent = parent
|
this.parentId = parentId
|
||||||
this.children = []
|
this.children = []
|
||||||
this.completed = completed
|
this.completed = completed
|
||||||
|
|
||||||
// Generate a new ID if none specified
|
// Generate a new ID if none specified
|
||||||
if (id==undefined){
|
if (id==undefined){
|
||||||
this.id = getNextTaskId()
|
this.id = getHighestTaskIdRecurse(taskTree) + 1
|
||||||
} else {
|
} else {
|
||||||
this.id=id
|
this.id=id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Accepts optional index. Defaults to adding to end of list.
|
||||||
|
addTask(description, index = null) {
|
||||||
|
index = index != null ? index: index = this.children.length
|
||||||
|
this.children.splice(index, 0, new ObjectiveTask(
|
||||||
|
{description: description, parentId: this.id}
|
||||||
|
))
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
|
getIndex(){
|
||||||
|
if (this.parentId !== null) {
|
||||||
|
const parent = getTaskById(this.parentId)
|
||||||
|
const index = parent.children.findIndex(task => task.id === this.id)
|
||||||
|
if (index === -1){
|
||||||
|
throw `getIndex failed: Task '${this.description}' not found in parent task '${parent.description}'`
|
||||||
|
}
|
||||||
|
return index
|
||||||
|
} else {
|
||||||
|
throw `getIndex failed: Task '${this.description}' has no parent`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to set parent to complete when all child tasks are completed
|
||||||
|
checkParentComplete() {
|
||||||
|
let all_completed = true;
|
||||||
|
if (this.parentId !== ""){
|
||||||
|
const parent = getTaskById(this.parentId);
|
||||||
|
for (const child of parent.children){
|
||||||
|
if (!child.completed){
|
||||||
|
all_completed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (all_completed){
|
||||||
|
parent.completed = true;
|
||||||
|
console.info(`Parent task '${parent.description}' completed after all child tasks complated.`)
|
||||||
|
} else {
|
||||||
|
parent.completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Complete the current task, setting next task to next incomplete task
|
// Complete the current task, setting next task to next incomplete task
|
||||||
completeTask() {
|
completeTask() {
|
||||||
this.completed = true
|
this.completed = true
|
||||||
console.info(`Task successfully completed: ${JSON.stringify(this.description)}`)
|
console.info(`Task successfully completed: ${JSON.stringify(this.description)}`)
|
||||||
|
this.checkParentComplete()
|
||||||
setCurrentTask()
|
setCurrentTask()
|
||||||
updateUiTaskList()
|
updateUiTaskList()
|
||||||
}
|
}
|
||||||
@@ -211,6 +277,7 @@ class ObjectiveTask {
|
|||||||
<span class="text_pole objective-task" style="display: block" id="objective-task-description-${this.id}" contenteditable>${this.description}</span>
|
<span class="text_pole objective-task" style="display: block" id="objective-task-description-${this.id}" contenteditable>${this.description}</span>
|
||||||
<div id="objective-task-delete-${this.id}" class="objective-task-button fa-solid fa-xmark fa-2x" title="Delete Task"></div>
|
<div id="objective-task-delete-${this.id}" class="objective-task-button fa-solid fa-xmark fa-2x" title="Delete Task"></div>
|
||||||
<div id="objective-task-add-${this.id}" class="objective-task-button fa-solid fa-plus fa-2x" title="Add Task"></div>
|
<div id="objective-task-add-${this.id}" class="objective-task-button fa-solid fa-plus fa-2x" title="Add Task"></div>
|
||||||
|
<div id="objective-task-add-branch-${this.id}" class="objective-task-button fa-solid fa-code-fork fa-2x" title="Branch Task"></div>
|
||||||
</div><br>
|
</div><br>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -221,6 +288,15 @@ class ObjectiveTask {
|
|||||||
this.descriptionSpan = $(`#objective-task-description-${this.id}`);
|
this.descriptionSpan = $(`#objective-task-description-${this.id}`);
|
||||||
this.addButton = $(`#objective-task-add-${this.id}`);
|
this.addButton = $(`#objective-task-add-${this.id}`);
|
||||||
this.deleteButton = $(`#objective-task-delete-${this.id}`);
|
this.deleteButton = $(`#objective-task-delete-${this.id}`);
|
||||||
|
this.taskHtml = $(`#objective-task-label-${this.id}`);
|
||||||
|
this.branchButton = $(`#objective-task-add-branch-${this.id}`)
|
||||||
|
|
||||||
|
// Handle sub-task forking style
|
||||||
|
if (this.children.length > 0){
|
||||||
|
this.branchButton.css({'color':'#33cc33'})
|
||||||
|
} else {
|
||||||
|
this.branchButton.css({'color':''})
|
||||||
|
}
|
||||||
|
|
||||||
// Add event listeners and set properties
|
// Add event listeners and set properties
|
||||||
$(`#objective-task-complete-${this.id}`).prop('checked', this.completed);
|
$(`#objective-task-complete-${this.id}`).prop('checked', this.completed);
|
||||||
@@ -229,145 +305,66 @@ class ObjectiveTask {
|
|||||||
$(`#objective-task-description-${this.id}`).on('focusout', () => (this.onDescriptionFocusout()));
|
$(`#objective-task-description-${this.id}`).on('focusout', () => (this.onDescriptionFocusout()));
|
||||||
$(`#objective-task-delete-${this.id}`).on('click', () => (this.onDeleteClick()));
|
$(`#objective-task-delete-${this.id}`).on('click', () => (this.onDeleteClick()));
|
||||||
$(`#objective-task-add-${this.id}`).on('click', () => (this.onAddClick()));
|
$(`#objective-task-add-${this.id}`).on('click', () => (this.onAddClick()));
|
||||||
|
this.branchButton.on('click', () => (this.onBranchClick()))
|
||||||
|
}
|
||||||
|
|
||||||
|
onBranchClick() {
|
||||||
|
currentObjective = this
|
||||||
|
updateUiTaskList();
|
||||||
|
setCurrentTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
onCompleteClick(){
|
onCompleteClick(){
|
||||||
this.completed = this.completedCheckbox.prop('checked')
|
this.completed = this.completedCheckbox.prop('checked')
|
||||||
|
this.checkParentComplete()
|
||||||
setCurrentTask();
|
setCurrentTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
onDescriptionUpdate(){
|
onDescriptionUpdate(){
|
||||||
this.description = this.descriptionSpan.text();
|
this.description = this.descriptionSpan.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
onDescriptionFocusout(){
|
onDescriptionFocusout(){
|
||||||
setCurrentTask();
|
setCurrentTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeleteClick(){
|
onDeleteClick(){
|
||||||
deleteTask(this.id);
|
const index = this.getIndex()
|
||||||
|
const parent = getTaskById(this.parentId)
|
||||||
|
parent.children.splice(index, 1)
|
||||||
|
updateUiTaskList()
|
||||||
|
setCurrentTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddClick(){
|
onAddClick(){
|
||||||
const {_, index} = getTaskById(this.id)
|
const index = this.getIndex()
|
||||||
addTask("", index + 1);
|
const parent = getTaskById(this.parentId)
|
||||||
setCurrentTask();
|
parent.addTask("", index + 1);
|
||||||
updateUiTaskList();
|
updateUiTaskList();
|
||||||
|
setCurrentTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
toSaveState() {
|
toSaveStateRecurse() {
|
||||||
|
let children = []
|
||||||
|
if (this.children.length > 0){
|
||||||
|
for (const child of this.children){
|
||||||
|
children.push(child.toSaveStateRecurse())
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
"id":this.id,
|
"id":this.id,
|
||||||
"description":this.description,
|
"description":this.description,
|
||||||
"completed":this.completed,
|
"completed":this.completed,
|
||||||
"parent": this.parent,
|
"parentId": this.parentId,
|
||||||
|
"children": children,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//###############################//
|
//###############################//
|
||||||
//# UI AND Settings #//
|
//# Custom Prompts #//
|
||||||
//###############################//
|
//###############################//
|
||||||
|
|
||||||
|
|
||||||
const defaultSettings = {
|
|
||||||
objective: "",
|
|
||||||
tasks: [],
|
|
||||||
chatDepth: 2,
|
|
||||||
checkFrequency: 3,
|
|
||||||
hideTasks: false,
|
|
||||||
prompts: defaultPrompts,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convenient single call. Not much at the moment.
|
|
||||||
function resetState() {
|
|
||||||
loadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
function saveState() {
|
|
||||||
const context = getContext();
|
|
||||||
|
|
||||||
if (currentChatId == "") {
|
|
||||||
currentChatId = context.chatId
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert globalTasks for saving
|
|
||||||
const tasks = globalTasks.map(task => {return task.toSaveState()})
|
|
||||||
|
|
||||||
chat_metadata['objective'] = {
|
|
||||||
objective: globalObjective,
|
|
||||||
tasks: tasks,
|
|
||||||
checkFrequency: $('#objective-check-frequency').val(),
|
|
||||||
chatDepth: $('#objective-chat-depth').val(),
|
|
||||||
hideTasks: $('#objective-hide-tasks').prop('checked'),
|
|
||||||
prompts: objectivePrompts,
|
|
||||||
}
|
|
||||||
|
|
||||||
saveMetadataDebounced();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump core state
|
|
||||||
function debugObjectiveExtension() {
|
|
||||||
console.log(JSON.stringify({
|
|
||||||
"currentTask": currentTask.description,
|
|
||||||
"globalObjective": globalObjective,
|
|
||||||
"globalTasks": globalTasks.map(v => {return v.toSaveState()}),
|
|
||||||
"chat_metadata": chat_metadata['objective'],
|
|
||||||
"extension_settings": extension_settings['objective'],
|
|
||||||
"prompts": objectivePrompts
|
|
||||||
}, null, 2))
|
|
||||||
}
|
|
||||||
|
|
||||||
window.debugObjectiveExtension = debugObjectiveExtension
|
|
||||||
|
|
||||||
|
|
||||||
// Populate UI task list
|
|
||||||
function updateUiTaskList() {
|
|
||||||
$('#objective-tasks').empty()
|
|
||||||
// Show tasks if there are any
|
|
||||||
if (globalTasks.length > 0){
|
|
||||||
for (const task of globalTasks) {
|
|
||||||
task.addUiElement()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Show button to add tasks if there are none
|
|
||||||
$('#objective-tasks').append(`
|
|
||||||
<input id="objective-task-add-first" type="button" class="menu_button" value="Add Task">
|
|
||||||
`)
|
|
||||||
$("#objective-task-add-first").on('click', () => {
|
|
||||||
addTask("")
|
|
||||||
setCurrentTask()
|
|
||||||
updateUiTaskList()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Trigger creation of new tasks with given objective.
|
|
||||||
async function onGenerateObjectiveClick() {
|
|
||||||
globalObjective = $('#objective-text').val()
|
|
||||||
await generateTasks()
|
|
||||||
saveState()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update extension prompts
|
|
||||||
function onChatDepthInput() {
|
|
||||||
saveState()
|
|
||||||
setCurrentTask() // Ensure extension prompt is updated
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update how often we check for task completion
|
|
||||||
function onCheckFrequencyInput() {
|
|
||||||
checkCounter = $("#objective-check-frequency").val()
|
|
||||||
$('#objective-counter').text(checkCounter)
|
|
||||||
saveState()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onHideTasksInput() {
|
|
||||||
$('#objective-tasks').prop('hidden', $('#objective-hide-tasks').prop('checked'))
|
|
||||||
saveState()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onEditPromptClick() {
|
function onEditPromptClick() {
|
||||||
let popupText = ''
|
let popupText = ''
|
||||||
popupText += `
|
popupText += `
|
||||||
@@ -411,7 +408,7 @@ function onEditPromptClick() {
|
|||||||
|
|
||||||
// Handle save
|
// Handle save
|
||||||
$('#objective-custom-prompt-save').on('click', () => {
|
$('#objective-custom-prompt-save').on('click', () => {
|
||||||
addCustomPrompt($('#objective-custom-prompt-name').val(), objectivePrompts)
|
saveCustomPrompt($('#objective-custom-prompt-name').val(), objectivePrompts)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle delete
|
// Handle delete
|
||||||
@@ -424,7 +421,7 @@ function onEditPromptClick() {
|
|||||||
$('#objective-prompt-load').on('change', loadCustomPrompt)
|
$('#objective-prompt-load').on('change', loadCustomPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCustomPrompt(customPromptName, customPrompts) {
|
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
|
||||||
@@ -453,7 +450,7 @@ function deleteCustomPrompt(customPromptName){
|
|||||||
function loadCustomPrompt(){
|
function loadCustomPrompt(){
|
||||||
const optionSelected = $("#objective-prompt-load").find(':selected').val()
|
const optionSelected = $("#objective-prompt-load").find(':selected').val()
|
||||||
console.log(optionSelected)
|
console.log(optionSelected)
|
||||||
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)
|
||||||
$('#objective-prompt-check').val(objectivePrompts.checkTaskCompleted)
|
$('#objective-prompt-check').val(objectivePrompts.checkTaskCompleted)
|
||||||
@@ -472,10 +469,149 @@ function populateCustomPrompts(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//###############################//
|
||||||
|
//# UI AND Settings #//
|
||||||
|
//###############################//
|
||||||
|
|
||||||
|
|
||||||
|
const defaultSettings = {
|
||||||
|
currentObjectiveId: null,
|
||||||
|
taskTree: null,
|
||||||
|
chatDepth: 2,
|
||||||
|
checkFrequency: 3,
|
||||||
|
hideTasks: false,
|
||||||
|
prompts: defaultPrompts,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convenient single call. Not much at the moment.
|
||||||
|
function resetState() {
|
||||||
|
loadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
function saveState() {
|
||||||
|
const context = getContext();
|
||||||
|
|
||||||
|
if (currentChatId == "") {
|
||||||
|
currentChatId = context.chatId
|
||||||
|
}
|
||||||
|
|
||||||
|
chat_metadata['objective'] = {
|
||||||
|
currentObjectiveId: currentObjective.id,
|
||||||
|
taskTree: taskTree.toSaveStateRecurse(),
|
||||||
|
checkFrequency: $('#objective-check-frequency').val(),
|
||||||
|
chatDepth: $('#objective-chat-depth').val(),
|
||||||
|
hideTasks: $('#objective-hide-tasks').prop('checked'),
|
||||||
|
prompts: objectivePrompts,
|
||||||
|
}
|
||||||
|
|
||||||
|
saveMetadataDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump core state
|
||||||
|
function debugObjectiveExtension() {
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
"currentTask": currentTask,
|
||||||
|
"currentObjective": currentObjective,
|
||||||
|
"taskTree": taskTree.toSaveStateRecurse(),
|
||||||
|
"chat_metadata": chat_metadata['objective'],
|
||||||
|
"extension_settings": extension_settings['objective'],
|
||||||
|
"prompts": objectivePrompts
|
||||||
|
}, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
window.debugObjectiveExtension = debugObjectiveExtension
|
||||||
|
|
||||||
|
|
||||||
|
// Populate UI task list
|
||||||
|
function updateUiTaskList() {
|
||||||
|
$('#objective-tasks').empty()
|
||||||
|
|
||||||
|
// Show button to navigate back to parent objective if parent exists
|
||||||
|
if (currentObjective){
|
||||||
|
if (currentObjective.parentId !== "") {
|
||||||
|
$('#objective-parent').show()
|
||||||
|
} else {
|
||||||
|
$('#objective-parent').hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#objective-text').val(currentObjective.description)
|
||||||
|
if (currentObjective.children.length > 0){
|
||||||
|
// Show tasks if there are any to show
|
||||||
|
for (const task of currentObjective.children) {
|
||||||
|
task.addUiElement()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Show button to add tasks if there are none
|
||||||
|
$('#objective-tasks').append(`
|
||||||
|
<input id="objective-task-add-first" type="button" class="menu_button" value="Add Task">
|
||||||
|
`)
|
||||||
|
$("#objective-task-add-first").on('click', () => {
|
||||||
|
currentObjective.addTask("")
|
||||||
|
setCurrentTask()
|
||||||
|
updateUiTaskList()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onParentClick() {
|
||||||
|
currentObjective = getTaskById(currentObjective.parentId)
|
||||||
|
updateUiTaskList()
|
||||||
|
setCurrentTask()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger creation of new tasks with given objective.
|
||||||
|
async function onGenerateObjectiveClick() {
|
||||||
|
await generateTasks()
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update extension prompts
|
||||||
|
function onChatDepthInput() {
|
||||||
|
saveState()
|
||||||
|
setCurrentTask() // Ensure extension prompt is updated
|
||||||
|
}
|
||||||
|
|
||||||
|
function onObjectiveTextFocusOut(){
|
||||||
|
currentObjective.description = $('#objective-text').val()
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update how often we check for task completion
|
||||||
|
function onCheckFrequencyInput() {
|
||||||
|
checkCounter = $("#objective-check-frequency").val()
|
||||||
|
$('#objective-counter').text(checkCounter)
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onHideTasksInput() {
|
||||||
|
$('#objective-tasks').prop('hidden', $('#objective-hide-tasks').prop('checked'))
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadTaskChildrenRecurse(savedTask) {
|
||||||
|
let tempTaskTree = new ObjectiveTask({
|
||||||
|
id: savedTask.id,
|
||||||
|
description: savedTask.description,
|
||||||
|
completed: savedTask.completed,
|
||||||
|
parentId: savedTask.parentId,
|
||||||
|
})
|
||||||
|
for (const task of savedTask.children){
|
||||||
|
const childTask = loadTaskChildrenRecurse(task)
|
||||||
|
tempTaskTree.children.push(childTask)
|
||||||
|
}
|
||||||
|
return tempTaskTree
|
||||||
|
}
|
||||||
|
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
// Load/Init settings for chatId
|
// Load/Init settings for chatId
|
||||||
currentChatId = getContext().chatId
|
currentChatId = getContext().chatId
|
||||||
|
|
||||||
|
// Reset Objectives and Tasks in memory
|
||||||
|
taskTree = null;
|
||||||
|
currentObjective = null;
|
||||||
|
|
||||||
// Init extension settings
|
// Init extension settings
|
||||||
if (Object.keys(extension_settings.objective).length === 0) {
|
if (Object.keys(extension_settings.objective).length === 0) {
|
||||||
Object.assign(extension_settings.objective, { 'customPrompts': {'default':defaultPrompts}})
|
Object.assign(extension_settings.objective, { 'customPrompts': {'default':defaultPrompts}})
|
||||||
@@ -488,6 +624,7 @@ function loadSettings() {
|
|||||||
|
|
||||||
// Migrate existing settings
|
// Migrate existing settings
|
||||||
if (currentChatId in extension_settings.objective) {
|
if (currentChatId in extension_settings.objective) {
|
||||||
|
// TODO: Remove this soon
|
||||||
chat_metadata['objective'] = extension_settings.objective[currentChatId];
|
chat_metadata['objective'] = extension_settings.objective[currentChatId];
|
||||||
delete extension_settings.objective[currentChatId];
|
delete extension_settings.objective[currentChatId];
|
||||||
}
|
}
|
||||||
@@ -496,21 +633,47 @@ function loadSettings() {
|
|||||||
Object.assign(chat_metadata, { objective: defaultSettings });
|
Object.assign(chat_metadata, { objective: defaultSettings });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update globals
|
// Migrate legacy flat objective to new objectiveTree and currentObjective
|
||||||
globalObjective = chat_metadata['objective'].objective
|
if ('objective' in chat_metadata.objective) {
|
||||||
globalTasks = chat_metadata['objective'].tasks.map(task => {
|
|
||||||
return new ObjectiveTask({
|
// Create root objective from legacy objective
|
||||||
id: task.id,
|
taskTree = new ObjectiveTask({id:0, description: chat_metadata.objective.objective});
|
||||||
description: task.description,
|
currentObjective = taskTree;
|
||||||
completed: task.completed,
|
|
||||||
parent: task.parent,
|
// Populate root objective tree from legacy tasks
|
||||||
})
|
if ('tasks' in chat_metadata.objective) {
|
||||||
});
|
let idIncrement = 0;
|
||||||
|
taskTree.children = chat_metadata.objective.tasks.map(task => {
|
||||||
|
idIncrement += 1;
|
||||||
|
return new ObjectiveTask({
|
||||||
|
id: idIncrement,
|
||||||
|
description: task.description,
|
||||||
|
completed: task.completed,
|
||||||
|
parentId: taskTree.id,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
saveState();
|
||||||
|
delete chat_metadata.objective.objective;
|
||||||
|
delete chat_metadata.objective.tasks;
|
||||||
|
} else {
|
||||||
|
// Load Objectives and Tasks (Normal path)
|
||||||
|
if (chat_metadata.objective.taskTree){
|
||||||
|
taskTree = loadTaskChildrenRecurse(chat_metadata.objective.taskTree)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there's a root task
|
||||||
|
if (!taskTree) {
|
||||||
|
taskTree = new ObjectiveTask({id:0,description:$('#objective-text').val()})
|
||||||
|
}
|
||||||
|
|
||||||
|
currentObjective = taskTree
|
||||||
checkCounter = chat_metadata['objective'].checkFrequency
|
checkCounter = chat_metadata['objective'].checkFrequency
|
||||||
|
|
||||||
// Update UI elements
|
// Update UI elements
|
||||||
$('#objective-counter').text(checkCounter)
|
$('#objective-counter').text(checkCounter)
|
||||||
$("#objective-text").text(globalObjective)
|
$("#objective-text").text(taskTree.description)
|
||||||
updateUiTaskList()
|
updateUiTaskList()
|
||||||
$('#objective-chat-depth').val(chat_metadata['objective'].chatDepth)
|
$('#objective-chat-depth').val(chat_metadata['objective'].chatDepth)
|
||||||
$('#objective-check-frequency').val(chat_metadata['objective'].checkFrequency)
|
$('#objective-check-frequency').val(chat_metadata['objective'].checkFrequency)
|
||||||
@@ -533,38 +696,44 @@ jQuery(() => {
|
|||||||
<div class="objective-settings">
|
<div class="objective-settings">
|
||||||
<div class="inline-drawer">
|
<div class="inline-drawer">
|
||||||
<div class="inline-drawer-toggle inline-drawer-header">
|
<div class="inline-drawer-toggle inline-drawer-header">
|
||||||
<b>Objective</b>
|
<b>Objective</b>
|
||||||
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
||||||
</div>
|
|
||||||
<div class="inline-drawer-content">
|
|
||||||
<label for="objective-text"><small>Enter an objective and generate tasks. The AI will attempt to complete tasks autonomously</small></label>
|
|
||||||
<textarea id="objective-text" type="text" class="text_pole textarea_compact" rows="4"></textarea>
|
|
||||||
<div class="objective_block flex-container">
|
|
||||||
<input id="objective-generate" class="menu_button" type="submit" value="Auto-Generate Tasks" />
|
|
||||||
<label class="checkbox_label"><input id="objective-hide-tasks" type="checkbox"> Hide Tasks</label>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="inline-drawer-content">
|
||||||
<div id="objective-tasks"> </div>
|
<label for="objective-text"><small>Enter an objective and generate tasks. The AI will attempt to complete tasks autonomously</small></label>
|
||||||
<div class="objective_block margin-bot-10px">
|
<textarea id="objective-text" type="text" class="text_pole textarea_compact" rows="4"></textarea>
|
||||||
<div class="objective_block objective_block_control flex1 flexFlowColumn">
|
<div class="objective_block flex-container">
|
||||||
<label for="objective-chat-depth">Position in Chat</label>
|
<input id="objective-generate" class="menu_button" type="submit" value="Auto-Generate Tasks" />
|
||||||
<input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" />
|
<label class="checkbox_label"><input id="objective-hide-tasks" type="checkbox"> Hide Tasks</label>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<div id="objective-parent" class="objective_block flex-container">
|
||||||
<div class="objective_block objective_block_control flex1">
|
<i class="objective-task-button fa-solid fa-circle-left fa-2x" title="Go to Parent"></i>
|
||||||
|
<small>Go to parent task</small>
|
||||||
<label for="objective-check-frequency">Task Check Frequency</label>
|
|
||||||
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="0" max="99" />
|
|
||||||
<small>(0 = disabled)</small>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="objective-tasks"> </div>
|
||||||
|
<div class="objective_block margin-bot-10px">
|
||||||
|
<div class="objective_block objective_block_control flex1 flexFlowColumn">
|
||||||
|
<label for="objective-chat-depth">Position in Chat</label>
|
||||||
|
<input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" />
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="objective_block objective_block_control flex1">
|
||||||
|
|
||||||
|
<label for="objective-check-frequency">Task Check Frequency</label>
|
||||||
|
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="0" max="99" />
|
||||||
|
<small>(0 = disabled)</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span> Messages until next AI task completion check <span id="objective-counter">0</span></span>
|
||||||
|
<div class="objective_block flex-container">
|
||||||
|
<input id="objective_prompt_edit" class="menu_button" type="submit" value="Edit Prompts" />
|
||||||
|
</div>
|
||||||
|
<hr class="sysHR">
|
||||||
</div>
|
</div>
|
||||||
<span> Messages until next AI task completion check <span id="objective-counter">0</span></span>
|
|
||||||
<div class="objective_block flex-container">
|
|
||||||
<input id="objective_prompt_edit" class="menu_button" type="submit" value="Edit Prompts" />
|
|
||||||
</div>
|
|
||||||
<hr class="sysHR">
|
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
addManualTaskCheckUi()
|
addManualTaskCheckUi()
|
||||||
$('#extensions_settings').append(settingsHtml);
|
$('#extensions_settings').append(settingsHtml);
|
||||||
@@ -573,6 +742,9 @@ jQuery(() => {
|
|||||||
$("#objective-check-frequency").on('input', onCheckFrequencyInput)
|
$("#objective-check-frequency").on('input', onCheckFrequencyInput)
|
||||||
$('#objective-hide-tasks').on('click', onHideTasksInput)
|
$('#objective-hide-tasks').on('click', onHideTasksInput)
|
||||||
$('#objective_prompt_edit').on('click', onEditPromptClick)
|
$('#objective_prompt_edit').on('click', onEditPromptClick)
|
||||||
|
$('#objective-parent').hide()
|
||||||
|
$('#objective-parent').on('click',onParentClick)
|
||||||
|
$('#objective-text').on('focusout',onObjectiveTextFocusOut)
|
||||||
loadSettings()
|
loadSettings()
|
||||||
|
|
||||||
eventSource.on(event_types.CHAT_CHANGED, () => {
|
eventSource.on(event_types.CHAT_CHANGED, () => {
|
||||||
|
@@ -62,6 +62,8 @@ function loadNovelPreset(preset) {
|
|||||||
nai_settings.top_a = preset.top_a;
|
nai_settings.top_a = preset.top_a;
|
||||||
nai_settings.typical_p = preset.typical_p;
|
nai_settings.typical_p = preset.typical_p;
|
||||||
nai_settings.min_length = preset.min_length;
|
nai_settings.min_length = preset.min_length;
|
||||||
|
nai_settings.cfg_scale = preset.cfg_scale;
|
||||||
|
nai_settings.phrase_rep_pen = preset.phrase_rep_pen;
|
||||||
loadNovelSettingsUi(nai_settings);
|
loadNovelSettingsUi(nai_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +86,8 @@ function loadNovelSettings(settings) {
|
|||||||
nai_settings.top_a = settings.top_a;
|
nai_settings.top_a = settings.top_a;
|
||||||
nai_settings.typical_p = settings.typical_p;
|
nai_settings.typical_p = settings.typical_p;
|
||||||
nai_settings.min_length = settings.min_length;
|
nai_settings.min_length = settings.min_length;
|
||||||
|
nai_settings.phrase_rep_pen = settings.phrase_rep_pen;
|
||||||
|
nai_settings.cfg_scale = settings.cfg_scale;
|
||||||
nai_settings.streaming_novel = !!settings.streaming_novel;
|
nai_settings.streaming_novel = !!settings.streaming_novel;
|
||||||
loadNovelSettingsUi(nai_settings);
|
loadNovelSettingsUi(nai_settings);
|
||||||
|
|
||||||
@@ -95,6 +99,39 @@ function loadNovelSettings(settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const phraseRepPenStrings = [
|
||||||
|
null,
|
||||||
|
"very_light",
|
||||||
|
"light",
|
||||||
|
"medium",
|
||||||
|
"aggressive",
|
||||||
|
"very_aggressive"
|
||||||
|
]
|
||||||
|
|
||||||
|
function getPhraseRepPenString(phraseRepPenCounter) {
|
||||||
|
if (phraseRepPenCounter < 1 || phraseRepPenCounter > F5) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return phraseRepPenStrings[phraseRepPenCounter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPhraseRepPenCounter(phraseRepPenString) {
|
||||||
|
if (phraseRepPenString === phraseRepPenStrings[1]) {
|
||||||
|
return 1;
|
||||||
|
} else if (phraseRepPenString === phraseRepPenStrings[2]) {
|
||||||
|
return 2;
|
||||||
|
} else if (phraseRepPenString === phraseRepPenStrings[3]) {
|
||||||
|
return 3;
|
||||||
|
} else if (phraseRepPenString === phraseRepPenStrings[4]) {
|
||||||
|
return 4;
|
||||||
|
} else if (phraseRepPenString === phraseRepPenStrings[5]) {
|
||||||
|
return 5;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function loadNovelSettingsUi(ui_settings) {
|
function loadNovelSettingsUi(ui_settings) {
|
||||||
$("#temp_novel").val(ui_settings.temperature);
|
$("#temp_novel").val(ui_settings.temperature);
|
||||||
$("#temp_counter_novel").text(Number(ui_settings.temperature).toFixed(2));
|
$("#temp_counter_novel").text(Number(ui_settings.temperature).toFixed(2));
|
||||||
@@ -118,6 +155,10 @@ function loadNovelSettingsUi(ui_settings) {
|
|||||||
$("#top_a_counter_novel").text(Number(ui_settings.top_a).toFixed(2));
|
$("#top_a_counter_novel").text(Number(ui_settings.top_a).toFixed(2));
|
||||||
$("#typical_p_novel").val(ui_settings.typical_p);
|
$("#typical_p_novel").val(ui_settings.typical_p);
|
||||||
$("#typical_p_counter_novel").text(Number(ui_settings.typical_p).toFixed(2));
|
$("#typical_p_counter_novel").text(Number(ui_settings.typical_p).toFixed(2));
|
||||||
|
$("#cfg_scale_novel").val(ui_settings.cfg_scale);
|
||||||
|
$("#cfg_scale_counter_novel").text(Number(ui_settings.cfg_scale).toFixed(2));
|
||||||
|
$("#phrase_rep_pen_novel").val(getPhraseRepPenCounter(ui_settings.phrase_rep_pen));
|
||||||
|
$("#phrase_rep_pen_counter_novel").text(getPhraseRepPenCounter(ui_settings.phrase_rep_pen));
|
||||||
$("#min_length_novel").val(ui_settings.min_length);
|
$("#min_length_novel").val(ui_settings.min_length);
|
||||||
$("#min_length_counter_novel").text(Number(ui_settings.min_length).toFixed(0));
|
$("#min_length_counter_novel").text(Number(ui_settings.min_length).toFixed(0));
|
||||||
|
|
||||||
@@ -191,6 +232,18 @@ const sliders = [
|
|||||||
format: (val) => Number(val).toFixed(2),
|
format: (val) => Number(val).toFixed(2),
|
||||||
setValue: (val) => { nai_settings.typical_p = Number(val).toFixed(2); },
|
setValue: (val) => { nai_settings.typical_p = Number(val).toFixed(2); },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sliderId: "#cfg_scale_novel",
|
||||||
|
counterId: "#cfg_scale_counter_novel",
|
||||||
|
format: (val) => `${val}`,
|
||||||
|
setValue: (val) => { nai_settings.cfg_scale = Number(val).toFixed(2); },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sliderId: "#phrase_rep_pen_novel",
|
||||||
|
counterId: "#phrase_rep_pen_counter_novel",
|
||||||
|
format: (val) => `${val}`,
|
||||||
|
setValue: (val) => { nai_settings.phrase_rep_pen = getPhraseRepPenString(Number(val).toFixed(0)); },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sliderId: "#min_length_novel",
|
sliderId: "#min_length_novel",
|
||||||
counterId: "#min_length_counter_novel",
|
counterId: "#min_length_counter_novel",
|
||||||
@@ -200,6 +253,7 @@ const sliders = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export function getNovelGenerationData(finalPromt, this_settings, this_amount_gen) {
|
export function getNovelGenerationData(finalPromt, this_settings, this_amount_gen) {
|
||||||
|
const isNewModel = (nai_settings.model_novel.includes('clio') || nai_settings.model_novel.includes('kayra'));
|
||||||
return {
|
return {
|
||||||
"input": finalPromt,
|
"input": finalPromt,
|
||||||
"model": nai_settings.model_novel,
|
"model": nai_settings.model_novel,
|
||||||
@@ -217,13 +271,16 @@ export function getNovelGenerationData(finalPromt, this_settings, this_amount_ge
|
|||||||
"top_p": parseFloat(nai_settings.top_p),
|
"top_p": parseFloat(nai_settings.top_p),
|
||||||
"top_k": parseInt(nai_settings.top_k),
|
"top_k": parseInt(nai_settings.top_k),
|
||||||
"typical_p": parseFloat(nai_settings.typical_p),
|
"typical_p": parseFloat(nai_settings.typical_p),
|
||||||
|
"cfg_scale": parseFloat(nai_settings.cfg_scale),
|
||||||
|
"cfg_uc": "",
|
||||||
|
"phrase_rep_pen": nai_settings.phrase_rep_pen,
|
||||||
//"stop_sequences": {{187}},
|
//"stop_sequences": {{187}},
|
||||||
//bad_words_ids = {{50256}, {0}, {1}};
|
//bad_words_ids = {{50256}, {0}, {1}};
|
||||||
"generate_until_sentence": true,
|
"generate_until_sentence": true,
|
||||||
"use_cache": false,
|
"use_cache": false,
|
||||||
"use_string": true,
|
"use_string": true,
|
||||||
"return_full_text": false,
|
"return_full_text": false,
|
||||||
"prefix": "vanilla",
|
"prefix": isNewModel ? "special_instruct" : "vanilla",
|
||||||
"order": this_settings.order,
|
"order": this_settings.order,
|
||||||
"streaming": nai_settings.streaming_novel,
|
"streaming": nai_settings.streaming_novel,
|
||||||
};
|
};
|
||||||
|
@@ -256,7 +256,7 @@ function fixMarkdown(text) {
|
|||||||
// i.e. "^example * text* * harder problem *\n" -> "^example *text* *harder problem*\n"
|
// i.e. "^example * text* * harder problem *\n" -> "^example *text* *harder problem*\n"
|
||||||
|
|
||||||
// Find pairs of formatting characters and capture the text in between them
|
// Find pairs of formatting characters and capture the text in between them
|
||||||
const format = /(\*|_|~){1,2}([\s\S]*?)\1{1,2}/gm;
|
const format = /([\*_]{1,2})([\s\S]*?)\1/gm;
|
||||||
let matches = [];
|
let matches = [];
|
||||||
let match;
|
let match;
|
||||||
while ((match = format.exec(text)) !== null) {
|
while ((match = format.exec(text)) !== null) {
|
||||||
@@ -267,7 +267,7 @@ function fixMarkdown(text) {
|
|||||||
let newText = text;
|
let newText = text;
|
||||||
for (let i = matches.length - 1; i >= 0; i--) {
|
for (let i = matches.length - 1; i >= 0; i--) {
|
||||||
let matchText = matches[i][0];
|
let matchText = matches[i][0];
|
||||||
let replacementText = matchText.replace(/(\*|_|~)(\s+)|(\s+)(\*|_|~)/g, '$1$4');
|
let replacementText = matchText.replace(/(\*|_)([\t \u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+)|([\t \u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+)(\*|_)/g, '$1$4');
|
||||||
newText = newText.slice(0, matches[i].index) + replacementText + newText.slice(matches[i].index + matchText.length);
|
newText = newText.slice(0, matches[i].index) + replacementText + newText.slice(matches[i].index + matchText.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1786,7 +1786,7 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
|
|||||||
|
|
||||||
console.log(request.body);
|
console.log(request.body);
|
||||||
const bw = require('./src/bad-words');
|
const bw = require('./src/bad-words');
|
||||||
const bad_words_ids = request.body.model.includes('clio') ? bw.clioBadWordsId : bw.badWordIds;
|
const isNewModel = (request.body.model.includes('clio') || request.body.model.includes('kayra'));
|
||||||
const data = {
|
const data = {
|
||||||
"input": request.body.input,
|
"input": request.body.input,
|
||||||
"model": request.body.model,
|
"model": request.body.model,
|
||||||
@@ -1805,13 +1805,16 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
|
|||||||
"top_p": request.body.top_p,
|
"top_p": request.body.top_p,
|
||||||
"top_k": request.body.top_k,
|
"top_k": request.body.top_k,
|
||||||
"typical_p": request.body.typical_p,
|
"typical_p": request.body.typical_p,
|
||||||
|
"cfg_scale": request.body.cfg_scale,
|
||||||
|
"cfg_uc": request.body.cfg_uc,
|
||||||
|
"phrase_rep_pen": request.body.phrase_rep_pen,
|
||||||
//"stop_sequences": {{187}},
|
//"stop_sequences": {{187}},
|
||||||
"bad_words_ids": bad_words_ids,
|
"bad_words_ids": isNewModel ? bw.clioBadWordsId : bw.badWordIds,
|
||||||
//generate_until_sentence = true;
|
//generate_until_sentence = true;
|
||||||
"use_cache": request.body.use_cache,
|
"use_cache": request.body.use_cache,
|
||||||
"use_string": true,
|
"use_string": true,
|
||||||
"return_full_text": request.body.return_full_text,
|
"return_full_text": request.body.return_full_text,
|
||||||
"prefix": request.body.prefix,
|
"prefix": isNewModel ? "special_instruct" : request.body.prefix,
|
||||||
"order": request.body.order
|
"order": request.body.order
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user