From f7856dc4dd482b9fed400d6af2923e16d5d5146f Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 31 May 2023 10:25:53 +0900 Subject: [PATCH] [feat] added 'Use Probability Condition' in lorebook --- src-tauri/tauri.conf.json | 2 +- src/lang/en.ts | 5 ++++- src/lang/ko.ts | 4 +++- src/lib/SideBars/LoreBookData.svelte | 23 +++++++++++++++++++++-- src/ts/characterCards.ts | 15 ++++++++++++--- src/ts/process/lorebook.ts | 12 +++++++++++- src/ts/storage/database.ts | 3 ++- version.json | 2 +- 8 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 410af6c3..138f3ea1 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "RisuAI", - "version": "1.22.1" + "version": "1.22.2" }, "tauri": { "allowlist": { diff --git a/src/lang/en.ts b/src/lang/en.ts index 5dde3ac3..f3e9ace4 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -79,6 +79,7 @@ export const languageEnglish = { scenario: "A brief description about character's scenario. \n\n**It is not recommended to use this option. Describe it in character description instead.**", utilityBot: "When activated, it ignores main prompt. \n\n**It is not recommended to use this option. Modifiy system prompt instead.**", loreSelective: "If Selective mode is toggled, both Activation Key and Secondary key should have a match to activate the lore.", + loreRandomActivation: "If Use Probability Condition is abled, if the lore's other conditions are all met, the lore will be activated with a set probability which is set by 'Probability' each time a chat is sent.", additionalAssets: "Additional assets to display in your chat. \n\n - use `{{raw::}}` to use as path.\n - use `{{img::}}` to use as image", superMemory: "SuperMemory makes your character memorize more by giving summarized data to AI.\n\n" + "SuperMemory model is a model that summarizes that text. davinci is recommended, and Auxiliary models are not recommended unless it is an unfiltered model with over 2000 tokens with great summarizing skill.\n\n" @@ -294,5 +295,7 @@ export const languageEnglish = { orderByOrder: "Talk by Order", removeFromGroup: "Do you really want to remove {{char}} from group?", talkness: "Talkativeness", - active: "Active" + active: "Active", + loreRandomActivation: "Use Probability Condition", + activationProbability: "Probability" } \ No newline at end of file diff --git a/src/lang/ko.ts b/src/lang/ko.ts index 0d20cea4..ac5bb1ca 100644 --- a/src/lang/ko.ts +++ b/src/lang/ko.ts @@ -273,5 +273,7 @@ export const languageKorean = { orderByOrder: "순서대로 말하기", removeFromGroup: "정말로 {{char}}을 그룹에서 삭제시키겠습니까?", talkness: "대화량", - active: "활성화" + active: "활성화", + loreRandomActivation: "확률 조건 사용", + activationProbability: "발동 확률" } \ No newline at end of file diff --git a/src/lib/SideBars/LoreBookData.svelte b/src/lib/SideBars/LoreBookData.svelte index d59c7f7f..0437e9ee 100644 --- a/src/lib/SideBars/LoreBookData.svelte +++ b/src/lib/SideBars/LoreBookData.svelte @@ -39,9 +39,20 @@ {#if value.selective} {language.SecondaryKeys} {language.activationKeysInfo} - + {/if} {/if} + {#if !(value.activationPercent === undefined || value.activationPercent === null)} + {language.activationProbability} + { + if(isNaN(value.activationPercent) || !value.activationPercent || value.activationPercent < 0){ + value.activationPercent = 0 + } + if(value.activationPercent > 100){ + value.activationPercent = 100 + } + }}> + {/if} {language.insertOrder} {language.prompt} @@ -50,10 +61,18 @@ {language.alwaysActive} -
+
{language.selective}
+
+ {#if value.activationPercent === undefined || value.activationPercent === null} + {value.activationPercent = 50}}/> + {:else} + {value.activationPercent = null}}/> + {/if} + {language.loreRandomActivation} +
{/if} diff --git a/src/ts/characterCards.ts b/src/ts/characterCards.ts index e35efd83..6053ade8 100644 --- a/src/ts/characterCards.ts +++ b/src/ts/characterCards.ts @@ -382,7 +382,8 @@ async function importSpecv2(card:CharacterCardV2, img?:Uint8Array):Promise r.trim()), secondary_keys: lore.selective ? lore.secondkey.split(',').map(r => r.trim()) : undefined, content: lore.content, - extensions: lore.extentions ?? {}, + extensions: ext, enabled: true, insertion_order: lore.insertorder, constant: lore.alwaysActive, selective:lore.selective, name: lore.comment, comment: lore.comment, - case_sensitive: lore.extentions?.risu_case_sensitive + case_sensitive: caseSensitive, }) } diff --git a/src/ts/process/lorebook.ts b/src/ts/process/lorebook.ts index 45daba32..bbb2a6f7 100644 --- a/src/ts/process/lorebook.ts +++ b/src/ts/process/lorebook.ts @@ -2,7 +2,7 @@ import { get } from "svelte/store"; import {selectedCharID} from '../stores' import { DataBase, setDatabase, type loreBook } from "../storage/database"; import { tokenize } from "../tokenizer"; -import { selectSingleFile } from "../util"; +import { checkNullish, selectSingleFile } from "../util"; import { alertError, alertNormal } from "../alert"; import { language } from "../../lang"; import { downloadFile } from "../storage/globalApi"; @@ -80,6 +80,16 @@ export async function loadLoreBookPrompt(){ for (const lore of fullLore){ if(lore){ if(lore.key.length > 1 || lore.alwaysActive){ + if(!checkNullish(lore.activationPercent)){ + let activationPercent = lore.activationPercent + if(isNaN(activationPercent) || !activationPercent || activationPercent < 0){ + activationPercent = 0 + } + if(activationPercent < (Math.random() * 100)){ + continue + } + } + formatedLore.push({ keys: lore.alwaysActive ? 'always' : (lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => { return a.length > 1 diff --git a/src/ts/storage/database.ts b/src/ts/storage/database.ts index 0156f5d0..2aa55fd9 100644 --- a/src/ts/storage/database.ts +++ b/src/ts/storage/database.ts @@ -8,7 +8,7 @@ import { defaultAutoSuggestPrompt, defaultJailbreak, defaultMainPrompt } from '. export const DataBase = writable({} as any as Database) export const loadedStore = writable(false) -export let appVer = '1.22.1' +export let appVer = '1.22.2' export function setDatabase(data:Database){ if(checkNullish(data.characters)){ @@ -283,6 +283,7 @@ export interface loreBook{ extentions?:{ risu_case_sensitive:boolean } + activationPercent?:number } export interface character{ diff --git a/version.json b/version.json index 8d9a1e92..2f483bbb 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version":"1.22.1"} \ No newline at end of file +{"version":"1.22.2"} \ No newline at end of file