mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-05 19:15:34 +00:00
update README
This commit is contained in:
parent
147819eaf4
commit
088d6e7d2d
140
README-CN.md
140
README-CN.md
@ -4,7 +4,6 @@ bilingual_book_maker 是一个 AI 翻译工具,使用 ChatGPT 帮助用户制
|
||||
|
||||

|
||||
|
||||
|
||||
## 准备
|
||||
|
||||
1. ChatGPT or OpenAI token [^token]
|
||||
@ -12,44 +11,113 @@ bilingual_book_maker 是一个 AI 翻译工具,使用 ChatGPT 帮助用户制
|
||||
3. 能正常联网的环境或 proxy
|
||||
4. python3.8+
|
||||
|
||||
## 快速开始
|
||||
|
||||
## 使用
|
||||
本地放了一个 `test_books/animal_farm.epub` 给大家测试
|
||||
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
|
||||
或
|
||||
pip install -U bbook_maker
|
||||
bbook --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
|
||||
```
|
||||
|
||||
## 翻译服务
|
||||
|
||||
- `pip install -r requirements.txt` 或 `pip install -U bbook_maker`
|
||||
- 使用 `--openai_key` 指定 OpenAI API key,如果有多个可以用英文逗号分隔(xxx,xxx,xxx),可以减少接口调用次数限制带来的错误。
|
||||
或者,指定环境变量 `BBM_OPENAI_API_KEY` 来略过这个选项。
|
||||
- 本地放了一个 `test_books/animal_farm.epub` 给大家测试
|
||||
- 默认用了 [GPT-3.5-turbo](https://openai.com/blog/introducing-chatgpt-and-whisper-apis) 模型,也就是 ChatGPT 正在使用的模型。
|
||||
- 可以使用 DeepL 封装的 api 进行翻译,需要付费,[DeepL Translator](https://rapidapi.com/splintPRO/api/dpl-translator) 来获得 token `--model deepl --deepl_key ${deepl_key}`
|
||||
- 可以使用 DeepL free `--model deeplfree`
|
||||
- 可以使用 [Claude](https://console.anthropic.com/docs) 模型进行翻译 `--model claude --claude_key ${claude_key}`
|
||||
- 可以使用 google 来翻译 `--model google`
|
||||
- 可以使用彩云进行翻译 `--model caiyun --caiyun_key ${caiyun_key}`
|
||||
- 可以使用 Gemini 进行翻译 `--model gemini --gemini_key ${gemini_key}`
|
||||
- 可以使用腾讯交互翻译(免费)进行翻译`--model tencentransmart`
|
||||
- 可以使用[xAI](https://x.ai)进行翻译`--model xai --xai_key ${xai_key}`
|
||||
- 可以使用 [Ollama](https://github.com/ollama/ollama) 自托管模型进行翻译,使用 `--ollama_model ${ollama_model_name}`
|
||||
- 如果 ollama server 不运行在本地,使用 `--api_base http://x.x.x.x:port/v1` 指向 ollama server 地址
|
||||
- 使用 `--test` 命令如果大家没付费可以加上这个先看看效果(有 limit 稍微有些慢)
|
||||
- 使用 `--language` 指定目标语言,例如: `--language "Simplified Chinese"`,预设值为 `"Simplified Chinese"`.
|
||||
请阅读 helper message 来查找可用的目标语言: `python make_book.py --help`
|
||||
- 使用 `--proxy` 参数,方便中国大陆的用户在本地测试时使用代理,传入类似 `http://127.0.0.1:7890` 的字符串
|
||||
- 使用 `--resume` 命令,可以手动中断后,加入命令继续执行。
|
||||
- epub 由 html 文件组成。默认情况下,我们只翻译 `<p>` 中的内容。
|
||||
使用 `--translate-tags` 指定需要翻译的标签。使用逗号分隔多个标签。例如:
|
||||
`--translate-tags h1,h2,h3,p,div`
|
||||
- 请使用 --book_from 选项指定电子阅读器类型(现在只有 kobo 可用),并使用 --device_path 指定挂载点。
|
||||
- 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。
|
||||
**请注意,此处你输入的api应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
|
||||
- 翻译完会生成一本 ${book_name}_bilingual.epub 的双语书
|
||||
- 如果出现了错误或使用 `CTRL+C` 中断命令,不想接下来继续翻译了,会生成一本 ${book_name}_bilingual_temp.epub 的书,直接改成你想要的名字就可以了
|
||||
- 如果你想要翻译电子书中的无标签字符串,可以使用 `--allow_navigable_strings` 参数,会将可遍历字符串加入翻译队列,**注意,在条件允许情况下,请寻找更规范的电子书**
|
||||
- 如果你想调整 prompt,你可以使用 `--prompt` 参数。有效的占位符包括 `{text}` 和 `{language}`。你可以用以下方式配置 prompt:
|
||||
|
||||
* DeepL
|
||||
使用 DeepL 封装的 api 进行翻译,需要付费。[DeepL Translator](https://rapidapi.com/splintPRO/api/dpl-translator) 来获得 token
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model deepl --deepl_key ${deepl_key}
|
||||
```
|
||||
|
||||
* DeepL free
|
||||
使用 DeepL free
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model deeplfree
|
||||
```
|
||||
|
||||
* Claude
|
||||
使用 [Claude](https://console.anthropic.com/docs) 模型进行翻译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model claude --claude_key ${claude_key}
|
||||
```
|
||||
|
||||
* 谷歌翻译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model google
|
||||
```
|
||||
|
||||
* 彩云小译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model caiyun --caiyun_key ${caiyun_key}
|
||||
```
|
||||
|
||||
* Gemini
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model gemini --gemini_key ${gemini_key}
|
||||
```
|
||||
|
||||
* 腾讯交互翻译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model tencentransmart
|
||||
```
|
||||
|
||||
* [xAI](https://x.ai)
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model xai --xai_key ${xai_key}
|
||||
```
|
||||
|
||||
* [Ollama](https://github.com/ollama/ollama)
|
||||
使用 [Ollama](https://github.com/ollama/ollama) 自托管模型进行翻译。
|
||||
如果 ollama server 不运行在本地,使用 `--api_base http://x.x.x.x:port/v1` 指向 ollama server 地址
|
||||
|
||||
```shell
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --ollama_model ${ollama_model_name}
|
||||
```
|
||||
|
||||
* groq
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --groq_key [your_key] --model groq --model_list llama3-8b-8192
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
- 翻译完会生成一本 `{book_name}_bilingual.epub` 的双语书
|
||||
- 如果出现了错误或使用 `CTRL+C` 中断命令,不想接下来继续翻译了,会生成一本 `{book_name}_bilingual_temp.epub` 的书,直接改成你想要的名字就可以了
|
||||
|
||||
## 参数说明
|
||||
|
||||
- `--test`: 如果大家没付费可以加上这个先看看效果(有 limit 稍微有些慢)
|
||||
- `--language`: 指定目标语言
|
||||
- 例如: `--language "Simplified Chinese"`,预设值为 `"Simplified Chinese"`.
|
||||
- 请阅读 helper message 来查找可用的目标语言: `python make_book.py --help`
|
||||
- `--proxy` 参数,方便中国大陆的用户在本地测试时使用代理,传入类似 `http://127.0.0.1:7890` 的字符串
|
||||
- 使用`--batch_size` 参数,指定批量翻译的行数(默认行数为 10,目前只对 txt 生效)
|
||||
- `--resume` 命令,可以手动中断后,加入命令继续执行。
|
||||
- `--translate-tags` 指定需要翻译的标签,使用逗号分隔多个标签。epub 由 html 文件组成,默认情况下,只翻译 `<p>` 中的内容。例如: `--translate-tags h1,h2,h3,p,div`
|
||||
- `--book_from` 选项指定电子阅读器类型(现在只有 kobo 可用),并使用 `--device_path` 指定挂载点。
|
||||
- `--api_base ${url}`: 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。
|
||||
**请注意,此处你输入的 api 应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
|
||||
- `--allow_navigable_strings`: 如果你想要翻译电子书中的无标签字符串,可以使用 `--allow_navigable_strings` 参数,会将可遍历字符串加入翻译队列,**注意,在条件允许情况下,请寻找更规范的电子书**
|
||||
- `--prompt`: 如果你想调整 prompt,你可以使用 `--prompt` 参数。有效的占位符包括 `{text}` 和 `{language}`。你可以用以下方式配置 prompt:
|
||||
如果您不需要设置 `system` 角色,可以这样:`--prompt "Translate {text} to {language}"` 或者 `--prompt prompt_template_sample.txt`(示例文本文件可以在 [./prompt_template_sample.txt](./prompt_template_sample.txt) 找到)。
|
||||
如果您需要设置 `system` 角色,可以使用以下方式配置:`--prompt '{"user":"Translate {text} to {language}", "system": "You are a professional translator."}'`,或者 `--prompt prompt_template_sample.json`(示例 JSON 文件可以在 [./prompt_template_sample.json](./prompt_template_sample.json) 找到)。
|
||||
你也可以用环境以下环境变量来配置 `system` 和 `user` 角色 prompt:`BBM_CHATGPTAPI_USER_MSG_TEMPLATE` 和 `BBM_CHATGPTAPI_SYS_MSG`。
|
||||
该参数可以是提示模板字符串,也可以是模板 `.txt` 文件的路径。
|
||||
- 使用`--batch_size` 参数,指定批量翻译的行数(默认行数为10,目前只对txt生效)
|
||||
该参数可以是提示模板字符串,也可以是模板 `.txt` 文件的路径。
|
||||
|
||||
### 示范用例
|
||||
|
||||
@ -99,10 +167,10 @@ python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch
|
||||
python3 make_book.py --model caiyun --caiyun_key 3975l6lr5pcbvidl6jl2 --book_name test_books/animal_farm.epub
|
||||
# 可以在环境变量中设置BBM_CAIYUN_API_KEY,略过--openai_key
|
||||
export BBM_CAIYUN_API_KEY=${your_api_key}
|
||||
|
||||
```
|
||||
|
||||
更加小白的示例
|
||||
|
||||
```shell
|
||||
python3 make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'
|
||||
|
||||
@ -110,12 +178,11 @@ python3 make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_
|
||||
python make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'
|
||||
```
|
||||
|
||||
|
||||
[演示视频](https://www.bilibili.com/video/BV1XX4y1d75D/?t=0h07m08s)
|
||||
[演示视频2](https://www.bilibili.com/video/BV1T8411c7iU/)
|
||||
|
||||
[演示视频 2](https://www.bilibili.com/video/BV1T8411c7iU/)
|
||||
|
||||
使用 Azure OpenAI service
|
||||
|
||||
```shell
|
||||
python3 make_book.py --book_name 'animal_farm.epub' --openai_key XXXXX --api_base 'https://example-endpoint.openai.azure.com' --deployment_id 'deployment-name'
|
||||
|
||||
@ -123,14 +190,11 @@ python3 make_book.py --book_name 'animal_farm.epub' --openai_key XXXXX --api_bas
|
||||
python make_book.py --book_name 'animal_farm.epub' --openai_key XXXXX --api_base 'https://example-endpoint.openai.azure.com' --deployment_id 'deployment-name'
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 注意
|
||||
|
||||
1. Free trail 的 API token 有所限制,如果想要更快的速度,可以考虑付费方案
|
||||
2. 欢迎提交 PR
|
||||
|
||||
|
||||
# 感谢
|
||||
|
||||
- @[yetone](https://github.com/yetone)
|
||||
|
132
README.md
132
README.md
@ -2,11 +2,13 @@
|
||||
[](https://github.com/BerriAI/litellm)
|
||||
|
||||
# bilingual_book_maker
|
||||
|
||||
The bilingual_book_maker is an AI translation tool that uses ChatGPT to assist users in creating multi-language versions of epub/txt/srt files and books. This tool is exclusively designed for translating epub books that have entered the public domain and is not intended for copyrighted works. Before using this tool, please review the project's **[disclaimer](./disclaimer.md)**.
|
||||
|
||||

|
||||
|
||||
## Supported Models
|
||||
|
||||
gpt-4, gpt-3.5-turbo, claude-2, palm, llama-2, azure-openai, command-nightly, gemini
|
||||
For using Non-OpenAI models, use class `liteLLM()` - liteLLM supports all models above.
|
||||
Find more info here for using liteLLM: https://github.com/BerriAI/litellm/blob/main/setup.py
|
||||
@ -18,47 +20,116 @@ Find more info here for using liteLLM: https://github.com/BerriAI/litellm/blob/m
|
||||
3. Environment with internet access or proxy
|
||||
4. Python 3.8+
|
||||
|
||||
## Use
|
||||
## Quick Start
|
||||
|
||||
A sample book, `test_books/animal_farm.epub`, is provided for testing purposes.
|
||||
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
|
||||
OR
|
||||
pip install -U bbook_maker
|
||||
bbook --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
|
||||
```
|
||||
|
||||
## Translate Service
|
||||
|
||||
- `pip install -r requirements.txt` or `pip install -U bbook_maker`(you can use)
|
||||
- Use `--openai_key` option to specify OpenAI API key. If you have multiple keys, separate them by commas (xxx,xxx,xxx) to reduce errors caused by API call limits.
|
||||
Or, just set environment variable `BBM_OPENAI_API_KEY` instead.
|
||||
- A sample book, `test_books/animal_farm.epub`, is provided for testing purposes.
|
||||
- The default underlying model is [GPT-3.5-turbo](https://openai.com/blog/introducing-chatgpt-and-whisper-apis), which is used by ChatGPT currently. Use `--model gpt4` to change the underlying model to `GPT4`. You can also use `GPT4omini`.
|
||||
- Important to note that `gpt-4` is significantly more expensive than `gpt-4-turbo`, but to avoid bumping into rate limits, we automatically balance queries across `gpt-4-1106-preview`, `gpt-4`, `gpt-4-32k`, `gpt-4-0613`,`gpt-4-32k-0613`.
|
||||
- If you want to use a specific model alias with OpenAI (eg `gpt-4-1106-preview` or `gpt-3.5-turbo-0125`), you can use `--model openai --model_list gpt-4-1106-preview,gpt-3.5-turbo-0125`. `--model_list` takes a comma-separated list of model aliases.
|
||||
- If using chatgptapi, you can add `--use_context` to add a context paragraph to each passage sent to the model for translation (see below).
|
||||
- Support DeepL model [DeepL Translator](https://rapidapi.com/splintPRO/api/dpl-translator) need pay to get the token use `--model deepl --deepl_key ${deepl_key}`
|
||||
- Support DeepL free model `--model deeplfree`
|
||||
- Support Google [Gemini](https://aistudio.google.com/app/apikey) model, use `--model gemini` for Gemini Flash or `--model geminipro` for Gemini Pro. `--gemini_key ${gemini_key}`
|
||||
- If you want to use a specific model alias with Gemini (eg `gemini-1.5-flash-002` or `gemini-1.5-flash-8b-exp-0924`), you can use `--model gemini --model_list gemini-1.5-flash-002,gemini-1.5-flash-8b-exp-0924`. `--model_list` takes a comma-separated list of model aliases.
|
||||
- Support [Claude](https://console.anthropic.com/docs) model, use `--model claude --claude_key ${claude_key}`
|
||||
- Support [Tencent TranSmart](https://transmart.qq.com) model (Free), use `--model tencentransmart`
|
||||
- Support [xAI](https://x.ai) model, use `--model xai --xai_key ${xai_key}`
|
||||
- Support [Ollama](https://github.com/ollama/ollama) self-host models, use `--ollama_model ${ollama_model_name}`
|
||||
- If ollama server is not running on localhost, use `--api_base http://x.x.x.x:port/v1` to point to the ollama server address
|
||||
- Important to note that `gpt-4` is significantly more expensive than `gpt-4-turbo`, but to avoid bumping into rate limits, we automatically balance queries across `gpt-4-1106-preview`, `gpt-4`, `gpt-4-32k`, `gpt-4-0613`,`gpt-4-32k-0613`.
|
||||
- If you want to use a specific model alias with OpenAI (eg `gpt-4-1106-preview` or `gpt-3.5-turbo-0125`), you can use `--model openai --model_list gpt-4-1106-preview,gpt-3.5-turbo-0125`. `--model_list` takes a comma-separated list of model aliases.
|
||||
- If using chatgptapi, you can add `--use_context` to add a context paragraph to each passage sent to the model for translation (see below).
|
||||
|
||||
* DeepL
|
||||
Support DeepL model [DeepL Translator](https://rapidapi.com/splintPRO/api/dpl-translator) need pay to get the token
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model deepl --deepl_key ${deepl_key}
|
||||
```
|
||||
|
||||
* DeepL free
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model deeplfree
|
||||
```
|
||||
|
||||
* [Claude](https://console.anthropic.com/docs)
|
||||
使用 [Claude](https://console.anthropic.com/docs) 模型进行翻译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model claude --claude_key ${claude_key}
|
||||
```
|
||||
|
||||
* 谷歌翻译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model google
|
||||
```
|
||||
|
||||
* 彩云小译
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model caiyun --caiyun_key ${caiyun_key}
|
||||
```
|
||||
|
||||
* Gemini
|
||||
Support Google [Gemini](https://aistudio.google.com/app/apikey) model, use `--model gemini` for Gemini Flash or `--model geminipro` for Gemini Pro.
|
||||
If you want to use a specific model alias with Gemini (eg `gemini-1.5-flash-002` or `gemini-1.5-flash-8b-exp-0924`), you can use `--model gemini --model_list gemini-1.5-flash-002,gemini-1.5-flash-8b-exp-0924`. `--model_list` takes a comma-separated list of model aliases.
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model gemini --gemini_key ${gemini_key}
|
||||
```
|
||||
|
||||
* [Tencent TranSmart](https://transmart.qq.com)
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model tencentransmart
|
||||
```
|
||||
|
||||
* [xAI](https://x.ai)
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --model xai --xai_key ${xai_key}
|
||||
```
|
||||
|
||||
* Support [Ollama](https://github.com/ollama/ollama) self-host models,
|
||||
If ollama server is not running on localhost, use `--api_base http://x.x.x.x:port/v1` to point to the ollama server address
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --ollama_model ${ollama_model_name}
|
||||
```
|
||||
|
||||
* groq
|
||||
|
||||
```
|
||||
python3 make_book.py --book_name test_books/animal_farm.epub --groq_key [your_key] --model groq --model_list llama3-8b-8192
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
- Once the translation is complete, a bilingual book named `${book_name}_bilingual.epub` would be generated.
|
||||
- If there are any errors or you wish to interrupt the translation by pressing `CTRL+C`. A book named `{book_name}_bilingual_temp.epub` would be generated. You can simply rename it to any desired name.
|
||||
|
||||
## Params
|
||||
|
||||
- Use `--test` option to preview the result if you haven't paid for the service. Note that there is a limit and it may take some time.
|
||||
- Set the target language like `--language "Simplified Chinese"`. Default target language is `"Simplified Chinese"`.
|
||||
Read available languages by helper message: `python make_book.py --help`
|
||||
- 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 `<p>`.
|
||||
- Use `--resume` option to manually resume the process after an interruption. -`--translate-tags`: epub is made of html files. By default, we only translate contents in `<p>`.
|
||||
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 <URL>` to support it.
|
||||
**Note: the api url should be '`https://xxxx/v1`'. Quotation marks are required.**
|
||||
- Once the translation is complete, a bilingual book named `${book_name}_bilingual.epub` would be generated.
|
||||
- If there are any errors or you wish to interrupt the translation by pressing `CTRL+C`. A book named `${book_name}_bilingual_temp.epub` would be generated. You can simply rename it to any desired name.
|
||||
- If you want to translate strings in an e-book that aren't labeled with any tags, you can use the `--allow_navigable_strings` parameter. This will add the strings to the translation queue. **Note that it's best to look for e-books that are more standardized if possible.**
|
||||
- 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:
|
||||
- Use `--book_from` option to specify e-reader type (Now only `kobo` is available), and use `--device_path` to specify the mounting point. -`--api_base`: If you want to change api_base like using Cloudflare Workers, use `--api_base <URL>` to support it.
|
||||
**Note: the api url should be '`https://xxxx/v1`'. Quotation marks are required.** -`--allow_navigable_strings`: If you want to translate strings in an e-book that aren't labeled with any tags, you can use the `--allow_navigable_strings` parameter. This will add the strings to the translation queue. **Note that it's best to look for e-books that are more standardized if possible.** -`--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` (example of a text file can be found at [./prompt_template_sample.txt](./prompt_template_sample.txt)).
|
||||
If you need to set the `system` role content, you can use the following format: `--prompt '{"user":"Translate {text} to {language}", "system": "You are a professional translator."}'` or `--prompt prompt_template_sample.json` (example of a JSON file can be found at [./prompt_template_sample.json](./prompt_template_sample.json)).
|
||||
You can also set the `user` and `system` role prompt by setting environment variables: `BBM_CHATGPTAPI_USER_MSG_TEMPLATE` and `BBM_CHATGPTAPI_SYS_MSG`.
|
||||
- Use the `--batch_size` parameter to specify the number of lines for batch translation (default is 10, currently only effective for txt files).
|
||||
- `--accumulated_num` Wait for how many tokens have been accumulated before starting the translation. gpt3.5 limits the total_token to 4090. For example, if you use --accumulated_num 1600, maybe openai will
|
||||
output 2200 tokens and maybe 200 tokens for other messages in the system messages user messages, 1600+2200+200=4000, So you are close to reaching the limit. You have to choose your own
|
||||
value, there is no way to know if the limit is reached before sending
|
||||
output 2200 tokens and maybe 200 tokens for other messages in the system messages user messages, 1600+2200+200=4000, So you are close to reaching the limit. You have to choose your own
|
||||
value, there is no way to know if the limit is reached before sending
|
||||
- `--use_context` prompts the model to create a three-paragraph summary. If it's the beginning of the translation, it will summarize the entire passage sent (the size depending on `--accumulated_num`). For subsequent passages, it will amend the summary to include details from the most recent passage, creating a running one-paragraph context payload of the important details of the entire translated work. This improves consistency of flow and tone throughout the translation. This option is available for all ChatGPT-compatible models and Gemini models.
|
||||
- Use `--context_paragraph_limit` to set a limit on the number of context paragraphs when using the `--use_context` option.
|
||||
- Use `--temperature` to set the temperature parameter for `chatgptapi`/`gpt4`/`claude` models. For example: `--temperature 0.7`.
|
||||
@ -66,10 +137,11 @@ value, there is no way to know if the limit is reached before sending
|
||||
- Use `--single_translate` to output only the translated book without creating a bilingual version.
|
||||
- `--translation_style` example: `--translation_style "color: #808080; font-style: italic;"`
|
||||
- `--retranslate` `--retranslate "$translated_filepath" "file_name_in_epub" "start_str" "end_str"(optional)`<br>
|
||||
Retranslate from start_str to end_str's tag:
|
||||
`python3 "make_book.py" --book_name "test_books/animal_farm.epub" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which' 'This kind of thing is not a good symptom. Obviously'`<br>
|
||||
Retranslate start_str's tag:
|
||||
`python3 "make_book.py" --book_name "test_books/animal_farm.epub" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which'`
|
||||
Retranslate from start_str to end_str's tag:
|
||||
`python3 "make_book.py" --book_name "test_books/animal_farm.epub" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which' 'This kind of thing is not a good symptom. Obviously'`<br>
|
||||
Retranslate start_str's tag:
|
||||
`python3 "make_book.py" --book_name "test_books/animal_farm.epub" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which'`
|
||||
|
||||
### Examples
|
||||
|
||||
**Note if use `pip install bbook_maker` all commands can change to `bbook_maker args`**
|
||||
@ -145,6 +217,7 @@ export BBM_CAIYUN_API_KEY=${your_api_key}
|
||||
```
|
||||
|
||||
More understandable example
|
||||
|
||||
```shell
|
||||
python3 make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'
|
||||
|
||||
@ -153,6 +226,7 @@ python make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_b
|
||||
```
|
||||
|
||||
Microsoft Azure Endpoints
|
||||
|
||||
```shell
|
||||
python3 make_book.py --book_name 'animal_farm.epub' --openai_key XXXXX --api_base 'https://example-endpoint.openai.azure.com' --deployment_id 'deployment-name'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user