Add support for nsfw avoidance prompt

This commit is contained in:
maver
2023-06-03 16:48:29 +02:00
parent 1adad6105a
commit e47f436cf7
2 changed files with 23 additions and 2 deletions

View File

@ -2,6 +2,14 @@ import {countTokens} from "./openai.js";
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
import {substituteParams} from "../script.js";
// Thrown by ChatCompletion when a requested prompt couldn't be found.
class IdentifierNotFoundError extends Error {
constructor(identifier) {
super(`Identifier ${identifier} not found`);
this.name = 'IdentifierNotFoundError';
}
}
// OpenAI API chat message handling
// const map = [{identifier: 'example', message: {role: 'system', content: 'exampleContent'}}, ...];
const ChatCompletion = {
@ -12,6 +20,10 @@ const ChatCompletion = {
this.map.push({ identifier, message });
return this;
},
get(identifier) {
const index = this.getMessageIndex(identifier);
return this.assertIndex(index, identifier).map[index];
},
insertBefore(identifier, insertIdentifier, insert) {
const index = this.getMessageIndex(identifier);
this.map.splice(this.assertIndex(index, identifier), 0, { identifier: insertIdentifier, message: insert });