refactor name and icon get
This commit is contained in:
@@ -3,6 +3,7 @@ import { HypaProcesser } from '../memory/hypamemory'
|
||||
import type { OpenAIChat } from "..";
|
||||
import { stringlizeChat } from "../stringlize";
|
||||
import { get } from "svelte/store";
|
||||
import { getUserName } from "src/ts/util";
|
||||
|
||||
export async function additionalInformations(char: character,chats:Chat,){
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
@@ -18,7 +19,7 @@ export async function additionalInformations(char: character,chats:Chat,){
|
||||
|
||||
if(!name){
|
||||
if(chat.role === 'user'){
|
||||
name = db.username
|
||||
name = getUserName()
|
||||
}
|
||||
else{
|
||||
name = char.name
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { language } from "../../lang";
|
||||
import { alertError } from "../alert";
|
||||
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 { stableDiff } from "./stableDiff";
|
||||
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){
|
||||
currentTokens += await tokenizer.tokenizeChat(example)
|
||||
@@ -634,7 +634,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
}
|
||||
}
|
||||
else if(msg.role === 'user'){
|
||||
name = `${db.username}`
|
||||
name = `${getUserName()}`
|
||||
}
|
||||
if(!msg.chatId){
|
||||
msg.chatId = v4()
|
||||
|
||||
@@ -7,6 +7,7 @@ import { HypaProcesser } from "./hypamemory";
|
||||
import { stringlizeChat } from "../stringlize";
|
||||
import { globalFetch } from "src/ts/storage/globalApi";
|
||||
import { runSummarizer } from "../transformers";
|
||||
import { getUserName } from "src/ts/util";
|
||||
|
||||
export async function supaMemory(
|
||||
chats:OpenAIChat[],
|
||||
@@ -329,7 +330,7 @@ export async function supaMemory(
|
||||
if((chunkSize + tokens) > maxChunkSize){
|
||||
if(stringlizedChat === ''){
|
||||
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
|
||||
currentTokens -= tokens
|
||||
chunkSize += tokens
|
||||
@@ -338,7 +339,7 @@ export async function supaMemory(
|
||||
lastId = cont.memo
|
||||
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
|
||||
currentTokens -= tokens
|
||||
chunkSize += tokens
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { OpenAIChat } from ".."
|
||||
import { get } from "svelte/store"
|
||||
import { globalFetch } from "src/ts/storage/globalApi"
|
||||
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){
|
||||
const db = get(DataBase)
|
||||
@@ -34,7 +34,7 @@ export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued:
|
||||
res += '> '
|
||||
}
|
||||
if(db.NAIappendName){
|
||||
res += db.username + ": "
|
||||
res += getUserName() + ": "
|
||||
}
|
||||
res += form.content
|
||||
resultString.push(res)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { DataBase } from "../storage/database";
|
||||
import { getUserName } from "../util";
|
||||
|
||||
export function multiChatReplacer(){
|
||||
|
||||
@@ -57,7 +58,7 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, s
|
||||
let name = form.name
|
||||
if(form.role === 'user'){
|
||||
prefix = appendWhitespace(suggesting ? assistantPrefix : userPrefix, seperator)
|
||||
name ??= `${db.username}`
|
||||
name ??= `${getUserName()}`
|
||||
name += ': '
|
||||
}
|
||||
else if(form.role === 'assistant'){
|
||||
@@ -80,7 +81,7 @@ export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, s
|
||||
if(!continued){
|
||||
if(db.ooba.formating.useName){
|
||||
if (suggesting){
|
||||
resultString.push(appendWhitespace(assistantPrefix, seperator) + `${db.username}:\n` + db.autoSuggestPrefix)
|
||||
resultString.push(appendWhitespace(assistantPrefix, seperator) + `${getUserName()}:\n` + db.autoSuggestPrefix)
|
||||
} else {
|
||||
resultString.push(assistantPrefix + `${characterName}:`)
|
||||
}
|
||||
@@ -173,17 +174,17 @@ export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:
|
||||
chunks.push(`${char}: `)
|
||||
}
|
||||
}
|
||||
if(db.username){
|
||||
charNames.push(db.username)
|
||||
if(getUserName()){
|
||||
charNames.push(getUserName())
|
||||
if(mode === 'ain'){
|
||||
chunks.push(`${db.username} `)
|
||||
chunks.push(`${db.username} `)
|
||||
chunks.push(`${getUserName()} `)
|
||||
chunks.push(`${getUserName()} `)
|
||||
}
|
||||
else{
|
||||
chunks.push(`${db.username}:`)
|
||||
chunks.push(`${db.username}:`)
|
||||
chunks.push(`${db.username}: `)
|
||||
chunks.push(`${db.username}: `)
|
||||
chunks.push(`${getUserName()}:`)
|
||||
chunks.push(`${getUserName()}:`)
|
||||
chunks.push(`${getUserName()}: `)
|
||||
chunks.push(`${getUserName()}: `)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +224,7 @@ export function stringlizeAINChat(formated:OpenAIChat[], char:string, continued:
|
||||
resultString.push(form.content)
|
||||
}
|
||||
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'){
|
||||
resultString.push(...formatToAIN(form.name ?? char, form.content))
|
||||
@@ -315,7 +316,7 @@ export function unstringlizeAIN(data:string,formated:OpenAIChat[], char:string =
|
||||
}
|
||||
}
|
||||
else{
|
||||
const role = (cont.character.trim() === db.username ? 'user' : 'char')
|
||||
const role = (cont.character.trim() === getUserName() ? 'user' : 'char')
|
||||
result.push([
|
||||
role,
|
||||
`「${cont.content}」`
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { OpenAIChat } from '..';
|
||||
import { get } from 'svelte/store';
|
||||
import { DataBase } from 'src/ts/storage/database';
|
||||
import { CurrentCharacter } from 'src/ts/stores';
|
||||
import { getUserName } from 'src/ts/util';
|
||||
|
||||
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' }}",
|
||||
@@ -93,6 +94,6 @@ export const applyChatTemplate = (messages:OpenAIChat[]) => {
|
||||
"messages": formatedMessages,
|
||||
"add_generation_prompt": true,
|
||||
"risu_char": currentChar.name,
|
||||
"risu_user": db.username
|
||||
"risu_user": getUserName()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user