For better results, you can use two different LLM instances: one optimized for creative translation and another optimized for maintaining XML structure (filling).
translation_llm: Use a higher temperature (e.g., 0.8) for more natural and creative language translation.fill_llm: Use a lower temperature (e.g., 0.3) to ensure strict adherence to the EPUB/XML structure during the filling process.
from epub_translator import LLM, translate, language, SubmitKind
translation_llm = LLM(
key="your-api-key",
url="https://api.openai.com/v1",
model="gpt-4",
token_encoding="o200k_base",
temperature=0.8,
)
fill_llm = LLM(
key="your-api-key",
url="https://api.openai.com/v1",
model="gpt-4",
token_encoding="o200k_base",
temperature=0.3,
)
translate(
source_path="source.epub",
target_path="translated.epub",
target_language=language.CHINESE,
submit=SubmitKind.APPEND_BLOCK,
translation_llm=translation_llm,
fill_llm=fill_llm,
)