feat: persona binding

This commit is contained in:
kwaroran
2024-07-30 00:40:09 +09:00
parent 634056b0cb
commit b9b7201889
11 changed files with 187 additions and 31 deletions

View File

@@ -2,7 +2,7 @@
import Suggestion from './Suggestion.svelte';
import AdvancedChatEditor from './AdvancedChatEditor.svelte';
import { CameraIcon, DatabaseIcon, DicesIcon, GlobeIcon, ImagePlusIcon, LanguagesIcon, Laugh, MenuIcon, MicOffIcon, PackageIcon, Plus, RefreshCcwIcon, ReplyIcon, Send, StepForwardIcon } from "lucide-svelte";
import { CurrentCharacter, CurrentChat, CurrentUsername, selectedCharID, CurrentUserIcon, CurrentShowMemoryLimit,CurrentSimpleCharacter, PlaygroundStore } from "../../ts/stores";
import { CurrentCharacter, CurrentChat, CurrentUsername, selectedCharID, CurrentUserIcon, CurrentShowMemoryLimit,CurrentSimpleCharacter, PlaygroundStore, UserIconProtrait } from "../../ts/stores";
import Chat from "./Chat.svelte";
import { DataBase, type Message, type character, type groupChat } from "../../ts/storage/database";
import { getCharImage } from "../../ts/characters";
@@ -587,7 +587,7 @@
message={chat.data}
img={getCharImage($CurrentUserIcon, 'css')}
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $CurrentShowMemoryLimit}
largePortrait={$DataBase.personas[$DataBase.selectedPersona].largePortrait}
largePortrait={$UserIconProtrait}
MessageGenerationInfo={chat.generationInfo}
/>
{/if}

View File

@@ -83,7 +83,7 @@
<div class="text-textcolor">You should accept RisuRealm's <a class="text-green-600 hover:text-green-500 transition-colors duration-200 cursor-pointer" on:click={() => {
openURL('https://sv.risuai.xyz/hub/tos')
}}>Terms of Service</a> to continue</div>
{:else if $alertStore.type !== 'select' && $alertStore.type !== 'requestdata' && $alertStore.type !== 'addchar' && $alertStore.type !== 'hypaV2'}
{:else if $alertStore.type !== 'select' && $alertStore.type !== 'requestdata' && $alertStore.type !== 'addchar' && $alertStore.type !== 'hypaV2' && $alertStore.type !== 'chatOptions'}
<span class="text-gray-300">{$alertStore.msg}</span>
{#if $alertStore.submsg}
<span class="text-gray-500 text-sm">{$alertStore.submsg}</span>
@@ -368,6 +368,48 @@
</div>
</button>
</div>
{:else if $alertStore.type === 'chatOptions'}
<div class="w-2xl flex flex-col max-w-full">
<h1 class="text-xl mb-4 font-bold">
{language.chatOptions}
</h1>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => {
alertStore.set({
type: 'none',
msg: '0'
})
}}>
<div class="flex flex-col justify-start items-start">
<span>{language.createCopy}</span>
</div>
<div class="ml-9 float-right flex-1 flex justify-end">
<ChevronRightIcon />
</div>
</button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => {
alertStore.set({
type: 'none',
msg: '1'
})
}}>
<div class="flex flex-col justify-start items-start">
<span>{language.bindPersona}</span>
</div>
<div class="ml-9 float-right flex-1 flex justify-end">
<ChevronRightIcon />
</div>
</button>
<button class="border-darkborderc border py-2 px-8 flex rounded-md hover:ring-2 items-center mt-2" on:click={() => {
alertStore.set({
type: 'none',
msg: 'cancel'
})
}}>
<div class="flex flex-col justify-start items-start">
<span>{language.cancel}</span>
</div>
</button>
</div>
{/if}
</div>
</div>

View File

