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

@@ -8,7 +8,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2 versionCode 2
versionName "1.111.6" versionName "1.111.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions { aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

View File

@@ -12,7 +12,7 @@
"filters": [], "filters": [],
"attributes": [], "attributes": [],
"versionCode": 2, "versionCode": 2,
"versionName": "1.111.6", "versionName": "1.111.7",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
], ],

View File

@@ -8,7 +8,7 @@
}, },
"package": { "package": {
"productName": "RisuAI", "productName": "RisuAI",
"version": "1.111.6" "version": "1.111.7"
}, },
"tauri": { "tauri": {
"allowlist": { "allowlist": {

View File

@@ -649,4 +649,6 @@ export const languageEnglish = {
goCharacterOnImport: "Go to Character on Realm Import", goCharacterOnImport: "Go to Character on Realm Import",
format: "Format", format: "Format",
v2Warning: "Warning: V2 card is no longer supported. it may not contain all the data.", 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 { CurrentChat } from "src/ts/stores";
import { tokenize } from "src/ts/tokenizer"; import { tokenize } from "src/ts/tokenizer";
import TextAreaInput from "../UI/GUI/TextAreaInput.svelte"; import TextAreaInput from "../UI/GUI/TextAreaInput.svelte";
import ModuleChatMenu from "../Setting/Pages/Module/ModuleChatMenu.svelte";
let btn let btn
let input = '' let input = ''
let cardExportType = 'realm' let cardExportType = 'realm'
@@ -58,7 +59,7 @@
} }
}}></svelte:window> }}></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="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"> <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'} {#if $alertStore.type === 'error'}
@@ -450,6 +451,13 @@
}) })
}} }}
>{$alertStore.msg}</div> >{$alertStore.msg}</div>
{:else if $alertStore.type === 'selectModule'}
<ModuleChatMenu alertMode close={(d) => {
alertStore.set({
type: 'none',
msg: d
})
}} />
{/if} {/if}
<style> <style>

View File

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

View File

@@ -29,6 +29,7 @@
import { updateInlayScreen } from "src/ts/process/inlayScreen"; import { updateInlayScreen } from "src/ts/process/inlayScreen";
import { registerOnnxModel } from "src/ts/process/transformers"; import { registerOnnxModel } from "src/ts/process/transformers";
import MultiLangInput from "../UI/GUI/MultiLangInput.svelte"; import MultiLangInput from "../UI/GUI/MultiLangInput.svelte";
import { applyModule } from "src/ts/process/modules";
let subMenu = 0 let subMenu = 0
@@ -904,20 +905,30 @@
</div> </div>
{#if $DataBase.supaMemoryType === 'hypaV2'} {#if $DataBase.supaMemoryType === 'hypaV2'}
<Button on:click={() => { <Button
currentChar.data.chats[currentChar.data.chatPage].hypaV2Data ??= { on:click={() => {
chunks: [], currentChar.data.chats[currentChar.data.chatPage].hypaV2Data ??= {
mainChunks: [] chunks: [],
} mainChunks: []
showHypaV2Alert() }
}}> showHypaV2Alert()
}}
className="mt-4"
>
{language.HypaMemory} V2 Data {language.HypaMemory} V2 Data
</Button> </Button>
{:else if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4 || currentChar.data.supaMemory} {: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> <TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].supaMemoryData}></TextAreaInput>
{/if} {/if}
<Button
on:click={applyModule}
className="mt-4"
>
{language.applyModule}
</Button>
{#if currentChar.data.license !== 'CC BY-NC-SA 4.0' {#if currentChar.data.license !== 'CC BY-NC-SA 4.0'
&& currentChar.data.license !== 'CC BY-SA 4.0' && currentChar.data.license !== 'CC BY-SA 4.0'
&& currentChar.data.license !== 'CC BY-ND 4.0' && currentChar.data.license !== 'CC BY-ND 4.0'
@@ -946,15 +957,9 @@
{/if} {/if}
{:else} {:else}
{#if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4 || currentChar.data.supaMemory} {#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> <TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].supaMemoryData}></TextAreaInput>
{/if} {/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"> <div class="flex items-center mt-4">
<Check bind:check={currentChar.data.lowLevelAccess} name={language.lowLevelAccess}/> <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" import { DataBase, type MessageGenerationInfo } from "./storage/database"
interface alertData{ 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, msg: string,
submsg?: string submsg?: string
} }
@@ -269,6 +269,23 @@ export async function alertInput(msg:string){
return get(alertStore).msg 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){ export function alertRequestData(info:AlertGenerationInfoStoreData){
alertGenerationInfoStore.set(info) alertGenerationInfoStore.set(info)
alertStore.set({ alertStore.set({

View File

@@ -1,9 +1,9 @@
import { language } from "src/lang" 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 { DataBase, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database"
import { downloadFile } from "../storage/globalApi" import { downloadFile } from "../storage/globalApi"
import { get } from "svelte/store" import { get } from "svelte/store"
import { CurrentChat } from "../stores" import { CurrentCharacter, CurrentChat } from "../stores"
import { selectSingleFile } from "../util" import { selectSingleFile } from "../util"
import { v4 } from "uuid" import { v4 } from "uuid"
import { convertExternalLorebook } from "./lorebook" import { convertExternalLorebook } from "./lorebook"
@@ -186,4 +186,42 @@ export function getModuleRegexScripts() {
} }
} }
return customscripts 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 DataBase = writable({} as any as Database)
export const loadedStore = writable(false) export const loadedStore = writable(false)
export let appVer = "1.111.6" export let appVer = "1.111.7"
export let webAppSubVer = '' export let webAppSubVer = ''
export function setDatabase(data:Database){ export function setDatabase(data:Database){

View File

@@ -1 +1 @@
{"version":"1.111.6"} {"version":"1.111.7"}