From cb3779f2793f261ed0045351129161944a2c4186 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Sat, 27 Jan 2024 22:17:23 +0800 Subject: [PATCH] fix: 374 Signed-off-by: yihong0618 --- .gitignore | 4 ++++ book_maker/translator/chatgptapi_translator.py | 1 + book_maker/translator/gemini_translator.py | 10 +++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ee409ad..bf37d80 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,7 @@ dmypy.json /test_books/*.epub log/ .chatgpt_cache.json +# for user do not want to push +*.srt +*.txt +*.bin diff --git a/book_maker/translator/chatgptapi_translator.py b/book_maker/translator/chatgptapi_translator.py index c745cf6..c9daf32 100644 --- a/book_maker/translator/chatgptapi_translator.py +++ b/book_maker/translator/chatgptapi_translator.py @@ -21,6 +21,7 @@ GPT35_MODEL_LIST = [ "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-0301", + "gpt-3.5-turbo-0125", ] GPT4_MODEL_LIST = [ "gpt-4-1106-preview", diff --git a/book_maker/translator/gemini_translator.py b/book_maker/translator/gemini_translator.py index 872772d..0dc43a6 100644 --- a/book_maker/translator/gemini_translator.py +++ b/book_maker/translator/gemini_translator.py @@ -53,6 +53,13 @@ class Gemini(Base): def translate(self, text): t_text = "" + print(text) + # same for caiyun translate src issue #279 gemini for #374 + text_list = text.splitlines() + num = None + if len(text_list) > 1: + if text_list[0].isdigit(): + num = text_list[0] try: self.convo.send_message( self.DEFAULT_PROMPT.format(text=text, language=self.language) @@ -60,7 +67,6 @@ class Gemini(Base): print(text) t_text = self.convo.last.text.strip() except StopCandidateException as e: - print("Here") match = re.search(r'content\s*{\s*parts\s*{\s*text:\s*"([^"]+)"', str(e)) if match: t_text = match.group(1) @@ -80,4 +86,6 @@ class Gemini(Base): print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]") # for limit time.sleep(0.5) + if num: + t_text = str(num) + "\n" + t_text return t_text