update: refine the text of messages to the end user (#100)

* update: refine the text of messages to the end user

* update: refine message text

* fix: lint

---------

Co-authored-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
Yurii 2023-03-08 11:24:05 +01:00 committed by GitHub
parent 6c72c29943
commit 3472f3e673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,34 +13,34 @@ def main():
"--book_name", "--book_name",
dest="book_name", dest="book_name",
type=str, type=str,
help="your epub book file path", help="path of the epub file to be translated",
) )
parser.add_argument( parser.add_argument(
"--openai_key", "--openai_key",
dest="openai_key", dest="openai_key",
type=str, type=str,
default="", default="",
help="openai api key,if you have more than one key,you can use comma" help="OpenAI api key,if you have more than one key, please use comma"
" to split them and you can break through the limitation", " to split them to go beyond the rate limits",
) )
parser.add_argument( parser.add_argument(
"--no_limit", "--no_limit",
dest="no_limit", dest="no_limit",
action="store_true", action="store_true",
help="If you are a paying customer you can add it", help="with a paid account, you can specify this option",
) )
parser.add_argument( parser.add_argument(
"--test", "--test",
dest="test", dest="test",
action="store_true", action="store_true",
help="if test we only translat 10 contents you can easily check", help="only the first 10 paragraphs will be translated, for testing",
) )
parser.add_argument( parser.add_argument(
"--test_num", "--test_num",
dest="test_num", dest="test_num",
type=int, type=int,
default=10, default=10,
help="test num for the test", help="how many paragraphs will be translated for testing",
) )
parser.add_argument( parser.add_argument(
"-m", "-m",
@ -50,7 +50,7 @@ def main():
default="chatgptapi", default="chatgptapi",
choices=["chatgptapi", "gpt3"], # support DeepL later choices=["chatgptapi", "gpt3"], # support DeepL later
metavar="MODEL", metavar="MODEL",
help="Which model to use, available: {%(choices)s}", help="model to use, available: {%(choices)s}",
) )
parser.add_argument( parser.add_argument(
"--language", "--language",
@ -65,7 +65,7 @@ def main():
"--resume", "--resume",
dest="resume", dest="resume",
action="store_true", action="store_true",
help="if program accidentally stop you can use this to resume", help="if program stop unexpected you can use this to resume",
) )
parser.add_argument( parser.add_argument(
"-p", "-p",
@ -80,7 +80,7 @@ def main():
"--api_base", "--api_base",
dest="api_base", dest="api_base",
type=str, type=str,
help="replace base url from openapi", help="specify base url other than the OpenAI's official API address",
) )
options = parser.parse_args() options = parser.parse_args()
@ -91,17 +91,19 @@ def main():
OPENAI_API_KEY = options.openai_key or env.get("OPENAI_API_KEY") OPENAI_API_KEY = options.openai_key or env.get("OPENAI_API_KEY")
if not OPENAI_API_KEY: if not OPENAI_API_KEY:
raise Exception("Need openai API key, please google how to") raise Exception("OpenAI API key not provided, please google how to obtain it")
book_type = options.book_name.split(".")[-1] book_type = options.book_name.split(".")[-1]
support_type_list = list(BOOK_LOADER_DICT.keys()) support_type_list = list(BOOK_LOADER_DICT.keys())
if book_type not in support_type_list: if book_type not in support_type_list:
raise Exception(f"now only support {','.join(support_type_list)} files") raise Exception(
f"now only support files of these formats: {','.join(support_type_list)}"
)
translate_model = MODEL_DICT.get(options.model) translate_model = MODEL_DICT.get(options.model)
assert translate_model is not None, "Not support model" assert translate_model is not None, "unsupported model"
book_loader = BOOK_LOADER_DICT.get(book_type) book_loader = BOOK_LOADER_DICT.get(book_type)
assert book_loader is not None, "Not support loader" assert book_loader is not None, "unsupported loader"
language = options.language language = options.language
if options.language in LANGUAGES: if options.language in LANGUAGES:
# use the value for prompt # use the value for prompt