@@ -9,7 +9,6 @@
import { getCharImage } from "src/ts/characters";
import { changeUserPersona, exportUserPersona, importUserPersona, saveUserPersona, selectUserImg } from "src/ts/persona";
import { DataBase, setDatabase } from "src/ts/storage/database";
import { CurrentUserIcon } from "src/ts/stores";
import { get } from "svelte/store";
</script>
@@ -68,10 +67,10 @@
<div class="flex w-full items-starts rounded-md bg-darkbg p-4 max-w-full flex-wrap">
<div class="flex flex-col mt-4 mr-4">
<button on:click={() => {selectUserImg()}}>
{#if $CurrentUserIcon === ''}
{#if $DataBase.userIcon === ''}
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" />
{:else}
{#await getCharImage($CurrentUserIcon, $DataBase.personas[$DataBase.selectedPersona].largePortrait ? 'lgcss' : 'css')}
{#await getCharImage($DataBase.userIcon, $DataBase.personas[$DataBase.selectedPersona].largePortrait ? 'lgcss' : 'css')}
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" />
{:then im}
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" style={im} />
@@ -81,7 +80,7 @@
</div>
<div class="flex flex-grow flex-col p-2 max-w-full">
<span class="text-sm text-textcolor2">{language.name}</span>
<TextInput marginBottom size="lg" placeholder="User" bind:value={$DataBase.username} />
<TextInput marginBottom size="lg" placeholder="User" bind:value={$DataBase.username}/>
<span class="text-sm text-textcolor2">{language.description}</span>
<TextAreaInput autocomplete="off" bind:value={$DataBase.personaPrompt} placeholder={`Put the description of this persona here.\nExample: [<user> is a 20 year old girl.]`} />
<div class="flex gap-2 mt-4 max-w-full flex-wrap">

View File

@@ -1,10 +1,10 @@
<script lang="ts">
import type { Chat, character, groupChat } from "src/ts/storage/database";
import { DataBase } from "src/ts/storage/database";
import { DataBase, setDatabase } from "src/ts/storage/database";
import TextInput from "../UI/GUI/TextInput.svelte";
import { DownloadIcon, PencilIcon, FolderUpIcon, MenuIcon, TrashIcon } from "lucide-svelte";
import { exportChat, importChat } from "src/ts/characters";
import { alertConfirm, alertError, alertSelect } from "src/ts/alert";
import { alertChatOptions, alertConfirm, alertError, alertNormal, alertSelect } from "src/ts/alert";
import { language } from "src/lang";
import Button from "../UI/GUI/Button.svelte";
import { findCharacterbyId, parseKeyValue, sleep, sortableOptions } from "src/ts/util";
@@ -13,6 +13,7 @@
import { CurrentCharacter } from "src/ts/stores";
import Sortable from 'sortablejs/modular/sortable.core.esm.js';
import { onDestroy, onMount } from "svelte";
import { v4 } from "uuid";
export let chara:character|groupChat
let editMode = false
@@ -95,16 +96,41 @@
<span>{chat.name}</span>
{/if}
<div class="flex-grow flex justify-end">
{#if $DataBase.tpo}
<button class="text-textcolor2 hover:text-green-500 mr-1 cursor-pointer" on:click={async () => {
const multiuser = parseInt(await alertSelect(["Open Multiuser Room"]))
if(multiuser === 0){
createMultiuserRoom()
<button class="text-textcolor2 hover:text-green-500 mr-1 cursor-pointer" on:click={async () => {
const option = await alertChatOptions()
switch(option){
case 0:{
const newChat = structuredClone(chara.chats[i])
newChat.name = `Copy of ${newChat.name}`
chara.chats.unshift(newChat)
chara.chatPage = 0
chara.chats = chara.chats
}
}}>
<MenuIcon size={18}/>
</button>
{/if}
case 1:{
const chat = chara.chats[i]
if(chat.bindedPersona){
const confirm = await alertConfirm(language.doYouWantToUnbindCurrentPersona)
if(confirm){
chat.bindedPersona = ''
alertNormal(language.personaUnbindedSuccess)
}
}
else{
const confirm = await alertConfirm(language.doYouWantToBindCurrentPersona)
if(confirm){
if(!$DataBase.personas[$DataBase.selectedPersona].id){
$DataBase.personas[$DataBase.selectedPersona].id = v4()
}
chat.bindedPersona = $DataBase.personas[$DataBase.selectedPersona].id
console.log($DataBase.personas[$DataBase.selectedPersona])
alertNormal(language.personaBindedSuccess)
}
}
}
}
}}>
<MenuIcon size={18}/>
</button>
<button class="text-textcolor2 hover:text-green-500 mr-1 cursor-pointer" on:click={() => {
editMode = !editMode
}}>