feat: add module apply

This commit is contained in:
kwaroran
2024-06-05 16:38:44 +09:00
parent 1b776c3076
commit 764c2370dd
11 changed files with 115 additions and 35 deletions

View File

@@ -649,4 +649,6 @@ export const languageEnglish = {
goCharacterOnImport: "Go to Character on Realm Import",
format: "Format",
v2Warning: "Warning: V2 card is no longer supported. it may not contain all the data.",
applyModule: "Apply Module",
successApplyModule: "Module is successfully applied",
}

View File

@@ -18,6 +18,7 @@
import { CurrentChat } from "src/ts/stores";
import { tokenize } from "src/ts/tokenizer";
import TextAreaInput from "../UI/GUI/TextAreaInput.svelte";
import ModuleChatMenu from "../Setting/Pages/Module/ModuleChatMenu.svelte";
let btn
let input = ''
let cardExportType = 'realm'
@@ -58,7 +59,7 @@
}
}}></svelte:window>
{#if $alertStore.type !== 'none' && $alertStore.type !== 'toast' && $alertStore.type !== 'cardexport'}
{#if $alertStore.type !== 'none' && $alertStore.type !== 'toast' && $alertStore.type !== 'cardexport' && $alertStore.type !== 'selectModule'}
<div class="absolute w-full h-full z-50 bg-black bg-opacity-50 flex justify-center items-center" class:vis={ $alertStore.type === 'wait2'}>
<div class="bg-darkbg p-4 break-any rounded-md flex flex-col max-w-3xl max-h-full overflow-y-auto">
{#if $alertStore.type === 'error'}
@@ -450,6 +451,13 @@
})
}}
>{$alertStore.msg}</div>
{:else if $alertStore.type === 'selectModule'}
<ModuleChatMenu alertMode close={(d) => {
alertStore.set({
type: 'none',
msg: d
})
}} />
{/if}
<style>

View File

