Render prompt manager after swiping with updated tokens

Including world info and extension prompts
This commit is contained in:
maver
2023-06-24 19:55:39 +02:00
parent 2f4424e6c6
commit 28fa2f5f57
2 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js"; import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
import {event_types, eventSource, substituteParams} from "../script.js"; import {event_types, eventSource, substituteParams} from "../script.js";
import {IdentifierNotFoundError, TokenHandler} from "./openai.js"; import {TokenHandler} from "./openai.js";
class Prompt { class Prompt {
identifier; role; content; name; system_prompt; identifier; role; content; name; system_prompt;
@ -240,14 +240,26 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
}); });
}; };
PromptManagerModule.prototype.render = function () { /**
* Main rendering function
*
* @param afterTryGenerate - Whether a dry run should be attempted before rendering
*/
PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
if (null === this.activeCharacter) return; if (null === this.activeCharacter) return;
this.error = null; this.error = null;
this.tryGenerate().then(() => {
if (true === afterTryGenerate) {
this.tryGenerate().then(() => {
this.renderPromptManager();
this.renderPromptManagerListItems()
this.makeDraggable();
});
} else {
this.renderPromptManager(); this.renderPromptManager();
this.renderPromptManagerListItems() this.renderPromptManagerListItems()
this.makeDraggable(); this.makeDraggable();
}); }
} }
/** /**
@ -590,6 +602,7 @@ PromptManagerModule.prototype.getPromptCollection = function () {
} }
PromptManagerModule.prototype.populateTokenHandler = function(messageCollection) { PromptManagerModule.prototype.populateTokenHandler = function(messageCollection) {
this.tokenHandler.resetCounts();
const counts = this.tokenHandler.getCounts(); const counts = this.tokenHandler.getCounts();
messageCollection.getCollection().forEach((message) => { messageCollection.getCollection().forEach((message) => {
counts[message.identifier] = message.getTokens(); counts[message.identifier] = message.getTokens();

View File

@ -610,6 +610,7 @@ function prepareOpenAIMessages({
} }
} finally { } finally {
promptManager.populateTokenHandler(chatCompletion.getMessages()); promptManager.populateTokenHandler(chatCompletion.getMessages());
promptManager.render(false);
} }
const chat = chatCompletion.getChat(); const chat = chatCompletion.getChat();
@ -1075,6 +1076,10 @@ class TokenHandler {
return this.counts; return this.counts;
} }
resetCounts() {
Object.keys(this.counts).forEach((key) => this.counts[key] = 0 );
}
setCounts(counts) { setCounts(counts) {
this.counts = counts; this.counts = counts;
} }