Skip to content

Commit

Permalink
fix #590
Browse files Browse the repository at this point in the history
  • Loading branch information
zyddnys committed Mar 22, 2024
1 parent 3b75612 commit 7e0016b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions manga_translator/translators/sakura.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import List, Dict

from .common import CommonTranslator
from .keys import SAKURA_API_BASE
from .keys import SAKURA_API_BASE, SAKURA_API_KEY


class Sakura13BTranslator(CommonTranslator):
Expand All @@ -33,11 +33,6 @@ class Sakura13BTranslator(CommonTranslator):
def __init__(self):
super().__init__()
#检测/v1是否存在
if "/v1" not in SAKURA_API_BASE:
openai.api_base = SAKURA_API_BASE + "/v1"
else:
openai.api_base = SAKURA_API_BASE
openai.api_key = "sk-114514"
self.temperature = 0.3
self.top_p = 0.3
self.frequency_penalty = 0.0
Expand Down Expand Up @@ -246,7 +241,14 @@ async def _request_translation(self, input_text_list) -> str:
'num_beams': 1,
'repetition_penalty': 1.0,
}
old_api_base = openai.api_base or ''
old_api_key = openai.api_key or ''

if "/v1" not in SAKURA_API_BASE:
openai.api_base = SAKURA_API_BASE + "/v1"
else:
openai.api_base = SAKURA_API_BASE
openai.api_key = SAKURA_API_KEY
response = await openai.ChatCompletion.acreate(
model="sukinishiro",
messages=[
Expand All @@ -266,6 +268,8 @@ async def _request_translation(self, input_text_list) -> str:
seed=-1,
extra_query=extra_query,
)
openai.api_base = old_api_base
openai.api_key = old_api_key

# 提取并返回响应文本
for choice in response.choices:
Expand Down

0 comments on commit 7e0016b

Please sign in to comment.