Skip to content

Commit

Permalink
add skipH
Browse files Browse the repository at this point in the history
  • Loading branch information
xd2333 committed Mar 29, 2024
1 parent 2be0cb4 commit 97898d6
Show file tree
Hide file tree
Showing 5 changed files with 534 additions and 8 deletions.
14 changes: 14 additions & 0 deletions GalTransl/Backend/BingGPT4Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
NewBing_NAME_PROMPT3,
NewBing_PROOFREAD_PROMPT,
NewBing_TRANS_PROMPT,
H_WORDS_LIST
)


Expand Down Expand Up @@ -60,6 +61,11 @@ def __init__(
self.force_NewBing_hs_mode = val
else:
self.force_NewBing_hs_mode = False
# 跳过h
if val := config.getKey("skipH"):
self.skipH = val
else:
self.skipH = False
# 跳过重试
if val := config.getKey("skipRetry"):
self.skipRetry = val
Expand Down Expand Up @@ -385,6 +391,14 @@ async def batch_translate(
proofread=proofread,
retran_key=retran_key,
)
if self.skipH:
LOGGER.warning("skipH: 将跳过含有敏感词的句子")
trans_list_unhit = [
tran
for tran in trans_list_unhit
if not any(word in tran.post_jp for word in H_WORDS_LIST)
]

if len(trans_list_unhit) == 0:
return []
# 新文件重置chatbot
Expand Down
19 changes: 18 additions & 1 deletion GalTransl/Backend/GPT3Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
GPT35_1106_TRANS_PROMPT,
GPT35_0125_SYSTEM_PROMPT,
GPT35_0125_TRANS_PROMPT,
H_WORDS_LIST,
)


Expand Down Expand Up @@ -71,6 +72,11 @@ def __init__(
self.restore_context_mode = val
else:
self.restore_context_mode = False
# 跳过h
if val := config.getKey("skipH"):
self.skipH = val
else:
self.skipH = False
# 跳过重试
if val := config.getKey("skipRetry"):
self.skipRetry = val
Expand Down Expand Up @@ -355,7 +361,9 @@ async def asyncTranslate(self, content: CTransList, gptdict="") -> CTransList:
LOGGER.warning("-> 单句仍错,重置会话")
# 单句5次重试则中止
if self.retry_count == 5:
raise RuntimeError(f"-> 单句反复出错,已中止。最后错误为:{error_message}")
raise RuntimeError(
f"-> 单句反复出错,已中止。最后错误为:{error_message}"
)
continue

if warn_flag:
Expand Down Expand Up @@ -494,6 +502,15 @@ async def batch_translate(
retry_failed=retry_failed,
retran_key=retran_key,
)

if self.skipH:
LOGGER.warning("skipH: 将跳过含有敏感词的句子")
trans_list_unhit = [
tran
for tran in trans_list_unhit
if not any(word in tran.post_jp for word in H_WORDS_LIST)
]

if len(trans_list_unhit) == 0:
return []

Expand Down
17 changes: 14 additions & 3 deletions GalTransl/Backend/GPT4Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
GPT4Turbo_TRANS_PROMPT,
GPT4Turbo_CONF_PROMPT,
GPT4Turbo_PROOFREAD_PROMPT,
H_WORDS_LIST
)


Expand Down Expand Up @@ -86,6 +87,11 @@ def __init__(
self.skipRetry = val
else:
self.skipRetry = False
# 跳过h
if val := config.getKey("skipH"):
self.skipH = val
else:
self.skipH = False
# 流式输出模式
if val := config.getKey("gpt.streamOutputMode"):
self.streamOutputMode = val
Expand Down Expand Up @@ -436,9 +442,14 @@ async def batch_translate(
retran_key=retran_key,
)

# 校对模式多喂上一行
# if proofread and trans_list_unhit[0].prev_tran != None:
# trans_list_unhit.insert(0, trans_list_unhit[0].prev_tran)
if self.skipH:
LOGGER.warning("skipH: 将跳过含有敏感词的句子")
trans_list_unhit = [
tran
for tran in trans_list_unhit
if not any(word in tran.post_jp for word in H_WORDS_LIST)
]

if len(trans_list_unhit) == 0:
return []
# 新文件重置chatbot
Expand Down
Loading

0 comments on commit 97898d6

Please sign in to comment.