@@ -12,6 +12,11 @@
|
||||
import VisualNovelMain from "../VisualNovel/VisualNovelMain.svelte";
|
||||
let openChatList = false
|
||||
|
||||
$:{
|
||||
if ($DataBase.translatorType === 'submodel'){
|
||||
$DataBase.useStreaming = false
|
||||
}
|
||||
}
|
||||
const wallPaper = `background: url(${defaultWallpaper})`
|
||||
const externalStyles =
|
||||
("background: " + ($DataBase.textScreenColor ? ($DataBase.textScreenColor + '80') : "rgba(0,0,0,0.8)") + ';\n')
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
import { changeLanguage, language } from "src/lang";
|
||||
import { DataBase } from "src/ts/storage/database";
|
||||
import { sleep } from "src/ts/util";
|
||||
import Help from "src/lib/Others/Help.svelte";
|
||||
import OptionInput from "src/lib/UI/GUI/OptionInput.svelte";
|
||||
import SelectInput from "src/lib/UI/GUI/SelectInput.svelte";
|
||||
import { alertNormal } from "src/ts/alert";
|
||||
import { downloadFile } from "src/ts/storage/globalApi";
|
||||
import { languageEnglish } from "src/lang/en";
|
||||
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||
let langChanged = false
|
||||
|
||||
</script>
|
||||
<h2 class="mb-2 text-2xl font-bold mt-2">{language.language}</h2>
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<SelectInput className="mt-2 mb-4" bind:value={$DataBase.translatorType}>
|
||||
<OptionInput value="google" >Google</OptionInput>
|
||||
<OptionInput value="deepl" >DeepL</OptionInput>
|
||||
<OptionInput value="submodel" >Use submodel</OptionInput>
|
||||
</SelectInput>
|
||||
|
||||
{#if $DataBase.translatorType === 'deepl'}
|
||||
@@ -67,6 +68,11 @@
|
||||
<Check bind:check={$DataBase.deeplOptions.freeApi} name={language.deeplFreeKey}/>
|
||||
</div>
|
||||
|
||||
{:else if $DataBase.translatorType === 'submodel'}
|
||||
<span class="text-textcolor mt-4">Translate Prompt</span>
|
||||
<TextInput bind:value={$DataBase.translatorprompt} placeholder="If empty, use the default prompt."/>
|
||||
<span class="text-draculared text-xs mb-2">Response streaming is disabled when using submodels.</span>
|
||||
<span class="text-draculared text-xs mb-2">Translation sends a lot of requests at once, so don't use it at reverse proxy.</span>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
@@ -309,6 +309,9 @@ export function setDatabase(data:Database){
|
||||
if(!data.formatingOrder.includes('personaPrompt')){
|
||||
data.formatingOrder.splice(data.formatingOrder.indexOf('main'),0,'personaPrompt')
|
||||
}
|
||||
if(checkNullish(data.translatorprompt)){
|
||||
data.translatorprompt = ""
|
||||
}
|
||||
data.selectedPersona ??= 0
|
||||
data.personaPrompt ??= ''
|
||||
data.personas ??= [{
|
||||
@@ -519,13 +522,14 @@ export interface Database{
|
||||
mancerHeader:string
|
||||
emotionProcesser:'submodel'|'embedding',
|
||||
showMenuChatList?:boolean,
|
||||
translatorType:'google'|'deepl'|'none',
|
||||
translatorType:'google'|'deepl'|'submodel'|'none',
|
||||
NAIadventure?:boolean,
|
||||
NAIappendName?:boolean,
|
||||
deeplOptions:{
|
||||
key:string,
|
||||
freeApi:boolean
|
||||
}
|
||||
translatorprompt:string
|
||||
localStopStrings?:string[]
|
||||
autofillRequestUrl:boolean
|
||||
customProxyRequestModel:string
|
||||
|
||||
@@ -3,6 +3,8 @@ import { translatorPlugin } from "../plugins/plugins"
|
||||
import { DataBase } from "../storage/database"
|
||||
import { globalFetch } from "../storage/globalApi"
|
||||
import { alertError } from "../alert"
|
||||
import type { OpenAIChat } from "../process"
|
||||
import { requestChatData } from "../process/request"
|
||||
|
||||
let cache={
|
||||
origin: [''],
|
||||
@@ -120,7 +122,39 @@ async function translateMain(text:string, arg:{from:string, to:string, host:stri
|
||||
|
||||
}
|
||||
|
||||
if(db.translatorType === 'submodel'){
|
||||
|
||||
const defaulttranslateprompt = `You need to translate the entered sentence from ${arg.from.toLocaleUpperCase()} to ${arg.to.toLocaleUpperCase()}. You must not write any words other than the translated sentence.`
|
||||
|
||||
const translateprompt = (db.translatorprompt === '')? defaulttranslateprompt : db.translatorprompt
|
||||
|
||||
const promptbody:OpenAIChat[] = [
|
||||
{
|
||||
role:'system',
|
||||
content: translateprompt
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: text
|
||||
},
|
||||
]
|
||||
const rq = await requestChatData({
|
||||
formated: promptbody,
|
||||
temperature: 0.2,
|
||||
maxTokens: 500,
|
||||
bias: {}
|
||||
}, 'submodel')
|
||||
|
||||
if(rq.type === 'fail' || rq.type === 'streaming' || rq.type === 'multiline'){
|
||||
alertError(`${rq.result}`)
|
||||
return false
|
||||
}
|
||||
|
||||
const r = rq.result
|
||||
console.log(r)
|
||||
|
||||
return r
|
||||
}
|
||||
const url = `https://${arg.host}/translate_a/single?client=gtx&dt=t&sl=${arg.from}&tl=${arg.to}&q=` + encodeURIComponent(text)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user