From b4817f2c9b03ba96db36a0218933244c95f5eb7c Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Tue, 22 Aug 2023 19:36:53 +0800 Subject: [PATCH] feat: add github action to check spelling (#326) --- .github/workflows/make_test_ebook.yaml | 10 ++++++++++ README.md | 2 +- book_maker/cli.py | 8 ++++---- book_maker/translator/chatgptapi_translator.py | 2 +- book_maker/translator/gpt4_translator.py | 2 +- docs/book_source.md | 4 ++-- docs/prompt.md | 5 +++-- mkdocs.yml | 2 +- tests/test_integration.py | 2 +- typos.toml | 8 ++++++++ 10 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 typos.toml diff --git a/.github/workflows/make_test_ebook.yaml b/.github/workflows/make_test_ebook.yaml index 15b4eb5..76d6ac0 100644 --- a/.github/workflows/make_test_ebook.yaml +++ b/.github/workflows/make_test_ebook.yaml @@ -13,6 +13,16 @@ env: BBM_CAIYUN_API_KEY: ${{ secrets.BBM_CAIYUN_API_KEY }} jobs: + typos-check: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v3 + - name: Check spelling with custom config file + uses: crate-ci/typos@v1.16.6 + with: + config: ./typos.toml testing: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index bd21daa..75659fb 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Find more info here for using liteLLM: https://github.com/BerriAI/litellm/blob/m - Use `--proxy` option to specify proxy server for internet access. Enter a string such as `http://127.0.0.1:7890`. - Use `--resume` option to manually resume the process after an interruption. - epub is made of html files. By default, we only translate contents in `

`. - Use `--translate-tags` to specify tags need for translation. Use comma to seperate multiple tags. For example: + Use `--translate-tags` to specify tags need for translation. Use comma to separate multiple tags. For example: `--translate-tags h1,h2,h3,p,div` - Use `--book_from` option to specify e-reader type (Now only `kobo` is available), and use `--device_path` to specify the mounting point. - If you want to change api_base like using Cloudflare Workers, use `--api_base ` to support it. diff --git a/book_maker/cli.py b/book_maker/cli.py index 991e540..a640fac 100644 --- a/book_maker/cli.py +++ b/book_maker/cli.py @@ -274,7 +274,7 @@ So you are close to reaching the limit. You have to choose your own value, there options.openai_key or env.get( "OPENAI_API_KEY", - ) # XXX: for backward compatability, deprecate soon + ) # XXX: for backward compatibility, deprecate soon or env.get( "BBM_OPENAI_API_KEY", ) # suggest adding `BBM_` prefix for all the bilingual_book_maker ENVs. @@ -287,15 +287,15 @@ So you are close to reaching the limit. You have to choose your own value, there elif options.model == "caiyun": API_KEY = options.caiyun_key or env.get("BBM_CAIYUN_API_KEY") if not API_KEY: - raise Exception("Please provid caiyun key") + raise Exception("Please provide caiyun key") elif options.model == "deepl": API_KEY = options.deepl_key or env.get("BBM_DEEPL_API_KEY") if not API_KEY: - raise Exception("Please provid deepl key") + raise Exception("Please provide deepl key") elif options.model == "claude": API_KEY = options.claude_key or env.get("BBM_CLAUDE_API_KEY") if not API_KEY: - raise Exception("Please provid claude key") + raise Exception("Please provide claude key") else: API_KEY = "" diff --git a/book_maker/translator/chatgptapi_translator.py b/book_maker/translator/chatgptapi_translator.py index 62ea694..d23046e 100644 --- a/book_maker/translator/chatgptapi_translator.py +++ b/book_maker/translator/chatgptapi_translator.py @@ -41,7 +41,7 @@ class ChatGPTAPI(Base): prompt_sys_msg or environ.get( "OPENAI_API_SYS_MSG", - ) # XXX: for backward compatability, deprecate soon + ) # XXX: for backward compatibility, deprecate soon or environ.get(PROMPT_ENV_MAP["system"]) or "" ) diff --git a/book_maker/translator/gpt4_translator.py b/book_maker/translator/gpt4_translator.py index b648b6e..d3daeeb 100644 --- a/book_maker/translator/gpt4_translator.py +++ b/book_maker/translator/gpt4_translator.py @@ -44,7 +44,7 @@ class GPT4(Base): prompt_sys_msg or environ.get( "OPENAI_API_SYS_MSG", - ) # XXX: for backward compatability, deprecate soon + ) # XXX: for backward compatibility, deprecate soon or environ.get(PROMPT_ENV_MAP["system"]) or "" ) diff --git a/docs/book_source.md b/docs/book_source.md index c1afb74..1d9776c 100644 --- a/docs/book_source.md +++ b/docs/book_source.md @@ -6,7 +6,7 @@ Txt files and srt files are plain text files. This program can translate plain t python3 make_book.py --book_name test_books/the_little_prince.txt --test --language zh-hans ## epub -epub is made of html files. By default, we only translate contents in `

`. Use `--translate-tags` to specify tags need for translation. Use comma to seperate multiple tags. For example: `--translate-tags h1,h2,h3,p,div` +epub is made of html files. By default, we only translate contents in `

`. Use `--translate-tags` to specify tags need for translation. Use comma to separate multiple tags. For example: `--translate-tags h1,h2,h3,p,div` bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key} --translate-tags div,p @@ -17,4 +17,4 @@ If you want to translate strings in an e-book that aren't labeled with any tags, Use `--book_from` option to specify e-reader type (Now only `kobo` is available), and use `--device_path` to specify the mounting point. # Translate books download from Rakuten Kobo on kobo e-reader - bbook_maker --book_from kobo --device_path /tmp/kobo \ No newline at end of file + bbook_maker --book_from kobo --device_path /tmp/kobo diff --git a/docs/prompt.md b/docs/prompt.md index b616601..1b2b37c 100644 --- a/docs/prompt.md +++ b/docs/prompt.md @@ -1,4 +1,5 @@ -# Tweek the prompt +# Tweak the prompt + To tweak the prompt, use the `--prompt` parameter. Valid placeholders for the `user` role template include `{text}` and `{language}`. It supports a few ways to configure the prompt: - If you don't need to set the `system` role content, you can simply set it up like this: `--prompt "Translate {text} to {language}."` or `--prompt prompt_template_sample.txt` @@ -25,4 +26,4 @@ python3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_tem python3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_template_sample.json # or python3 make_book.py --book_name test_books/animal_farm.epub --prompt "Please translate \`{text}\` to {language}" -``` \ No newline at end of file +``` diff --git a/mkdocs.yml b/mkdocs.yml index b379f04..2cfd92d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -16,6 +16,6 @@ nav: - Command line options: cmd.md - Translate from different source: book_source.md - Environment setting: env_settings.md - - Tweek the prompt: prompt.md + - Tweak the prompt: prompt.md - Disclaimer: disclaimer.md \ No newline at end of file diff --git a/tests/test_integration.py b/tests/test_integration.py index ff3a064..03664b5 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -128,7 +128,7 @@ def test_google_translate_txt_batch_size(test_book_dir, tmpdir): reason="No BBM_CAIYUN_API_KEY in environment variable.", ) def test_caiyun_translate_txt(test_book_dir, tmpdir): - """Test caiyun tranlate txt""" + """Test caiyun translate txt""" shutil.copyfile( os.path.join(test_book_dir, "the_little_prince.txt"), os.path.join(tmpdir, "the_little_prince.txt"), diff --git a/typos.toml b/typos.toml new file mode 100644 index 0000000..c506f57 --- /dev/null +++ b/typos.toml @@ -0,0 +1,8 @@ +# See https://github.com/crate-ci/typos/blob/master/docs/reference.md to configure typos +[default.extend-words] +sur = "sur" +banch = "banch" # TODO: not sure if this is a typo or not +fo = "fo" +ba = "ba" +[files] +extend-exclude = ["LICENSE"]