@@ -7,8 +7,8 @@
import { DataBase } from "src/ts/storage/database";
import { CurrentChat } from "src/ts/stores";
import { SettingsMenuIndex, settingsOpen } from "src/ts/stores";
export let close = () => {}
export let close = (i:string) => {}
export let alertMode = false
let moduleSearch = ''
function sortModules(modules:RisuModule[], search:string){
@@ -20,11 +20,13 @@
}).sort((a, b) => {
let score = a.name.toLowerCase().localeCompare(b.name.toLowerCase())
if(db.enabledModules.includes(a.id)){
score += 1000
}
if(db.enabledModules.includes(b.id)){
score -= 1000
if(!alertMode){
if(db.enabledModules.includes(a.id)){
score += 1000
}
if(db.enabledModules.includes(b.id)){
score -= 1000
}
}
return score
@@ -39,7 +41,9 @@
<div class="flex items-center text-textcolor">
<h2 class="mt-0 mb-0 text-lg">{language.modules}</h2>
<div class="flex-grow flex justify-end">
<button class="text-textcolor2 hover:text-green-500 mr-2 cursor-pointer items-center" on:click={close}>
<button class="text-textcolor2 hover:text-green-500 mr-2 cursor-pointer items-center" on:click={() => {
close('')
}}>
<XIcon size={24}/>
</button>
</div>
@@ -64,15 +68,21 @@
<span class="">{rmodule.name}</span>
{/if}
<div class="flex-grow flex justify-end">
{#if $DataBase.enabledModules.includes(rmodule.id)}
{#if $DataBase.enabledModules.includes(rmodule.id) && !alertMode}
<button class="mr-2 text-textcolor2 cursor-not-allowed">
</button>
{:else}
<button class={(!$CurrentChat.modules.includes(rmodule.id)) ?
<button class={(!$CurrentChat.modules.includes(rmodule.id) && !alertMode) ?
"text-textcolor2 hover:text-green-500 mr-2 cursor-pointer" :
"mr-2 cursor-pointer text-blue-500"
} on:click={async (e) => {
e.stopPropagation()
if(alertMode){
close(rmodule.id)
return
}
if($CurrentChat.modules.includes(rmodule.id)){
$CurrentChat.modules.splice($CurrentChat.modules.indexOf(rmodule.id), 1)
}
@@ -93,7 +103,7 @@
<Button className="mt-4 flex-grow-0" size="sm" on:click={() => {
$SettingsMenuIndex = 14
$settingsOpen = true
close()
close('')
}}>{language.edit}</Button>
</div>
</div>

View File

@@ -29,6 +29,7 @@
import { updateInlayScreen } from "src/ts/process/inlayScreen";
import { registerOnnxModel } from "src/ts/process/transformers";
import MultiLangInput from "../UI/GUI/MultiLangInput.svelte";
import { applyModule } from "src/ts/process/modules";
let subMenu = 0
@@ -904,20 +905,30 @@
</div>
{#if $DataBase.supaMemoryType === 'hypaV2'}
<Button on:click={() => {
currentChar.data.chats[currentChar.data.chatPage].hypaV2Data ??= {
chunks: [],
mainChunks: []
}
showHypaV2Alert()
}}>
<Button
on:click={() => {
currentChar.data.chats[currentChar.data.chatPage].hypaV2Data ??= {
chunks: [],
mainChunks: []
}
showHypaV2Alert()
}}
className="mt-4"
>
{language.HypaMemory} V2 Data
</Button>
{:else if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4 || currentChar.data.supaMemory}
<span class="text-textcolor">{language.SuperMemory}</span>
<span class="text-textcolor mt-4">{language.SuperMemory}</span>
<TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].supaMemoryData}></TextAreaInput>
{/if}
<Button
on:click={applyModule}
className="mt-4"
>
{language.applyModule}
</Button>
{#if currentChar.data.license !== 'CC BY-NC-SA 4.0'
&& currentChar.data.license !== 'CC BY-SA 4.0'
&& currentChar.data.license !== 'CC BY-ND 4.0'
@@ -946,15 +957,9 @@
{/if}
{:else}
{#if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4 || currentChar.data.supaMemory}
<span class="text-textcolor">{language.SuperMemory}</span>
<span class="text-textcolor mt-4">{language.SuperMemory}</span>
<TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].supaMemoryData}></TextAreaInput>
{/if}
{#if $DataBase.useExperimental}
<div class="flex mb-2 items-center">
<Check bind:check={currentChar.data.useCharacterLore} name={language.useCharLorebook}/>
<Help key="experimental" name={language.useCharLorebook}/>
</div>
{/if}
<div class="flex items-center mt-4">
<Check bind:check={currentChar.data.lowLevelAccess} name={language.lowLevelAccess}/>

View File

@@ -6,7 +6,7 @@ import { Capacitor } from "@capacitor/core"
import { DataBase, type MessageGenerationInfo } from "./storage/database"
interface alertData{
type: 'error'| 'normal'|'none'|'ask'|'wait'|'selectChar'|'input'|'toast'|'wait2'|'markdown'|'select'|'login'|'tos'|'cardexport'|'requestdata'|'addchar'|'hypaV2',
type: 'error'| 'normal'|'none'|'ask'|'wait'|'selectChar'|'input'|'toast'|'wait2'|'markdown'|'select'|'login'|'tos'|'cardexport'|'requestdata'|'addchar'|'hypaV2'|'selectModule',
msg: string,
submsg?: string
}
@@ -269,6 +269,23 @@ export async function alertInput(msg:string){
return get(alertStore).msg
}
export async function alertModuleSelect(){
alertStore.set({
'type': 'selectModule',
'msg': ''
})
while(true){
if (get(alertStore).type === 'none'){
break
}
await sleep(10)
}
return get(alertStore).msg
}
export function alertRequestData(info:AlertGenerationInfoStoreData){
alertGenerationInfoStore.set(info)
alertStore.set({

View File

@@ -1,9 +1,9 @@
import { language } from "src/lang"
import { alertConfirm, alertError, alertNormal } from "../alert"
import { alertConfirm, alertError, alertModuleSelect, alertNormal } from "../alert"
import { DataBase, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database"
import { downloadFile } from "../storage/globalApi"
import { get } from "svelte/store"
import { CurrentChat } from "../stores"
import { CurrentCharacter, CurrentChat } from "../stores"
import { selectSingleFile } from "../util"
import { v4 } from "uuid"
import { convertExternalLorebook } from "./lorebook"
@@ -186,4 +186,42 @@ export function getModuleRegexScripts() {
}
}
return customscripts
}
export async function applyModule() {
const sel = await alertModuleSelect()
if (!sel) {
return
}
const module = structuredClone(getModuleById(sel))
if (!module) {
return
}
const currentChar = get(CurrentCharacter)
if (!currentChar) {
return
}
if(currentChar.type === 'group'){
return
}
if (module.lorebook) {
for (const lore of module.lorebook) {
currentChar.globalLore.push(lore)
}
}
if (module.regex) {
for (const regex of module.regex) {
currentChar.customscript.push(regex)
}
}
if (module.trigger) {
for (const trigger of module.trigger) {
currentChar.triggerscript.push(trigger)
}
}
alertNormal(language.successApplyModule)
}

View File

@@ -14,7 +14,7 @@ import type { OobaChatCompletionRequestParams } from '../model/ooba';
export const DataBase = writable({} as any as Database)
export const loadedStore = writable(false)
export let appVer = "1.111.6"
export let appVer = "1.111.7"
export let webAppSubVer = ''
export function setDatabase(data:Database){