Rework how past test is injected
This commit is contained in:
parent
8d3c5beede
commit
396bfa2632
9 changed files with 344 additions and 136 deletions
|
|
@ -89,4 +89,84 @@ def getResultString(translatedData, translationTime, filename):
|
|||
errorString = str(e) + '|' + translatedData[3] + Fore.RED
|
||||
return filename + ': ' + tokenString + timeString + Fore.RED + u' \u2717 ' +\
|
||||
errorString + Fore.RESET
|
||||
|
||||
|
||||
@retry(exceptions=Exception, tries=5, delay=5)
|
||||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
# Sub Vars
|
||||
varResponse = subVars(t)
|
||||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
if not re.search(r'[一-龠]+|[ぁ-?]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
# Save Translated Text
|
||||
translatedText = response.choices[0].message.content
|
||||
tokens = response.usage.total_tokens
|
||||
|
||||
# Resub Vars
|
||||
translatedText = resubVars(translatedText, varResponse[1])
|
||||
|
||||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
raise Exception
|
||||
else:
|
||||
return [translatedText, tokens]
|
||||
|
|
@ -320,7 +320,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -329,26 +329,44 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', subbedT):
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: ミカエル == Mikael | Female, ミカ == Mika | Female, ベルゼビュート == Beelzebuth | Female, ベル == Bel | Female, アズラエル == Azriel | Female, アズ == Az | Female, フレイア == Freya | Female'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Current Text to Translate: ' + subbedT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Current Text to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -362,13 +380,19 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Current Text to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Current Text to Translate:', '')
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
return [t, response.usage.total_tokens]
|
||||
raise Exception
|
||||
else:
|
||||
return [translatedText, tokens]
|
||||
|
|
@ -264,7 +264,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -273,28 +273,44 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', subbedT):
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: Name: 稲盛 楓 == Inamori Kaede\nNicknames: かえちゃん == Kae-chan or かえねぇ == Kae-nee\nGender: Female,\nName: 稲盛 真守 == Inamori Mamoru\nNicknames: まーくん == Maa-kun\nGender: Male,\nName: 蓮見 雄次郎 == Hasumi Yujiro\nGender: Male,\nName: 桐谷 拓馬 == Kiriya Takuma\nNicknames: たっくん == Tak-kun\nGender: Male,\nName: 稲盛 美玖 == Inamori Yuki\nGender: Female,\nName: 奥さん == Missus\nGender: Female'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -308,15 +324,19 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate:', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
return [t, response.usage.total_tokens]
|
||||
raise Exception
|
||||
else:
|
||||
return [translatedText, tokens]
|
||||
|
|
@ -461,7 +461,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -473,25 +473,41 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: (Name: 佐伯 瞳 == Saeki Hitomi\nGender: Female, Name: 山岸 優 == Yamagishi Yuu Gender: Female, Name: 五十嵐 朋美 == Igarashi Tomomi Gender: Female, Name: 新道 リサ == Shindou Risa Gender: Female, Name: 岸田 聡 == Kishida Satoshi Gender: Male, Name: 竹内 真也 == Takeuchi Shinya Gender: Male, Name: 田中 祐二 == Tanaka Yuuji Gender: Male)'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -505,11 +521,14 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate:', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
|
|
|
|||
|
|
@ -357,8 +357,11 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
|
|
@ -388,7 +391,6 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
|
|
|
|||
|
|
@ -1504,7 +1504,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -1513,28 +1513,44 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+', subbedT):
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: Name: セレナ == Serena\nGender: Female,\n\nName: カトリーヌ == Catherine\nGender: Female'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -1548,16 +1564,19 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate:', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
return [t, response.usage.total_tokens]
|
||||
raise Exception
|
||||
else:
|
||||
return [translatedText, tokens]
|
||||
|
|
@ -1686,7 +1686,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -1698,36 +1698,41 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 如月亜里愛 == Kisaragi Aria - Nickname: Aria - Gender: Female\
|
||||
Character: 愛洲美彌子 == Aisu Miyako - Gender: Female\
|
||||
Character: 喜遊名心 == Cocoa Kiyuna - Gender: Female\
|
||||
Character: 柵瀬愛色 == Ai Sakurai - Gender: Female\
|
||||
Character: 陰平小鞠 == Komari Kagehira - Gender: Female\
|
||||
Character: 訓覇一縷 == Ichiru Kurube - Gender: Female\
|
||||
Character: 緋皇月 == Luna Hisube - Gender: Female\
|
||||
Character: 刑事 == Detective - Gender: Male\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -1749,7 +1754,6 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
|
|
|
|||
|
|
@ -303,41 +303,55 @@ def resubVars(translatedText, allList):
|
|||
|
||||
@retry(exceptions=Exception, tries=5, delay=5)
|
||||
def translateGPT(t, history, fullPromptFlag):
|
||||
with LOCK:
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
global TOKENS
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo-0613")
|
||||
TOKENS += len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, 0)
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
# Sub Vars
|
||||
varResponse = subVars(t)
|
||||
subbedT = varResponse[0]
|
||||
|
||||
# If there isn't any Japanese in the text just skip
|
||||
return (t,0)
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', subbedT):
|
||||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: 夏樹 明人 == Natsuki Akito | Male, 朝露 砂夜子 == Asatsuyu Sayoko | Female, 神野 藍 == Jinno Ai | Female, 神野 菫 | Jinno Sumire | Female, 夏樹 海夕里 == Natsuki Miyuri | Female, 水森 陽太 == Mizumori Youta | Male, 夏樹 和人 == Natsuki Kazuto | Male, 野崎 博也 == Nozaki Hiroya | Male, 大菊 ジュン == Oogiku Jun | Male, 酒井 絹代 == Sakai Kinuyo | Female, 酒井 豊 == Sakai Yutaka | Male, 竜生 春義 == Tatsuki Haruyoshi | Male, 竜生 潤 == Tatsuki Jun | Male, 吉沢 英玄 == Yoshizawa Eigen | Male, 吉沢 武雄 == Yoshizawa Takeo | Male'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
frequency_penalty=1,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -351,13 +365,19 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate:', '')
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
return [t, response.usage.total_tokens]
|
||||
raise Exception
|
||||
else:
|
||||
return [translatedText, tokens]
|
||||
|
|
@ -468,7 +468,7 @@ def resubVars(translatedText, allList):
|
|||
def translateGPT(t, history, fullPromptFlag):
|
||||
# If ESTIMATE is True just count this as an execution and return.
|
||||
if ESTIMATE:
|
||||
enc = tiktoken.encoding_for_model("gpt-3.5-turbo")
|
||||
enc = tiktoken.encoding_for_model("gpt-4")
|
||||
tokens = len(enc.encode(t)) * 2 + len(enc.encode(history)) + len(enc.encode(PROMPT))
|
||||
return (t, tokens)
|
||||
|
||||
|
|
@ -480,25 +480,41 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+|[\uFF00-\uFFEF]', subbedT):
|
||||
return(t, 0)
|
||||
|
||||
"""Translate text using GPT"""
|
||||
context = 'Eroge Names Context: (Name: 佐伯 瞳 == Saeki Hitomi\nGender: Female, Name: 山岸 優 == Yamagishi Yuu Gender: Female, Name: 五十嵐 朋美 == Igarashi Tomomi Gender: Female, Name: 新道 リサ == Shindou Risa Gender: Female, Name: 岸田 聡 == Kishida Satoshi Gender: Male, Name: 竹内 真也 == Takeuchi Shinya Gender: Male, Name: 田中 祐二 == Tanaka Yuuji Gender: Male)'
|
||||
# Characters
|
||||
context = '```\
|
||||
Game Characters:\
|
||||
Character: 池ノ上 拓海 == Ikenoue Takumi - Gender: Male\
|
||||
Character: 福永 こはる == Fukunaga Koharu - Gender: Female\
|
||||
Character: 神泉 理央 == Kamiizumi Rio - Gender: Female\
|
||||
Character: 吉祥寺 アリサ == Kisshouji Arisa - Gender: Female\
|
||||
Character: 久我 友里子 == Kuga Yuriko - Gender: Female\
|
||||
```'
|
||||
|
||||
# Prompt
|
||||
if fullPromptFlag:
|
||||
system = PROMPT
|
||||
system = PROMPT
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
else:
|
||||
system = 'You are an expert translator who translates everything to English. Reply with only the English Translation of the text.'
|
||||
user = 'Line to Translate: ' + subbedT
|
||||
system = 'Output ONLY the english translation in the following format: `Translation: <ENGLISH_TRANSLATION>`'
|
||||
user = 'Line to Translate = ' + subbedT
|
||||
|
||||
# Create Message List
|
||||
msg = []
|
||||
msg.append({"role": "system", "content": system})
|
||||
msg.append({"role": "user", "content": context})
|
||||
if isinstance(history, list):
|
||||
for line in history:
|
||||
msg.append({"role": "user", "content": line})
|
||||
else:
|
||||
msg.append({"role": "user", "content": history})
|
||||
msg.append({"role": "user", "content": user})
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
temperature=0,
|
||||
temperature=0.1,
|
||||
frequency_penalty=0.2,
|
||||
presence_penalty=0.2,
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": context},
|
||||
{"role": "user", "content": history},
|
||||
{"role": "user", "content": user}
|
||||
],
|
||||
messages=msg,
|
||||
request_timeout=30,
|
||||
)
|
||||
|
||||
|
|
@ -512,12 +528,16 @@ def translateGPT(t, history, fullPromptFlag):
|
|||
# Remove Placeholder Text
|
||||
translatedText = translatedText.replace('English Translation: ', '')
|
||||
translatedText = translatedText.replace('Translation: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate: ', '')
|
||||
translatedText = translatedText.replace('Line to Translate = ', '')
|
||||
translatedText = translatedText.replace('Translation = ', '')
|
||||
translatedText = translatedText.replace('Translate = ', '')
|
||||
translatedText = translatedText.replace('English Translation:', '')
|
||||
translatedText = translatedText.replace('Translation:', '')
|
||||
translatedText = translatedText.replace('Line to Translate:', '')
|
||||
translatedText = re.sub(r'\n\nPast Translated Text:.*', '', translatedText, 0, re.DOTALL)
|
||||
translatedText = translatedText.replace('Line to Translate =', '')
|
||||
translatedText = translatedText.replace('Translation =', '')
|
||||
translatedText = translatedText.replace('Translate =', '')
|
||||
translatedText = re.sub(r'Note:.*', '', translatedText)
|
||||
translatedText = translatedText.replace('っ', '')
|
||||
|
||||
# Return Translation
|
||||
if len(translatedText) > 15 * len(t) or "I'm sorry, but I'm unable to assist with that translation" in translatedText:
|
||||
|
|
|
|||
Loading…
Reference in a new issue