[feat] emotion minilm processer
This commit is contained in:
@@ -414,4 +414,5 @@ export const languageEnglish = {
|
||||
HypaMemory: "HypaMemory",
|
||||
ToggleHypaMemory: "Toggle HypaMemory",
|
||||
resetPromptTemplateConfirm: "Do you really want to reset prompt template?",
|
||||
emotionMethod: "Emotion Method",
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<span class="text-textcolor mt-4 text-lg font-bold">{language.imageGeneration}</span>
|
||||
|
||||
<span class="text-textcolor mt-2">{language.provider} <Help key="sdProvider"/></span>
|
||||
<span class="text-textcolor mt-2">{language.imageGeneration} {language.provider} <Help key="sdProvider"/></span>
|
||||
<SelectInput className="mt-2 mb-4" bind:value={$DataBase.sdProvider}>
|
||||
<OptionInput value="" >None</OptionInput>
|
||||
<OptionInput value="webui" >Stable Diffusion WebUI</OptionInput>
|
||||
@@ -64,6 +64,14 @@
|
||||
<span class="text-textcolor mt-2">VOICEVOX URL</span>
|
||||
<TextInput size="sm" marginBottom bind:value={$DataBase.voicevoxUrl}/>
|
||||
|
||||
<span class="text-textcolor mt-4 text-lg font-bold">{language.emotionImage}</span>
|
||||
|
||||
<span class="text-textcolor mt-2">{language.emotionMethod}</span>
|
||||
<SelectInput className="mt-2 mb-4" bind:value={$DataBase.emotionProcesser}>
|
||||
<OptionInput value="submodel" >Ax. Model</OptionInput>
|
||||
<OptionInput value="embedding" >MiniLM-L6-v2</OptionInput>
|
||||
</SelectInput>
|
||||
|
||||
<span class="text-textcolor mt-4 text-lg font-bold">{language.SuperMemory} <Help key="superMemory" /></span>
|
||||
<span class="text-textcolor mt-4">{language.SuperMemory} {language.model}</span>
|
||||
<SelectInput className="mt-2 mb-2" bind:value={$DataBase.supaMemoryType}>
|
||||
|
||||
@@ -16,6 +16,7 @@ import { v4 } from "uuid";
|
||||
import { clone, cloneDeep } from "lodash";
|
||||
import { groupOrder } from "./group";
|
||||
import { runTrigger, type additonalSysPrompt } from "./triggers";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
|
||||
export interface OpenAIChat{
|
||||
role: 'system'|'user'|'assistant'|'function'
|
||||
@@ -762,19 +763,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
if(currentChar.viewScreen === 'emotion' && (!emoChanged) && (abortSignal.aborted === false)){
|
||||
|
||||
let currentEmotion = currentChar.emotionImages
|
||||
|
||||
function shuffleArray(array:string[]) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
let emotionList = currentEmotion.map((a) => {
|
||||
return a[0]
|
||||
})
|
||||
|
||||
let charemotions = get(CharEmotion)
|
||||
|
||||
let tempEmotion = charemotions[currentChar.chaId]
|
||||
@@ -785,6 +776,61 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n
|
||||
tempEmotion.splice(0, 1)
|
||||
}
|
||||
|
||||
if(db.emotionProcesser === 'embedding'){
|
||||
const hypaProcesser = new HypaProcesser('MiniLM')
|
||||
await hypaProcesser.addText(emotionList.map((v) => 'emotion:' + v))
|
||||
let searched = (await hypaProcesser.similaritySearchScored(result)).map((v) => {
|
||||
v[0] = v[0].replace("emotion:",'')
|
||||
return v
|
||||
})
|
||||
|
||||
//give panaltys
|
||||
for(let i =0;i<tempEmotion.length;i++){
|
||||
const emo = tempEmotion[i]
|
||||
//give panalty index
|
||||
const index = searched.findIndex((v) => {
|
||||
return v[0] === emo[0]
|
||||
})
|
||||
|
||||
const modifier = ((5 - ((tempEmotion.length - (i + 1))))) / 200
|
||||
|
||||
if(index !== -1){
|
||||
searched[index][1] -= modifier
|
||||
}
|
||||
}
|
||||
|
||||
//make a sorted array by score
|
||||
const emoresult = searched.sort((a,b) => {
|
||||
return b[1] - a[1]
|
||||
}).map((v) => {
|
||||
return v[0]
|
||||
})
|
||||
|
||||
console.log(searched)
|
||||
|
||||
for(const emo of currentEmotion){
|
||||
if(emo[0] === emoresult[0]){
|
||||
const emos:[string, string,number] = [emo[0], emo[1], Date.now()]
|
||||
tempEmotion.push(emos)
|
||||
charemotions[currentChar.chaId] = tempEmotion
|
||||
CharEmotion.set(charemotions)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function shuffleArray(array:string[]) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
let emobias:{[key:number]:number} = {}
|
||||
|
||||
for(const emo of emotionList){
|
||||
|
||||
@@ -122,12 +122,15 @@ export class HypaProcesser{
|
||||
|
||||
async similaritySearch(query: string) {
|
||||
const results = await this.similaritySearchVectorWithScore((await this.getEmbeds(query))[0],);
|
||||
|
||||
console.log(results)
|
||||
return results.map((result) => result[0]);
|
||||
}
|
||||
|
||||
async similaritySearchVectorWithScore(
|
||||
async similaritySearchScored(query: string) {
|
||||
const results = await this.similaritySearchVectorWithScore((await this.getEmbeds(query))[0],);
|
||||
return results
|
||||
}
|
||||
|
||||
private async similaritySearchVectorWithScore(
|
||||
query: number[],
|
||||
): Promise<[string, number][]> {
|
||||
const memoryVectors = this.vectors
|
||||
|
||||
@@ -304,6 +304,7 @@ export function setDatabase(data:Database){
|
||||
data.NAIsettings.starter ??= ""
|
||||
data.hypaModel ??= 'MiniLM'
|
||||
data.mancerHeader ??= ''
|
||||
data.emotionProcesser ??= 'submodel'
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
}
|
||||
@@ -623,6 +624,7 @@ export interface Database{
|
||||
hypaModel:'ada'|'MiniLM'
|
||||
saveTime?:number
|
||||
mancerHeader:string
|
||||
emotionProcesser:'submodel'|'embedding'
|
||||
}
|
||||
|
||||
interface hordeConfig{
|
||||
|
||||
Reference in New Issue
Block a user