[feat] additional description

This commit is contained in:
kwaroran
2023-09-27 14:15:07 +09:00
parent b733238272
commit 69ae060e1e
7 changed files with 60 additions and 4 deletions

View File

@@ -93,7 +93,8 @@ export const languageEnglish = {
replaceGlobalNote: "If its not blank, it replaces current global note to this.", replaceGlobalNote: "If its not blank, it replaces current global note to this.",
backgroundHTML: "A Markdown/HTML Data that would be injected to the background of chat screen.\n\n you can also use additional assets. for example, you can use `{{audio::<asset name}}` for background music." backgroundHTML: "A Markdown/HTML Data that would be injected to the background of chat screen.\n\n you can also use additional assets. for example, you can use `{{audio::<asset name}}` for background music."
+ "\n\n Additionaly, you can use these with additional assets:" + "\n\n Additionaly, you can use these with additional assets:"
+ "\n - `{{bg::<asset name>}}`: inject the background as asset" + "\n - `{{bg::<asset name>}}`: inject the background as asset",
additionalText: "The text that would be added to Character Description only when ai thinks its needed, so you can put long texts here. seperate with double newlines.",
}, },
setup: { setup: {
chooseProvider: "Choose AI Provider", chooseProvider: "Choose AI Provider",
@@ -435,4 +436,5 @@ export const languageEnglish = {
appendNameNAI: "Append Name on NAI", appendNameNAI: "Append Name on NAI",
customStopWords: "Custom Stop Words", customStopWords: "Custom Stop Words",
defaultPrompt: "Default Prompt", defaultPrompt: "Default Prompt",
additionalText: 'Additional Description',
} }

View File

@@ -611,6 +611,9 @@
<span class="text-textcolor">{language.replaceGlobalNote} <Help key="replaceGlobalNote"/></span> <span class="text-textcolor">{language.replaceGlobalNote} <Help key="replaceGlobalNote"/></span>
<TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.replaceGlobalNote}></TextAreaInput> <TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.replaceGlobalNote}></TextAreaInput>
<span class="text-textcolor mt-2">{language.additionalText} <Help key="additionalText" /></span>
<TextAreaInput margin="both" autocomplete="off" bind:value={currentChar.data.additionalText}></TextAreaInput>
{#if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4} {#if currentChar.data.chats[currentChar.data.chatPage].supaMemoryData && currentChar.data.chats[currentChar.data.chatPage].supaMemoryData.length > 4}
<span class="text-textcolor">{language.SuperMemory}</span> <span class="text-textcolor">{language.SuperMemory}</span>

View File

@@ -185,6 +185,7 @@ function convertOldTavernAndJSON(charaData:OldTavernChar, imgp:string|undefined
firstMsgIndex: -1, firstMsgIndex: -1,
replaceGlobalNote: "", replaceGlobalNote: "",
triggerscript: [], triggerscript: [],
additionalText: ''
} }
} }
@@ -346,7 +347,8 @@ async function importSpecv2(card:CharacterCardV2, img?:Uint8Array, mode?:'hub'|'
backgroundHTML: data?.extensions?.risuai?.backgroundHTML, backgroundHTML: data?.extensions?.risuai?.backgroundHTML,
license: data?.extensions?.risuai?.license, license: data?.extensions?.risuai?.license,
triggerscript: data?.extensions?.risuai?.triggerscript ?? [], triggerscript: data?.extensions?.risuai?.triggerscript ?? [],
private: data?.extensions?.risuai?.private ?? false private: data?.extensions?.risuai?.private ?? false,
additionalText: data?.extensions?.risuai?.additionalText ?? '',
} }
db.characters.push(char) db.characters.push(char)
@@ -424,7 +426,10 @@ async function createBaseV2(char:character) {
sdData: char.sdData, sdData: char.sdData,
additionalAssets: char.additionalAssets, additionalAssets: char.additionalAssets,
backgroundHTML: char.backgroundHTML, backgroundHTML: char.backgroundHTML,
license: char.license license: char.license,
triggerscript: char.triggerscript,
additionalText: char.additionalText
} }
} }
} }
@@ -463,6 +468,7 @@ export async function exportSpecV2(char:character, type:'png'|'json' = 'png') {
} }
} }
if(type === 'json'){ if(type === 'json'){
await downloadFile(`${char.name.replace(/[<>:"/\\|?*\.\,]/g, "")}_export.json`, Buffer.from(JSON.stringify(card, null, 4), 'utf-8')) await downloadFile(`${char.name.replace(/[<>:"/\\|?*\.\,]/g, "")}_export.json`, Buffer.from(JSON.stringify(card, null, 4), 'utf-8'))
alertNormal(language.successExport) alertNormal(language.successExport)
@@ -693,6 +699,7 @@ type CharacterCardV2 = {
license?:string, license?:string,
triggerscript?:triggerscript[] triggerscript?:triggerscript[]
private?:boolean private?:boolean
additionalText?:string
} }
} }
} }

