fix: #280,#279 (#281)

* fix: #280,#279
This commit is contained in:
yihong 2023-05-23 20:05:17 +08:00 committed by GitHub
parent 20ad3ba7c1
commit 1a0bd42259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 7 deletions

View File

@ -10,7 +10,7 @@ on:
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BBM_DEEPL_API_KEY: ${{ secrets.BBM_DEEPL_API_KEY }}
BBM_CAIYUN_API_KEY: ${{ secrets.BBM_CAIYUN_API_KEY }}
jobs:
testing:
@ -33,8 +33,35 @@ jobs:
run: |
pip install .
- name: Run tests
- name: make normal ebook test using google translate and cli
run: |
pip install pytest
pytest tests
bbook_maker --book_name "test_books/Liber_Esther.epub" --test --test_num 10 --model google --translate-tags div,p
bbook_maker --book_name "test_books/Liber_Esther.epub" --test --test_num 20 --model google
- name: make txt book test using google translate
run: |
python3 make_book.py --book_name "test_books/the_little_prince.txt" --test --test_num 20 --model google
- name: make txt book test with batch_size
run: |
python3 make_book.py --book_name "test_books/the_little_prince.txt" --test --batch_size 30 --test_num 20 --model google
- name: make caiyun translator test
if: env.BBM_CAIYUN_API_KEY != null
run: |
python3 make_book.py --book_name "test_books/the_little_prince.txt" --test --batch_size 30 --test_num 100 --model caiyun
- name: make openai key ebook test
if: env.BBM_DEEPL_API_KEY != null
run: |
python3 make_book.py --book_name "test_books/lemo.epub" --test --test_num 5 --language zh-hans
python3 make_book.py --book_name "test_books/animal_farm.epub" --test --test_num 5 --language ja --model gpt3 --prompt prompt_template_sample.txt
python3 make_book.py --book_name "test_books/animal_farm.epub" --test --test_num 5 --language ja --prompt prompt_template_sample.json
python3 make_book.py --book_name test_books/Lex_Fridman_episode_322.srt --test --test_num 20
- name: Rename and Upload ePub
if: env.OPENAI_API_KEY != null
uses: actions/upload-artifact@v2
with:
name: epub_output
path: "test_books/lemo_bilingual.epub"

View File

@ -128,6 +128,9 @@ class EPUBBookLoader(BaseBookLoader):
new_p = copy(p)
for p_exclude in self.exclude_translate_tags.split(","):
# for issue #280
if type(p) == NavigableString:
continue
for pt in new_p.find_all(p_exclude):
pt.extract()
@ -159,6 +162,9 @@ class EPUBBookLoader(BaseBookLoader):
temp_p = copy(p)
for p_exclude in self.exclude_translate_tags.split(","):
# for issue #280
if type(p) == NavigableString:
continue
for pt in temp_p.find_all(p_exclude):
pt.extract()
@ -276,8 +282,9 @@ class EPUBBookLoader(BaseBookLoader):
break
for t in extract_p_list_ori:
target.insert_after(t)
target = t
if target:
target.insert_after(t)
target = t
for item in complete_book.get_items():
if item.file_name != fixname:

View File

@ -1,5 +1,6 @@
import json
import re
import time
import requests
from rich import print
@ -43,6 +44,20 @@ class Caiyun(Base):
data=json.dumps(payload),
headers=self.headers,
)
t_text = json.loads(response.text)["target"]
try:
t_text = response.json()["target"]
except Exception as e:
print(str(e), response.text, "will sleep 60s for the time limit")
if "limit" in response.json()["message"]:
print("will sleep 60s for the time limit")
time.sleep(60)
response = requests.request(
"POST",
self.api_url,
data=json.dumps(payload),
headers=self.headers,
)
t_text = response.json()["target"]
print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
return t_text