Add autoTranslateCachedOnly option to auto-translate only previously translated text when enabled.
This commit is contained in:
@@ -170,6 +170,7 @@ export const languageEnglish = {
|
|||||||
summarizationPrompt: "The prompt that is used for summarization. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the chat data.",
|
summarizationPrompt: "The prompt that is used for summarization. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the chat data.",
|
||||||
translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.",
|
translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.",
|
||||||
translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.",
|
translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.",
|
||||||
|
autoTranslateCachedOnly: "If enabled, it will automatically translate only the text that the user has translated previously.",
|
||||||
},
|
},
|
||||||
setup: {
|
setup: {
|
||||||
chooseProvider: "Choose AI Provider",
|
chooseProvider: "Choose AI Provider",
|
||||||
@@ -811,4 +812,5 @@ export const languageEnglish = {
|
|||||||
translateBeforeHTMLFormatting: "Translate Before HTML Formatting",
|
translateBeforeHTMLFormatting: "Translate Before HTML Formatting",
|
||||||
retranslate: "Retranslate",
|
retranslate: "Retranslate",
|
||||||
loading: "Loading",
|
loading: "Loading",
|
||||||
|
autoTranslateCachedOnly: "Auto Translate Cached Only",
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
import { type MessageGenerationInfo } from "../../ts/storage/database.svelte";
|
import { type MessageGenerationInfo } from "../../ts/storage/database.svelte";
|
||||||
import { alertStore, DBState } from 'src/ts/stores.svelte';
|
import { alertStore, DBState } from 'src/ts/stores.svelte';
|
||||||
import { HideIconStore, ReloadGUIPointer, selIdState } from "../../ts/stores.svelte";
|
import { HideIconStore, ReloadGUIPointer, selIdState } from "../../ts/stores.svelte";
|
||||||
import { translateHTML } from "../../ts/translator/translator";
|
import { translateHTML, getLLMCache } from "../../ts/translator/translator";
|
||||||
import { risuChatParser } from "src/ts/process/scripts";
|
import { risuChatParser } from "src/ts/process/scripts";
|
||||||
import { type Unsubscriber } from "svelte/store";
|
import { type Unsubscriber } from "svelte/store";
|
||||||
import { get, isEqual, startsWith } from "lodash";
|
import { get, isEqual, startsWith } from "lodash";
|
||||||
@@ -140,7 +140,15 @@
|
|||||||
translateText = false
|
translateText = false
|
||||||
try {
|
try {
|
||||||
if(DBState.db.autoTranslate){
|
if(DBState.db.autoTranslate){
|
||||||
translateText = true
|
if(DBState.db.autoTranslateCachedOnly && DBState.db.translatorType === "llm"){
|
||||||
|
const cache = await getLLMCache(data)
|
||||||
|
if(cache !== null){
|
||||||
|
translateText = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
translateText = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -158,5 +158,11 @@
|
|||||||
<Help key="translateBeforeHTMLFormatting"/>
|
<Help key="translateBeforeHTMLFormatting"/>
|
||||||
</Check>
|
</Check>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center mt-4">
|
||||||
|
<Check bind:check={DBState.db.autoTranslateCachedOnly} name={language.autoTranslateCachedOnly}>
|
||||||
|
<Help key="autoTranslateCachedOnly"/>
|
||||||
|
</Check>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -846,6 +846,7 @@ export interface Database{
|
|||||||
otherAx: SeparateParameters
|
otherAx: SeparateParameters
|
||||||
}
|
}
|
||||||
translateBeforeHTMLFormatting:boolean
|
translateBeforeHTMLFormatting:boolean
|
||||||
|
autoTranslateCachedOnly:boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SeparateParameters{
|
interface SeparateParameters{
|
||||||
|
|||||||
@@ -507,4 +507,8 @@ async function translateLLM(text:string, arg:{to:string, regenerate?:boolean}):P
|
|||||||
}).replace(/<\/style-data>/g, '')
|
}).replace(/<\/style-data>/g, '')
|
||||||
await LLMCacheStorage.setItem(text, result)
|
await LLMCacheStorage.setItem(text, result)
|
||||||
return result
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLLMCache(text:string):Promise<string | null>{
|
||||||
|
return await LLMCacheStorage.getItem(text)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user