View File

@@ -289,6 +289,7 @@ export function characterFormatUpdate(index:number|character){
cha.chats[cha.chatPage].note = cha.chats[cha.chatPage].note.trim() cha.chats[cha.chatPage].note = cha.chats[cha.chatPage].note.trim()
cha.postHistoryInstructions = null cha.postHistoryInstructions = null
} }
cha.additionalText ??= ''
} }
else{ else{
@@ -350,7 +351,8 @@ export function createBlankChar():character{
scenario:"", scenario:"",
firstMsgIndex: -1, firstMsgIndex: -1,
replaceGlobalNote: "", replaceGlobalNote: "",
triggerscript: [] triggerscript: [],
additionalText: ''
} }
} }

View File

@@ -0,0 +1,37 @@
import { DataBase, type Chat, type character } from "src/ts/storage/database";
import { HypaProcesser } from '../memory/hypamemory'
import type { OpenAIChat } from "..";
import { stringlizeChat } from "../stringlize";
import { get } from "svelte/store";
export async function additionalInformations(char: character,chats:Chat,){
const processer = new HypaProcesser('MiniLM')
const db = get(DataBase)
const info = char.additionalText
if(info){
const infos = info.split('\n\n')
await processer.addText(infos)
const filteredChat = chats.message.slice(0, 4).map((chat) => {
let name = chat.saying ?? ''
if(!name){
if(chat.role === 'user'){
name = db.username
}
else{
name = char.name
}
}
return `${name}: ${chat.data}`
}).join("\n\n")
const searched = await processer.similaritySearch(filteredChat)
const result = searched.slice(0,3).join("\n\n")
return result
}
return ''
}

View File

@@ -17,6 +17,7 @@ import { clone, cloneDeep } from "lodash";
import { groupOrder } from "./group"; import { groupOrder } from "./group";
import { runTrigger, type additonalSysPrompt } from "./triggers"; import { runTrigger, type additonalSysPrompt } from "./triggers";
import { HypaProcesser } from "./memory/hypamemory"; import { HypaProcesser } from "./memory/hypamemory";
import { additionalInformations } from "./embedding/addinfo";
export interface OpenAIChat{ export interface OpenAIChat{
role: 'system'|'user'|'assistant'|'function' role: 'system'|'user'|'assistant'|'function'
@@ -226,6 +227,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
{ {
let description = risuChatParser((db.promptPreprocess ? db.descriptionPrefix: '') + currentChar.desc, {chara: currentChar}) let description = risuChatParser((db.promptPreprocess ? db.descriptionPrefix: '') + currentChar.desc, {chara: currentChar})
const additionalInfo = await additionalInformations(currentChar, currentChat)
if(currentChar.personality){ if(currentChar.personality){
description += risuChatParser("\n\nDescription of {{char}}: " + currentChar.personality, {chara: currentChar}) description += risuChatParser("\n\nDescription of {{char}}: " + currentChar.personality, {chara: currentChar})
} }

View File

@@ -572,6 +572,7 @@ export interface character{
backgroundCSS?:string backgroundCSS?:string
license?:string license?:string
private?:boolean private?:boolean
additionalText:string
} }