refactor name and icon get
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
|
import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
|
||||||
import { alertConfirm } from "src/ts/alert";
|
import { alertConfirm } from "src/ts/alert";
|
||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import { replacePlaceholders } from "../../ts/util";
|
import { getUserName, replacePlaceholders } from "../../ts/util";
|
||||||
import { onDestroy } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import { processScript } from "src/ts/process/scripts";
|
import { processScript } from "src/ts/process/scripts";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
}
|
}
|
||||||
,{
|
,{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: lastMessages.map(b=>(b.role==='char'? currentChar.name : $DataBase.username)+":"+b.data).reduce((a,b)=>a+','+b)
|
content: lastMessages.map(b=>(b.role==='char'? currentChar.name : getUserName())+":"+b.data).reduce((a,b)=>a+','+b)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
import Check from "src/lib/UI/GUI/CheckInput.svelte";
|
import Check from "src/lib/UI/GUI/CheckInput.svelte";
|
||||||
import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte";
|
import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte";
|
||||||
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||||
import { alertConfirm, alertError, alertSelect } from "src/ts/alert";
|
import { alertConfirm, alertSelect } from "src/ts/alert";
|
||||||
import { getCharImage } from "src/ts/characters";
|
import { getCharImage } from "src/ts/characters";
|
||||||
import { changeUserPersona, exportUserPersona, importUserPersona, saveUserPersona, selectUserImg } from "src/ts/persona";
|
import { changeUserPersona, exportUserPersona, importUserPersona, saveUserPersona, selectUserImg } from "src/ts/persona";
|
||||||
import { DataBase, setDatabase } from "src/ts/storage/database";
|
import { DataBase, setDatabase } from "src/ts/storage/database";
|
||||||
|
import { CurrentUserIcon } from "src/ts/stores";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -67,10 +68,10 @@
|
|||||||
<div class="flex w-full items-starts rounded-md bg-darkbg p-4 max-w-full flex-wrap">
|
<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">
|
<div class="flex flex-col mt-4 mr-4">
|
||||||
<button on:click={() => {selectUserImg()}}>
|
<button on:click={() => {selectUserImg()}}>
|
||||||
{#if $DataBase.userIcon === ''}
|
{#if $CurrentUserIcon === ''}
|
||||||
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" />
|
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" />
|
||||||
{:else}
|
{:else}
|
||||||
{#await getCharImage($DataBase.userIcon, $DataBase.personas[$DataBase.selectedPersona].largePortrait ? 'lgcss' : 'css')}
|
{#await getCharImage($CurrentUserIcon, $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" />
|
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" />
|
||||||
{:then im}
|
{:then im}
|
||||||
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" style={im} />
|
<div class="rounded-md h-28 w-28 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" style={im} />
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { DataBase, saveImage, setDatabase, type character, type Chat, defaultSdD
|
|||||||
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore, alertWait } from "./alert";
|
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore, alertWait } from "./alert";
|
||||||
import { language } from "../lang";
|
import { language } from "../lang";
|
||||||
import { decode as decodeMsgpack } from "msgpackr";
|
import { decode as decodeMsgpack } from "msgpackr";
|
||||||
import { checkNullish, findCharacterbyId, selectMultipleFile, selectSingleFile, sleep } from "./util";
|
import { checkNullish, findCharacterbyId, getUserName, selectMultipleFile, selectSingleFile, sleep } from "./util";
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { selectedCharID } from "./stores";
|
import { selectedCharID } from "./stores";
|
||||||
import { checkCharOrder, downloadFile, getFileSrc } from "./storage/globalApi";
|
import { checkCharOrder, downloadFile, getFileSrc } from "./storage/globalApi";
|
||||||
@@ -197,7 +197,7 @@ export async function exportChat(page:number){
|
|||||||
let i = 0
|
let i = 0
|
||||||
for(const v of chat.message){
|
for(const v of chat.message){
|
||||||
alertWait(`Translating... ${i++}/${chat.message.length}`)
|
alertWait(`Translating... ${i++}/${chat.message.length}`)
|
||||||
const name = v.saying ? findCharacterbyId(v.saying).name : v.role === 'char' ? char.name : anonymous ? '×××' : db.username
|
const name = v.saying ? findCharacterbyId(v.saying).name : v.role === 'char' ? char.name : anonymous ? '×××' : getUserName()
|
||||||
chatContentHTML += `<div class="chat">
|
chatContentHTML += `<div class="chat">
|
||||||
<h2>${name}</h2>
|
<h2>${name}</h2>
|
||||||
<div>${await htmlChatParse(v.data)}</div>
|
<div>${await htmlChatParse(v.data)}</div>
|
||||||
@@ -268,7 +268,7 @@ export async function exportChat(page:number){
|
|||||||
let i = 0
|
let i = 0
|
||||||
for(const v of chat.message){
|
for(const v of chat.message){
|
||||||
alertWait(`Translating... ${i++}/${chat.message.length}`)
|
alertWait(`Translating... ${i++}/${chat.message.length}`)
|
||||||
const name = v.saying ? findCharacterbyId(v.saying).name : v.role === 'char' ? char.name : anonymous ? '×××' : db.username
|
const name = v.saying ? findCharacterbyId(v.saying).name : v.role === 'char' ? char.name : anonymous ? '×××' : getUserName()
|
||||||
chatContentHTML += `<tr>
|
chatContentHTML += `<tr>
|
||||||
<td>${name}</td>
|
<td>${name}</td>
|
||||||
<td>${await htmlChatParse(v.data)}</td>
|
<td>${await htmlChatParse(v.data)}</td>
|
||||||
@@ -309,7 +309,7 @@ export async function exportChat(page:number){
|
|||||||
return `--${findCharacterbyId(v.saying).name}\n${v.data}`
|
return `--${findCharacterbyId(v.saying).name}\n${v.data}`
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return `--${v.role === 'char' ? char.name : db.username}\n${v.data}`
|
return `--${v.role === 'char' ? char.name : getUserName()}\n${v.data}`
|
||||||
}
|
}
|
||||||
}).join('\n\n')
|
}).join('\n\n')
|
||||||
|
|
||||||
@@ -409,7 +409,7 @@ export async function importChat(){
|
|||||||
|
|
||||||
function formatTavernChat(chat:string, charName:string){
|
function formatTavernChat(chat:string, charName:string){
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
return chat.replace(/<([Uu]ser)>|\{\{([Uu]ser)\}\}/g, db.username).replace(/((\{\{)|<)([Cc]har)(=.+)?((\}\})|>)/g, charName)
|
return chat.replace(/<([Uu]ser)>|\{\{([Uu]ser)\}\}/g, getUserName()).replace(/((\{\{)|<)([Cc]har)(=.+)?((\}\})|>)/g, charName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function characterFormatUpdate(index:number|character){
|
export function characterFormatUpdate(index:number|character){
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { get } from 'svelte/store';
|
|||||||
import css from '@adobe/css-tools'
|
import css from '@adobe/css-tools'
|
||||||
import { CurrentCharacter, CurrentChat, SizeStore, selectedCharID } from './stores';
|
import { CurrentCharacter, CurrentChat, SizeStore, selectedCharID } from './stores';
|
||||||
import { calcString } from './process/infunctions';
|
import { calcString } from './process/infunctions';
|
||||||
import { findCharacterbyId, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
import { findCharacterbyId, getUserIcon, getUserName, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
||||||
import { getInlayImage, writeInlayImage } from './process/files/image';
|
import { getInlayImage, writeInlayImage } from './process/files/image';
|
||||||
import { getModuleLorebooks } from './process/modules';
|
import { getModuleLorebooks } from './process/modules';
|
||||||
import { HypaProcesser } from './process/memory/hypamemory';
|
import { HypaProcesser } from './process/memory/hypamemory';
|
||||||
@@ -333,7 +333,7 @@ async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|c
|
|||||||
)
|
)
|
||||||
|
|
||||||
data = data.replace(/\uE9b4USER\uE9b4/g,
|
data = data.replace(/\uE9b4USER\uE9b4/g,
|
||||||
db.userIcon ? (await getFileSrc(db.userIcon)) : ''
|
getUserIcon() ? (await getFileSrc(getUserIcon())) : ''
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,7 +661,7 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
|
|||||||
if(matcherArg.consistantChar){
|
if(matcherArg.consistantChar){
|
||||||
return 'username'
|
return 'username'
|
||||||
}
|
}
|
||||||
return db.username
|
return getUserName()
|
||||||
}
|
}
|
||||||
case 'personality':
|
case 'personality':
|
||||||
case 'char_persona':{
|
case 'char_persona':{
|
||||||
@@ -1571,7 +1571,7 @@ const smMatcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
if(matcherArg.consistantChar){
|
if(matcherArg.consistantChar){
|
||||||
return 'username'
|
return 'username'
|
||||||
}
|
}
|
||||||
return db.username
|
return getUserName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { DataBase, saveImage, setDatabase } from "./storage/database"
|
import { DataBase, saveImage, setDatabase } from "./storage/database"
|
||||||
import { selectSingleFile, sleep } from "./util"
|
import { getUserName, selectSingleFile, sleep } from "./util"
|
||||||
import { alertError, alertNormal, alertStore } from "./alert"
|
import { alertError, alertNormal, alertStore } from "./alert"
|
||||||
import { downloadFile, readImage } from "./storage/globalApi"
|
import { downloadFile, readImage } from "./storage/globalApi"
|
||||||
import { language } from "src/lang"
|
import { language } from "src/lang"
|
||||||
@@ -17,7 +17,7 @@ export async function selectUserImg() {
|
|||||||
const imgp = await saveImage(img)
|
const imgp = await saveImage(img)
|
||||||
db.userIcon = imgp
|
db.userIcon = imgp
|
||||||
db.personas[db.selectedPersona] = {
|
db.personas[db.selectedPersona] = {
|
||||||
name: db.username,
|
name: getUserName(),
|
||||||
icon: db.userIcon,
|
icon: db.userIcon,
|
||||||
personaPrompt: db.personaPrompt
|
personaPrompt: db.personaPrompt
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ export async function selectUserImg() {
|
|||||||
export function saveUserPersona() {
|
export function saveUserPersona() {
|
||||||
let db = get(DataBase)
|
let db = get(DataBase)
|
||||||
db.personas[db.selectedPersona] = {
|
db.personas[db.selectedPersona] = {
|
||||||
name: db.username,
|
name: getUserName(),
|
||||||
icon: db.userIcon,
|
icon: db.userIcon,
|
||||||
personaPrompt: db.personaPrompt,
|
personaPrompt: db.personaPrompt,
|
||||||
largePortrait: db.personas[db.selectedPersona]?.largePortrait,
|
largePortrait: db.personas[db.selectedPersona]?.largePortrait,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { HypaProcesser } from '../memory/hypamemory'
|
|||||||
import type { OpenAIChat } from "..";
|
import type { OpenAIChat } from "..";
|
||||||
import { stringlizeChat } from "../stringlize";
|
import { stringlizeChat } from "../stringlize";
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
|
import { getUserName } from "src/ts/util";
|
||||||
|
|
||||||
export async function additionalInformations(char: character,chats:Chat,){
|
export async function additionalInformations(char: character,chats:Chat,){
|
||||||
const processer = new HypaProcesser('MiniLM')
|
const processer = new HypaProcesser('MiniLM')
|
||||||
@@ -18,7 +19,7 @@ export async function additionalInformations(char: character,chats:Chat,){
|
|||||||
|
|
||||||
if(!name){
|
if(!name){
|
||||||
if(chat.role === 'user'){
|
if(chat.role === 'user'){
|
||||||
name = db.username
|
name = getUserName()
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
name = char.name
|
name = char.name
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
|||||||
import { language } from "../../lang";
|
import { language } from "../../lang";
|
||||||
import { alertError } from "../alert";
|
import { alertError } from "../alert";
|
||||||
import { loadLoreBookPrompt, loadLoreBookV3Prompt } from "./lorebook";
|
import { loadLoreBookPrompt, loadLoreBookV3Prompt } from "./lorebook";
|
||||||
import { findCharacterbyId, getAuthorNoteDefaultText, isLastCharPunctuation, trimUntilPunctuation } from "../util";
|
import { findCharacterbyId, getAuthorNoteDefaultText, getUserName, isLastCharPunctuation, trimUntilPunctuation } from "../util";
|
||||||
import { requestChatData } from "./request";
|
import { requestChatData } from "./request";
|
||||||
import { stableDiff } from "./stableDiff";
|
import { stableDiff } from "./stableDiff";
|
||||||
import { processScript, processScriptFull, risuChatParser } from "./scripts";
|
import { processScript, processScriptFull, risuChatParser } from "./scripts";
|
||||||
@@ -574,7 +574,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const examples = exampleMessage(currentChar, db.username)
|
const examples = exampleMessage(currentChar, getUserName())
|
||||||
|
|
||||||
for(const example of examples){
|
for(const example of examples){
|
||||||
currentTokens += await tokenizer.tokenizeChat(example)
|
currentTokens += await tokenizer.tokenizeChat(example)
|
||||||
@@ -634,7 +634,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(msg.role === 'user'){
|
else if(msg.role === 'user'){
|
||||||
name = `${db.username}`
|
name = `${getUserName()}`
|
||||||
}
|
}
|
||||||
if(!msg.chatId){
|
if(!msg.chatId){
|
||||||
msg.chatId = v4()
|
msg.chatId = v4()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { HypaProcesser } from "./hypamemory";
|
|||||||
import { stringlizeChat } from "../stringlize";
|
import { stringlizeChat } from "../stringlize";
|
||||||
import { globalFetch } from "src/ts/storage/globalApi";
|
import { globalFetch } from "src/ts/storage/globalApi";
|
||||||
import { runSummarizer } from "../transformers";
|
import { runSummarizer } from "../transformers";
|
||||||
|
import { getUserName } from "src/ts/util";
|
||||||
|
|
||||||
export async function supaMemory(
|
export async function supaMemory(
|
||||||
chats:OpenAIChat[],
|
chats:OpenAIChat[],
|
||||||
@@ -329,7 +330,7 @@ export async function supaMemory(
|
|||||||
if((chunkSize + tokens) > maxChunkSize){
|
if((chunkSize + tokens) > maxChunkSize){
|
||||||
if(stringlizedChat === ''){
|
if(stringlizedChat === ''){
|
||||||
if(cont.role !== 'function' && cont.role !== 'system'){
|
if(cont.role !== 'function' && cont.role !== 'system'){
|
||||||
stringlizedChat += `${cont.role === 'assistant' ? char.type === 'group' ? '' : char.name : db.username}: ${cont.content}\n\n`
|
stringlizedChat += `${cont.role === 'assistant' ? char.type === 'group' ? '' : char.name : getUserName()}: ${cont.content}\n\n`
|
||||||
spiceLen += 1
|
spiceLen += 1
|
||||||
currentTokens -= tokens
|
currentTokens -= tokens
|
||||||
chunkSize += tokens
|
chunkSize += tokens
|
||||||
@@ -338,7 +339,7 @@ export async function supaMemory(
|
|||||||
lastId = cont.memo
|
lastId = cont.memo
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
stringlizedChat += `${cont.role === 'assistant' ? char.type === 'group' ? '' : char.name : db.username}: ${cont.content}\n\n`
|
stringlizedChat += `${cont.role === 'assistant' ? char.type === 'group' ? '' : char.name : getUserName()}: ${cont.content}\n\n`
|
||||||
spiceLen += 1
|
spiceLen += 1
|
||||||
currentTokens -= tokens
|
currentTokens -= tokens
|
||||||
chunkSize += tokens
|
chunkSize += tokens
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { OpenAIChat } from ".."
|
|||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { globalFetch } from "src/ts/storage/globalApi"
|
import { globalFetch } from "src/ts/storage/globalApi"
|
||||||
import { alertError, alertInput, alertNormal, alertWait } from "src/ts/alert"
|
import { alertError, alertInput, alertNormal, alertWait } from "src/ts/alert"
|
||||||
import { sleep } from "src/ts/util"
|
import { getUserName, sleep } from "src/ts/util"
|
||||||
|
|
||||||
export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued: boolean){
|
export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued: boolean){
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
@@ -34,7 +34,7 @@ export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued:
|
|||||||
res += '> '
|
res += '> '
|
||||||
}
|
}
|
||||||
if(db.NAIappendName){
|
if(db.NAIappendName){
|
||||||
res += db.username + ": "
|
res += getUserName() + ": "
|
||||||
}
|
}
|
||||||
res += form.content
|
res += form.content
|
||||||
resultString.push(res)
|
resultString.push(res)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import type { OpenAIChat } from ".";
|
import type { OpenAIChat } from ".";
|
||||||
import { DataBase } from "../storage/database";
|
import { DataBase } from "../storage/database";
|
||||||
|
import { getUserName } from "../util";
|
||||||
|
|
||||||
export function multiChatReplacer(){
|
export function multiChatReplacer(){
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, s
|
|||||||
let name = form.name
|
let name = form.name
|
||||||
if(form.role === 'user'){
|
if(form.role === 'user'){
|
||||||
prefix = appendWhitespace(suggesting ? assistantPrefix : userPrefix, seperator)
|
prefix = appendWhitespace(suggesting ? assistantPrefix : userPrefix, seperator)
|
||||||
name ??= `${db.username}`
|
name ??= `${getUserName()}`
|
||||||
name += ': '
|
name += ': '
|
||||||
}
|
}
|
||||||
else if(form.role === 'assistant'){
|
else if(form.role === 'assistant'){
|
||||||
@@ -80,7 +81,7 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, s
|
|||||||
if(!continued){
|
if(!continued){
|
||||||
if(db.ooba.formating.useName){
|
if(db.ooba.formating.useName){
|
||||||
if (suggesting){
|
if (suggesting){
|
||||||
resultString.push(appendWhitespace(assistantPrefix, seperator) + `${db.username}:\n` + db.autoSuggestPrefix)
|
resultString.push(appendWhitespace(assistantPrefix, seperator) + `${getUserName()}:\n` + db.autoSuggestPrefix)
|
||||||
} else {
|
} else {
|
||||||
resultString.push(assistantPrefix + `${characterName}:`)
|
resultString.push(assistantPrefix + `${characterName}:`)
|
||||||
}
|
}
|
||||||
@@ -173,17 +174,17 @@ export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:
|
|||||||
chunks.push(`${char}: `)
|
chunks.push(`${char}: `)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(db.username){
|
if(getUserName()){
|
||||||
charNames.push(db.username)
|
charNames.push(getUserName())
|
||||||
if(mode === 'ain'){
|
if(mode === 'ain'){
|
||||||
chunks.push(`${db.username} `)
|
chunks.push(`${getUserName()} `)
|
||||||
chunks.push(`${db.username} `)
|
chunks.push(`${getUserName()} `)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
chunks.push(`${db.username}:`)
|
chunks.push(`${getUserName()}:`)
|
||||||
chunks.push(`${db.username}:`)
|
chunks.push(`${getUserName()}:`)
|
||||||
chunks.push(`${db.username}: `)
|
chunks.push(`${getUserName()}: `)
|
||||||
chunks.push(`${db.username}: `)
|
chunks.push(`${getUserName()}: `)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +224,7 @@ export function stringlizeAINChat(formated:OpenAIChat[], char:string, continued:
|
|||||||
resultString.push(form.content)
|
resultString.push(form.content)
|
||||||
}
|
}
|
||||||
else if(form.role === 'user'){
|
else if(form.role === 'user'){
|
||||||
resultString.push(...formatToAIN(db.username, form.content))
|
resultString.push(...formatToAIN(getUserName(), form.content))
|
||||||
}
|
}
|
||||||
else if(form.name || form.role === 'assistant'){
|
else if(form.name || form.role === 'assistant'){
|
||||||
resultString.push(...formatToAIN(form.name ?? char, form.content))
|
resultString.push(...formatToAIN(form.name ?? char, form.content))
|
||||||
@@ -315,7 +316,7 @@ export function unstringlizeAIN(data:string,formated:OpenAIChat[], char:string =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const role = (cont.character.trim() === db.username ? 'user' : 'char')
|
const role = (cont.character.trim() === getUserName() ? 'user' : 'char')
|
||||||
result.push([
|
result.push([
|
||||||
role,
|
role,
|
||||||
`「${cont.content}」`
|
`「${cont.content}」`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { OpenAIChat } from '..';
|
|||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { DataBase } from 'src/ts/storage/database';
|
import { DataBase } from 'src/ts/storage/database';
|
||||||
import { CurrentCharacter } from 'src/ts/stores';
|
import { CurrentCharacter } from 'src/ts/stores';
|
||||||
|
import { getUserName } from 'src/ts/util';
|
||||||
|
|
||||||
export const chatTemplates = {
|
export const chatTemplates = {
|
||||||
'llama3': "{% set bos_token = '<|begin_of_text|>' %}{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}",
|
'llama3': "{% set bos_token = '<|begin_of_text|>' %}{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}",
|
||||||
@@ -93,6 +94,6 @@ export const applyChatTemplate = (messages:OpenAIChat[]) => {
|
|||||||
"messages": formatedMessages,
|
"messages": formatedMessages,
|
||||||
"add_generation_prompt": true,
|
"add_generation_prompt": true,
|
||||||
"risu_char": currentChar.name,
|
"risu_char": currentChar.name,
|
||||||
"risu_user": db.username
|
"risu_user": getUserName()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { get, writable, type Writable } from "svelte/store";
|
|||||||
import { DataBase, type Chat, type character, type groupChat } from "./storage/database";
|
import { DataBase, type Chat, type character, type groupChat } from "./storage/database";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import type { simpleCharacterArgument } from "./parser";
|
import type { simpleCharacterArgument } from "./parser";
|
||||||
import { sleep } from "./util";
|
import { getUserIcon, getUserName, sleep } from "./util";
|
||||||
import { getModules } from "./process/modules";
|
import { getModules } from "./process/modules";
|
||||||
|
|
||||||
function updateSize(){
|
function updateSize(){
|
||||||
@@ -76,8 +76,8 @@ function trySync(){
|
|||||||
CurrentCharacter.set(structuredClone(currentCharacter))
|
CurrentCharacter.set(structuredClone(currentCharacter))
|
||||||
CurrentSimpleCharacter.set(createSimpleCharacter(currentCharacter))
|
CurrentSimpleCharacter.set(createSimpleCharacter(currentCharacter))
|
||||||
CurrentChat.set(structuredClone(currentChat))
|
CurrentChat.set(structuredClone(currentChat))
|
||||||
CurrentUsername.set(db.username)
|
CurrentUsername.set(getUserName())
|
||||||
CurrentUserIcon.set(db.userIcon)
|
CurrentUserIcon.set(getUserIcon())
|
||||||
CurrentShowMemoryLimit.set(db.showMemoryLimit)
|
CurrentShowMemoryLimit.set(db.showMemoryLimit)
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
@@ -132,10 +132,10 @@ async function preInit(){
|
|||||||
|
|
||||||
DataBase.subscribe((data) => {
|
DataBase.subscribe((data) => {
|
||||||
updateCurrentCharacter()
|
updateCurrentCharacter()
|
||||||
if(data.username !== get(CurrentUsername)){
|
if(getUserName() !== get(CurrentUsername)){
|
||||||
CurrentUsername.set(data.username)
|
CurrentUsername.set(getUserName())
|
||||||
}
|
}
|
||||||
if(data.userIcon !== get(CurrentUserIcon)){
|
if(getUserIcon() !== get(CurrentUserIcon)){
|
||||||
CurrentUserIcon.set(data.userIcon)
|
CurrentUserIcon.set(data.userIcon)
|
||||||
}
|
}
|
||||||
if(data.showMemoryLimit !== get(CurrentShowMemoryLimit)){
|
if(data.showMemoryLimit !== get(CurrentShowMemoryLimit)){
|
||||||
@@ -189,6 +189,14 @@ async function preInit(){
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(getUserName() !== get(CurrentUsername)){
|
||||||
|
CurrentUsername.set(getUserName())
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getUserIcon() !== get(CurrentUserIcon)){
|
||||||
|
CurrentUserIcon.set(getUserIcon())
|
||||||
|
}
|
||||||
|
|
||||||
const variablePointer = get(CurrentVariablePointer)
|
const variablePointer = get(CurrentVariablePointer)
|
||||||
const currentState = structuredClone(chat?.scriptstate)
|
const currentState = structuredClone(chat?.scriptstate)
|
||||||
|
|
||||||
|
|||||||
@@ -103,10 +103,25 @@ export const replacePlaceholders = (msg:string, name:string) => {
|
|||||||
let selectedChar = get(selectedCharID)
|
let selectedChar = get(selectedCharID)
|
||||||
let currentChar = db.characters[selectedChar]
|
let currentChar = db.characters[selectedChar]
|
||||||
return msg .replace(/({{char}})|({{Char}})|(<Char>)|(<char>)/gi, currentChar.name)
|
return msg .replace(/({{char}})|({{Char}})|(<Char>)|(<char>)/gi, currentChar.name)
|
||||||
.replace(/({{user}})|({{User}})|(<User>)|(<user>)/gi, db.username)
|
.replace(/({{user}})|({{User}})|(<User>)|(<user>)/gi, getUserName())
|
||||||
.replace(/(\{\{((set)|(get))var::.+?\}\})/gu,'')
|
.replace(/(\{\{((set)|(get))var::.+?\}\})/gu,'')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUserName(){
|
||||||
|
const db = get(DataBase)
|
||||||
|
return db.username ?? 'User'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserIcon(){
|
||||||
|
const db = get(DataBase)
|
||||||
|
return db.userIcon ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserPersonaDesc(){
|
||||||
|
const db = get(DataBase)
|
||||||
|
return db.personaPrompt ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
export function checkIsIos(){
|
export function checkIsIos(){
|
||||||
return /(iPad|iPhone|iPod)/g.test(navigator.userAgent)
|
return /(iPad|iPhone|iPod)/g.test(navigator.userAgent)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user