feat: add probability decorator

This commit is contained in:
kwaroran
2024-06-04 19:36:09 +09:00
parent 658f14ec4e
commit 0e5e587c90
5 changed files with 34 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { get, writable } from "svelte/store"; import { get, writable } from "svelte/store";
import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc } from "./storage/database"; import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdDataFunc, type loreBook } from "./storage/database";
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert"; import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert";
import { language } from "../lang"; import { language } from "../lang";
import { decode as decodeMsgpack } from "msgpackr"; import { decode as decodeMsgpack } from "msgpackr";
@@ -336,6 +336,7 @@ export function characterFormatUpdate(index:number|character){
cha.backgroundHTML ??= '' cha.backgroundHTML ??= ''
cha.backgroundCSS ??= '' cha.backgroundCSS ??= ''
cha.creation_date ??= Date.now() cha.creation_date ??= Date.now()
cha.globalLore = updateLorebooks(cha.globalLore)
if(!cha.newGenData){ if(!cha.newGenData){
cha = updateInlayScreen(cha) cha = updateInlayScreen(cha)
} }
@@ -365,6 +366,24 @@ export function characterFormatUpdate(index:number|character){
return cha return cha
} }
export function updateLorebooks(book:loreBook[]){
return book.map((v) => {
v.bookVersion ??= 1
if(v.bookVersion >= 2){
return v
}
if(v.activationPercent){
const perc = v.activationPercent
v.activationPercent = null
v.content = `@@probability ${perc}\n${v.content}`
}
v.content = v.content.replace(/@@@?end/g, '@@depth 0').replace(/\<(char|bot)\>/g, '{{char}}').replace(/\<(user)\>/g, '{{user}}')
v.bookVersion = 2
return v
})
}
export function createBlankChar():character{ export function createBlankChar():character{
return { return {

View File

@@ -118,7 +118,7 @@ const deprecatedCBSwithParams = [
const decorators = [ const decorators = [
'activate_only_after', 'activate_only_every', 'keep_activate_after_match', 'dont_activate_after_match', 'depth', 'reverse_depth', 'activate_only_after', 'activate_only_every', 'keep_activate_after_match', 'dont_activate_after_match', 'depth', 'reverse_depth',
'instruct_depth', 'reverse_instruct_depth', 'instruct_scan_depth', 'role', 'scan_depth', 'is_greeting', 'position', 'ignore_on_max_context', 'instruct_depth', 'reverse_instruct_depth', 'instruct_scan_depth', 'role', 'scan_depth', 'is_greeting', 'position', 'ignore_on_max_context',
'additional_keys', 'exclude_keys', 'is_user_icon', 'activate', 'dont_activate', 'disable_ui_prompt' 'additional_keys', 'exclude_keys', 'is_user_icon', 'activate', 'dont_activate', 'disable_ui_prompt', 'probability'
] ]
const deprecatedDecorators = [ const deprecatedDecorators = [

View File

@@ -424,6 +424,11 @@ export async function loadLoreBookV3Prompt(){
} }
return false return false
} }
case 'probability':{
if(Math.random() * 100 > parseInt(arg[0])){
activated = false
}
}
default:{ default:{
return false return false
} }

View File

@@ -707,6 +707,7 @@ export interface loreBook{
data:string[] data:string[]
}, },
useRegex?:boolean useRegex?:boolean
bookVersion?:number
} }
export interface character{ export interface character{

View File

@@ -33,6 +33,7 @@ import { startObserveDom } from "../observer";
import { removeDefaultHandler } from "src/main"; import { removeDefaultHandler } from "src/main";
import { updateGuisize } from "../gui/guisize"; import { updateGuisize } from "../gui/guisize";
import { encodeCapKeySafe } from "./mobileStorage"; import { encodeCapKeySafe } from "./mobileStorage";
import { updateLorebooks } from "../characters";
//@ts-ignore //@ts-ignore
export const isTauri = !!window.__TAURI__ export const isTauri = !!window.__TAURI__
@@ -891,6 +892,12 @@ async function checkNewFormat() {
return v !== null return v !== null
}) })
db.modules = (db.modules ?? []).map((v) => {
if(v.lorebook){
v.lorebook = updateLorebooks(v.lorebook)
}
return v
})
if(!db.formatversion){ if(!db.formatversion){
function checkParge(data:string){ function checkParge(data:string){