This project demonstrates a batch processing implementation that enables LLMs to translate documents into multiple languages simultaneously. It's designed to efficiently handle the translation of markdown files while preserving formatting.
- Translates markdown content into multiple languages in parallel
- Saves translated files to specified output directory
- Install the required packages:
pip install -r requirements.txt- Set up your API key:
export ANTHROPIC_API_KEY="your-api-key-here"- Run the translation process:
python main.pyThe implementation uses a TranslateTextNode that processes batches of translation requests:
flowchart LR
batch[TranslateTextNode]
The TranslateTextNode:
- Prepares batches for multiple language translations
- Executes translations in parallel using the model
- Saves the translated content to individual files
- Maintains the original markdown structure
This approach demonstrates how PocketFlow can efficiently process multiple related tasks in parallel.
When you run the translation process, you'll see output similar to this:
Translated Chinese text
Translated Spanish text
Translated Japanese text
Translated German text
Translated Russian text
Translated Portuguese text
Translated French text
Translated Korean text
Saved translation to translations/README_CHINESE.md
Saved translation to translations/README_SPANISH.md
Saved translation to translations/README_JAPANESE.md
Saved translation to translations/README_GERMAN.md
Saved translation to translations/README_RUSSIAN.md
Saved translation to translations/README_PORTUGUESE.md
Saved translation to translations/README_FRENCH.md
Saved translation to translations/README_KOREAN.md
=== Translation Complete ===
Translations saved to: translations
============================
main.py: Implementation of the batch translation nodeutils.py: Simple wrapper for calling the Anthropic modelrequirements.txt: Project dependencies
The translations are saved to the translations directory, with each file named according to the target language.