Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flows/playground/flow.oo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ nodes:
value: 5
- handle: retry_interval_seconds
value: 6.5
- handle: write_mode
value: append
task: self::translator
title: Playground
4 changes: 2 additions & 2 deletions package.oo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ scripts:
dependencies:
{}
name: books-translator
version: 0.1.10
version: 0.1.11
displayName: Books Translator
description: Translate the epub book using LLM side by side.
releaseNotes: add groups & descriptions
releaseNotes: support the write_mode field
repository: https://github.com/oomol-flows/books-translater
529 changes: 267 additions & 262 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
requires-python = ">=3.10,<3.13"
dependencies = [
"requests (>=2.32.4,<3.0.0)",
"epub-translator (==0.0.6)",
"epub-translator (==0.0.7)",
]


Expand Down
12 changes: 11 additions & 1 deletion tasks/translator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pathlib import Path
from oocana import Context
from epub_translator import translate, LLM, Language
from epub_translator import translate, LLM, Language, TranslatedWriteMode


#region generated meta
Expand All @@ -13,6 +13,7 @@ class Inputs(typing.TypedDict):
source_file: str
translated_file: str | None
language: typing.Literal["zh-Hans", "zh-Hant", "en", "fr", "de", "es", "ru", "it", "pt", "ja", "ko"]
write_mode: typing.Literal["append", "replace"]
prompt: str | None
max_chunk_tokens: int
threads: int
Expand Down Expand Up @@ -55,6 +56,7 @@ def main(params: Inputs, context: Context) -> Outputs:
target_language=_parse_language_code(params["language"]),
user_prompt=params["prompt"],
working_path=working_path,
write_mode=_transform_write_mode(params["write_mode"]),
max_chunk_tokens_count=params["max_chunk_tokens"],
max_threads_count=params["threads"],
report_progress=lambda p: context.report_progress(100.0 * p),
Expand All @@ -63,6 +65,14 @@ def main(params: Inputs, context: Context) -> Outputs:
"translated_file": str(translated_file)
}

def _transform_write_mode(write_mode: str) -> TranslatedWriteMode:
if write_mode == "append":
return TranslatedWriteMode.APPEND
elif write_mode == "replace":
return TranslatedWriteMode.REPLACE
else:
raise ValueError(f"Invalid write mode: {write_mode}")

def _prepare_working_path(source_file: Path, context: Context) -> Path:
st_mtime = source_file.stat().st_mtime
hash = hashlib.new(name="sha512")
Expand Down
14 changes: 14 additions & 0 deletions tasks/translator/task.oo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ inputs_def:
- .epub
value:
nullable: true
- group: Translate
collapsed: false
- handle: language
description: Translation target language
json_schema:
Expand Down Expand Up @@ -57,6 +59,18 @@ inputs_def:
- Japanese
- Korean
value: zh-Hans
- handle: write_mode
json_schema:
enum:
- append
- replace
ui:options:
labels:
- Append
- Replace
description: 'How is the translation written into an EPUB file: Is it "append"
to the original text? Or does it "replace" the original text?'
value: append
- handle: prompt
description: Provide LLM with necessary information for translating books. For
example, you can fill in the glossary and character name specifications.
Expand Down