Change Reverse proxy name to Custom and add additionalParams
This commit is contained in:
28
src/ts/process/memory/termMemory.ts
Normal file
28
src/ts/process/memory/termMemory.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { OpenAIChat } from "..";
|
||||
import { HypaProcesser } from "./hypamemory";
|
||||
|
||||
export async function termMemory(chats:OpenAIChat[]){
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
processer.addText(chats.map(chat=>chat.content))
|
||||
|
||||
let scoredResults:{[key:string]:number}
|
||||
for(let i=1;i<5;i++){
|
||||
const chat = chats[chats.length-i]
|
||||
if(!chat?.content){
|
||||
continue
|
||||
}
|
||||
const scoredArray = (await processer.similaritySearchScored(chat.content)).map((result) => {
|
||||
return [result[0],result[1]/i] as [string,number]
|
||||
})
|
||||
for(const scored of scoredArray){
|
||||
if(scoredResults[scored[0]]){
|
||||
scoredResults[scored[0]] += scored[1]
|
||||
}else{
|
||||
scoredResults[scored[0]] = scored[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
const result = Object.entries(scoredResults).sort((a,b)=>a[1]-b[1])
|
||||
return result.map(([content,score])=>(content)).join('\n\n')
|
||||
|
||||
}
|
||||
@@ -606,6 +606,43 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
}
|
||||
}
|
||||
|
||||
if(raiModel === 'reverse_proxy'){
|
||||
const additionalParams = db.additionalParams
|
||||
for(let i=0;i<additionalParams.length;i++){
|
||||
let key = additionalParams[i][0]
|
||||
let value = additionalParams[i][1]
|
||||
|
||||
if(!key || !value){
|
||||
continue
|
||||
}
|
||||
|
||||
if(value === '{{none}}'){
|
||||
if(key.startsWith('header::')){
|
||||
key = key.replace('header::', '')
|
||||
delete headers[key]
|
||||
}
|
||||
else{
|
||||
delete body[key]
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if(key.startsWith('header::')){
|
||||
key = key.replace('header::', '')
|
||||
headers[key] = value
|
||||
}
|
||||
else if(isNaN(parseFloat(value))){
|
||||
if(value.startsWith('"') && value.endsWith('"')){
|
||||
value = value.slice(1, -1)
|
||||
}
|
||||
body[key] = value
|
||||
}
|
||||
else{
|
||||
body[key] = parseFloat(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const res = await globalFetch(replacerURL, {
|
||||
body: body,
|
||||
headers: headers,
|
||||
|
||||
Reference in New Issue
Block a user