mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Render prompt manager after swiping with updated tokens
Including world info and extension prompts
This commit is contained in:
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user