mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-05 19:15:34 +00:00
fix: drop chatgpt account
This commit is contained in:
parent
8cf4124986
commit
fcbfd37030
@ -43,7 +43,6 @@ bilingual_book_maker 是一个 AI 翻译工具,使用 ChatGPT 帮助用户制
|
|||||||
你也可以用环境以下环境变量来配置 `system` 和 `user` 角色 prompt:`BBM_CHATGPTAPI_USER_MSG_TEMPLATE` 和 `BBM_CHATGPTAPI_SYS_MSG`。
|
你也可以用环境以下环境变量来配置 `system` 和 `user` 角色 prompt:`BBM_CHATGPTAPI_USER_MSG_TEMPLATE` 和 `BBM_CHATGPTAPI_SYS_MSG`。
|
||||||
该参数可以是提示模板字符串,也可以是模板 `.txt` 文件的路径。
|
该参数可以是提示模板字符串,也可以是模板 `.txt` 文件的路径。
|
||||||
- 使用`--batch_size` 参数,指定批量翻译的行数(默认行数为10,目前只对txt生效)
|
- 使用`--batch_size` 参数,指定批量翻译的行数(默认行数为10,目前只对txt生效)
|
||||||
- 新增 model chatgptaccount,使用`--chatgptaccount`、`--chatgptpassword`传入 ChatGPT PLUS 账号密码进行翻译,不需要传key。
|
|
||||||
|
|
||||||
### 示范用例
|
### 示范用例
|
||||||
|
|
||||||
@ -81,8 +80,6 @@ python3 make_book.py --book_name test_books/the_little_prince.txt --test
|
|||||||
# 聚合多行翻译 txt 文件
|
# 聚合多行翻译 txt 文件
|
||||||
python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch_size 20
|
python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch_size 20
|
||||||
|
|
||||||
# chatgpt account model 翻译
|
|
||||||
python3 make_book.py --book_name test_books/animal_farm.epub --model chatgptaccount --chatgptaccount=xx--chatgptpassword xx
|
|
||||||
|
|
||||||
# 使用彩云小译翻译(彩云api目前只支持: 简体中文 <-> 英文, 简体中文 <-> 日语)
|
# 使用彩云小译翻译(彩云api目前只支持: 简体中文 <-> 英文, 简体中文 <-> 日语)
|
||||||
# 彩云提供了测试token(3975l6lr5pcbvidl6jl2)
|
# 彩云提供了测试token(3975l6lr5pcbvidl6jl2)
|
||||||
|
@ -49,7 +49,6 @@ 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>
|
`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:
|
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'`
|
`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'`
|
||||||
- - Add model chatgptaccount, use `--chatgptaccount`, `--chatgptpassword` to pass in ChatGPT PLUS account password for translation, no need to pass key.
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
**Note if use `pip install bbook_maker` all commands can change to `bbook args`**
|
**Note if use `pip install bbook_maker` all commands can change to `bbook args`**
|
||||||
@ -95,9 +94,6 @@ python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch
|
|||||||
# you can apply your own token by following this tutorial(https://bobtranslate.com/service/translate/caiyun.html)
|
# you can apply your own token by following this tutorial(https://bobtranslate.com/service/translate/caiyun.html)
|
||||||
python3 make_book.py --model caiyun --openai_key 3975l6lr5pcbvidl6jl2 --book_name test_books/animal_farm.epub
|
python3 make_book.py --model caiyun --openai_key 3975l6lr5pcbvidl6jl2 --book_name test_books/animal_farm.epub
|
||||||
|
|
||||||
#chatgptaccount model translate
|
|
||||||
python3 make_book.py --book_name test_books/animal_farm.epub --model chatgptaccount --chatgptaccount=xx--chatgptpassword xx
|
|
||||||
|
|
||||||
|
|
||||||
# Set env BBM_CAIYUN_API_KEY to ignore option --openai_key
|
# Set env BBM_CAIYUN_API_KEY to ignore option --openai_key
|
||||||
export BBM_CAIYUN_API_KEY=${your_api_key}
|
export BBM_CAIYUN_API_KEY=${your_api_key}
|
||||||
|
@ -231,21 +231,6 @@ So you are close to reaching the limit. You have to choose your own value, there
|
|||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--chatgptaccount",
|
|
||||||
dest="chatgptaccount",
|
|
||||||
type=str,
|
|
||||||
help="your chatgpt account",
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--chatgptpassword",
|
|
||||||
dest="chatgptpassword",
|
|
||||||
type=str,
|
|
||||||
help="your chatgpt password",
|
|
||||||
)
|
|
||||||
chatgpt_account = ""
|
|
||||||
chatgpt_password = ""
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
if not os.path.isfile(options.book_name):
|
if not os.path.isfile(options.book_name):
|
||||||
@ -283,11 +268,6 @@ So you are close to reaching the limit. You have to choose your own value, there
|
|||||||
API_KEY = options.deepl_key or env.get("BBM_DEEPL_API_KEY")
|
API_KEY = options.deepl_key or env.get("BBM_DEEPL_API_KEY")
|
||||||
if not API_KEY:
|
if not API_KEY:
|
||||||
raise Exception("Please provid deepl key")
|
raise Exception("Please provid deepl key")
|
||||||
elif options.model == "chatgptaccount":
|
|
||||||
chatgpt_account = options.chatgptaccount
|
|
||||||
chatgpt_password = options.chatgptpassword
|
|
||||||
if chatgpt_account is None or chatgpt_password is None:
|
|
||||||
raise Exception("Please provid chatgptaccount and chatgptpassword")
|
|
||||||
else:
|
else:
|
||||||
API_KEY = ""
|
API_KEY = ""
|
||||||
|
|
||||||
@ -328,8 +308,6 @@ So you are close to reaching the limit. You have to choose your own value, there
|
|||||||
is_test=options.test,
|
is_test=options.test,
|
||||||
test_num=options.test_num,
|
test_num=options.test_num,
|
||||||
prompt_config=parse_prompt_arg(options.prompt_arg),
|
prompt_config=parse_prompt_arg(options.prompt_arg),
|
||||||
chatgptaccount=chatgpt_account,
|
|
||||||
chatgptpassword=chatgpt_password,
|
|
||||||
)
|
)
|
||||||
# other options
|
# other options
|
||||||
if options.allow_navigable_strings:
|
if options.allow_navigable_strings:
|
||||||
|
@ -29,8 +29,6 @@ class EPUBBookLoader(BaseBookLoader):
|
|||||||
is_test=False,
|
is_test=False,
|
||||||
test_num=5,
|
test_num=5,
|
||||||
prompt_config=None,
|
prompt_config=None,
|
||||||
chatgptaccount=None,
|
|
||||||
chatgptpassword=None,
|
|
||||||
):
|
):
|
||||||
self.epub_name = epub_name
|
self.epub_name = epub_name
|
||||||
self.new_epub = epub.EpubBook()
|
self.new_epub = epub.EpubBook()
|
||||||
@ -38,8 +36,6 @@ class EPUBBookLoader(BaseBookLoader):
|
|||||||
key,
|
key,
|
||||||
language,
|
language,
|
||||||
api_base=model_api_base,
|
api_base=model_api_base,
|
||||||
chatgptaccount=chatgptaccount,
|
|
||||||
chatgptpassword=chatgptpassword,
|
|
||||||
**prompt_config_to_kwargs(prompt_config),
|
**prompt_config_to_kwargs(prompt_config),
|
||||||
)
|
)
|
||||||
self.is_test = is_test
|
self.is_test = is_test
|
||||||
|
@ -18,16 +18,12 @@ class TXTBookLoader(BaseBookLoader):
|
|||||||
is_test=False,
|
is_test=False,
|
||||||
test_num=5,
|
test_num=5,
|
||||||
prompt_config=None,
|
prompt_config=None,
|
||||||
chatgptaccount=None,
|
|
||||||
chatgptpassword=None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.txt_name = txt_name
|
self.txt_name = txt_name
|
||||||
self.translate_model = model(
|
self.translate_model = model(
|
||||||
key,
|
key,
|
||||||
language,
|
language,
|
||||||
api_base=model_api_base,
|
api_base=model_api_base,
|
||||||
chatgptaccount=chatgptaccount,
|
|
||||||
chatgptpassword=chatgptpassword,
|
|
||||||
**prompt_config_to_kwargs(prompt_config),
|
**prompt_config_to_kwargs(prompt_config),
|
||||||
)
|
)
|
||||||
self.is_test = is_test
|
self.is_test = is_test
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from book_maker.translator.caiyun_translator import Caiyun
|
from book_maker.translator.caiyun_translator import Caiyun
|
||||||
from book_maker.translator.chatgpt_account_translator import ChatGPTAccount
|
|
||||||
from book_maker.translator.chatgptapi_translator import ChatGPTAPI
|
from book_maker.translator.chatgptapi_translator import ChatGPTAPI
|
||||||
from book_maker.translator.deepl_translator import DeepL
|
from book_maker.translator.deepl_translator import DeepL
|
||||||
from book_maker.translator.google_translator import Google
|
from book_maker.translator.google_translator import Google
|
||||||
@ -11,6 +10,5 @@ MODEL_DICT = {
|
|||||||
"google": Google,
|
"google": Google,
|
||||||
"caiyun": Caiyun,
|
"caiyun": Caiyun,
|
||||||
"deepl": DeepL,
|
"deepl": DeepL,
|
||||||
"chatgptaccount": ChatGPTAccount,
|
|
||||||
# add more here
|
# add more here
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
import re
|
|
||||||
from revChatGPT.V1 import Chatbot
|
|
||||||
from rich import print
|
|
||||||
|
|
||||||
from .base_translator import Base
|
|
||||||
|
|
||||||
|
|
||||||
class ChatGPTAccount(Base):
|
|
||||||
def __init__(self, key, language, **kwargs):
|
|
||||||
super().__init__(key, language)
|
|
||||||
self.language = language
|
|
||||||
self.chatgpt_account = kwargs.get("chatgptaccount")
|
|
||||||
self.chatgpt_password = kwargs.get("chatgptpassword")
|
|
||||||
|
|
||||||
def rotate_key(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def translate(self, text):
|
|
||||||
print(text)
|
|
||||||
chatbot = Chatbot(
|
|
||||||
config={
|
|
||||||
"email": self.chatgpt_account,
|
|
||||||
"password": self.chatgpt_password,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
prompt = f"Please help me to translate,`{text}` to {self.language}"
|
|
||||||
t_text = ""
|
|
||||||
|
|
||||||
for data in chatbot.ask(prompt):
|
|
||||||
t_text = data["message"].encode("utf8").decode()
|
|
||||||
|
|
||||||
print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
|
|
||||||
return t_text
|
|
Loading…
x
Reference in New Issue
Block a user