[feat] better ain stringlizer
This commit is contained in:
@@ -3,7 +3,7 @@ import type { OpenAIChat, OpenAIChatFull } from ".";
|
|||||||
import { DataBase, setDatabase, type character } from "../storage/database";
|
import { DataBase, setDatabase, type character } from "../storage/database";
|
||||||
import { pluginProcess } from "../plugins/plugins";
|
import { pluginProcess } from "../plugins/plugins";
|
||||||
import { language } from "../../lang";
|
import { language } from "../../lang";
|
||||||
import { stringlizeAINChat, stringlizeChat, unstringlizeChat } from "./stringlize";
|
import { getUnstringlizerChunks, stringlizeAINChat, stringlizeChat, unstringlizeChat } from "./stringlize";
|
||||||
import { globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
|
import { globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
|
||||||
import { sleep } from "../util";
|
import { sleep } from "../util";
|
||||||
import { createDeep } from "./deepai";
|
import { createDeep } from "./deepai";
|
||||||
@@ -573,7 +573,8 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
top_p: 0.7,
|
top_p: 0.7,
|
||||||
tailfree: 1.0,
|
tailfree: 1.0,
|
||||||
rep_pen: arg.frequencyPenalty ?? (db.frequencyPenalty / 100) + 1,
|
rep_pen: arg.frequencyPenalty ?? (db.frequencyPenalty / 100) + 1,
|
||||||
model: aiModel === 'novellist_damsel' ? 'damsel' : 'supertrin'
|
model: aiModel === 'novellist_damsel' ? 'damsel' : 'supertrin',
|
||||||
|
userbadwords: [":",":",": ",": "].join("<<|>>")
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await globalFetch(api_server_url + '/api', {
|
const response = await globalFetch(api_server_url + '/api', {
|
||||||
|
|||||||
@@ -24,18 +24,9 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
|||||||
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
||||||
console.log(text)
|
console.log(text)
|
||||||
let minIndex = -1
|
let minIndex = -1
|
||||||
let chunks:string[] = ["system note:", "system:","system note:", "system:"]
|
|
||||||
if(char){
|
|
||||||
chunks.push(`${char}:`)
|
|
||||||
}
|
|
||||||
|
|
||||||
for(const form of formated){
|
const chunks = getUnstringlizerChunks(formated, char)
|
||||||
if(form.name){
|
|
||||||
chunks.push(`${form.name}:`)
|
|
||||||
chunks.push(`${form.name}:`)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(const chunk of chunks){
|
for(const chunk of chunks){
|
||||||
const ind = text.indexOf(chunk)
|
const ind = text.indexOf(chunk)
|
||||||
@@ -54,6 +45,23 @@ export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUnstringlizerChunks(formated:OpenAIChat[], char:string = ''){
|
||||||
|
let chunks:string[] = ["system note:", "system:","system note:", "system:"]
|
||||||
|
if(char){
|
||||||
|
chunks.push(`${char}:`)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const form of formated){
|
||||||
|
if(form.name){
|
||||||
|
chunks.push(`${form.name}:`)
|
||||||
|
chunks.push(`${form.name}:`)
|
||||||
|
chunks.push(`${form.name}: `)
|
||||||
|
chunks.push(`${form.name}: `)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chunks
|
||||||
|
}
|
||||||
|
|
||||||
export function stringlizeAINChat(formated:OpenAIChat[], char:string = ''){
|
export function stringlizeAINChat(formated:OpenAIChat[], char:string = ''){
|
||||||
let resultString:string[] = []
|
let resultString:string[] = []
|
||||||
for(const form of formated){
|
for(const form of formated){
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ export async function translate(text:string, reverse:boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return googleTrans(text, reverse, db.aiModel.startsWith('novellist') ? 'jp' : 'en')
|
return googleTrans(text, reverse, db.translator,db.aiModel.startsWith('novellist') ? 'jp' : 'en')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function googleTrans(text:string, reverse:boolean, target:'en'|'jp') {
|
async function googleTrans(text:string, reverse:boolean, from:string,target:'en'|'jp') {
|
||||||
let db = get(DataBase)
|
let db = get(DataBase)
|
||||||
const arg = {
|
const arg = {
|
||||||
|
|
||||||
from: reverse ? db.translator : target,
|
from: reverse ? from : target,
|
||||||
|
|
||||||
to: reverse ? target : db.translator,
|
to: reverse ? target : from,
|
||||||
|
|
||||||
host: 'translate.googleapis.com',
|
host: 'translate.googleapis.com',
|
||||||
|
|
||||||
@@ -89,5 +89,5 @@ async function jpTrans(text:string) {
|
|||||||
if(/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/.test(text)){
|
if(/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/.test(text)){
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
return await googleTrans(text,false, 'jp')
|
return await googleTrans(text,false, 'en','jp')
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user