[feat] additional description
This commit is contained in:
37
src/ts/process/embedding/addinfo.ts
Normal file
37
src/ts/process/embedding/addinfo.ts
Normal 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 ''
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { clone, cloneDeep } from "lodash";
|
||||
import { groupOrder } from "./group";
|
||||
import { runTrigger, type additonalSysPrompt } from "./triggers";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
import { additionalInformations } from "./embedding/addinfo";
|
||||
|
||||
export interface OpenAIChat{
|
||||
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})
|
||||
|
||||
const additionalInfo = await additionalInformations(currentChar, currentChat)
|
||||
|
||||
|
||||
if(currentChar.personality){
|
||||
description += risuChatParser("\n\nDescription of {{char}}: " + currentChar.personality, {chara: currentChar})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user