Adjust translate function
This commit is contained in:
parent
be9c77fc47
commit
2d0cb1f919
4 changed files with 72 additions and 72 deletions
|
|
@ -407,21 +407,20 @@ def batchList(input_list, batch_size):
|
|||
return [input_list[i:i + batch_size] for i in range(0, len(input_list), batch_size)]
|
||||
|
||||
def createContext(fullPromptFlag, subbedT):
|
||||
characters = 'Game Characters:\
|
||||
護 == Name: Mamoru - Male\
|
||||
神代 一騎 == Last Name: Kamishiro, First Name: Ikki - Male\
|
||||
神代 琴音 == Last Name: Kamishiro, First Name: Kotone - Female\
|
||||
神代 莉々子 == Last Name: Kamishiro, First Name: Ririko - Female\
|
||||
神代 紗夜 == Last Name: Kamishiro, First Name: Saya - Female\
|
||||
篠原漣 == Last Name: Shinohara, First Name: Ren - Male\
|
||||
藪井 == Name: Yabui - Male\
|
||||
舟木 == Name: Funaki - Male\
|
||||
貞二 == Name: Jouji - Male\
|
||||
兼田 響子 == Last Name: Kaneda, First Name: Kyouko - Female\
|
||||
兼田 真人 == Last Name: Kaneda, First Name: Masato - Male\
|
||||
小出 == Name: Koide - Male\
|
||||
進士 == Name: Shinji - Male\
|
||||
雪乃 == Name: Yukino - Female'
|
||||
characters = 'Game Characters:\n\
|
||||
林つかさ (Tsukasa Hayashi) - Female\n\
|
||||
山田美兎 (Miyato Yamada) - Female\n\
|
||||
鈴木赤音 (Akane Suzuki) - Female\n\
|
||||
佐藤莉伊南 (Riina Satou) - Female\n\
|
||||
佐々木万梨美 (Marimi Sasaki) - Female\n\
|
||||
渡辺登樹子 (Tokiko Watanabe) - Female\n\
|
||||
桃乃夢 (Yume Momono) - Female\n\
|
||||
吉浦美雪 (Miyuki Yoshiura) - Female\n\
|
||||
三ツ門まあな (Maana Mitsukado) - Female\n\
|
||||
モリー・ボイド (Molly Boyd) - Female\n\
|
||||
オルガ・ブヤチッチ (Olga Buyachich) - Female\n\
|
||||
アッチャラー ギッティ (Atchara Gitti) - Female\n\
|
||||
'
|
||||
|
||||
system = PROMPT if fullPromptFlag else \
|
||||
f'Output ONLY the {LANGUAGE} translation in the following format: `Translation: <{LANGUAGE.upper()}_TRANSLATION>`'
|
||||
|
|
@ -445,9 +444,8 @@ def translateText(characters, system, user, history):
|
|||
msg.append({"role": "user", "content": f'{user}'})
|
||||
response = openai.chat.completions.create(
|
||||
temperature=0.1,
|
||||
top_p = 0.2,
|
||||
frequency_penalty=0.1,
|
||||
presence_penalty=0.1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0,
|
||||
model=MODEL,
|
||||
messages=msg,
|
||||
)
|
||||
|
|
@ -460,7 +458,9 @@ def cleanTranslatedText(translatedText, varResponse):
|
|||
'っ': '',
|
||||
'〜': '~',
|
||||
'ー': '-',
|
||||
'ッ': ''
|
||||
'ッ': '',
|
||||
'。': '.',
|
||||
'Placeholder Text': ''
|
||||
# Add more replacements as needed
|
||||
}
|
||||
for target, replacement in placeholders.items():
|
||||
|
|
@ -494,7 +494,7 @@ def countTokens(characters, system, user, history):
|
|||
inputTotalTokens += len(enc.encode(user))
|
||||
|
||||
# Output
|
||||
outputTotalTokens += round(len(enc.encode(user))/1.7)
|
||||
outputTotalTokens += round(len(enc.encode(user))/1.5)
|
||||
|
||||
return [inputTotalTokens, outputTotalTokens]
|
||||
|
||||
|
|
@ -514,7 +514,8 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
for index, tItem in enumerate(tList):
|
||||
# Before sending to translation, if we have a list of items, add the formatting
|
||||
if isinstance(tItem, list):
|
||||
payload = '\\n'.join([f'<Line{i}>\`{item}\`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = '\\n'.join([f'<Line{i}>`{item}`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = payload.replace('``', '`Placeholder Text`')
|
||||
varResponse = subVars(payload)
|
||||
subbedT = varResponse[0]
|
||||
else:
|
||||
|
|
@ -546,7 +547,7 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
if isinstance(tItem, list):
|
||||
extractedTranslations = extractTranslation(translatedTextList, True)
|
||||
tList[index] = extractedTranslations
|
||||
if len(tList[index]) != len(translatedTextList):
|
||||
if len(tItem) != len(translatedTextList):
|
||||
mismatch = True # Just here so breakpoint can be set
|
||||
history = extractedTranslations[-10:] # Update history if we have a list
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -417,7 +417,6 @@ def translateText(characters, system, user, history):
|
|||
msg.append({"role": "user", "content": f'{user}'})
|
||||
response = openai.chat.completions.create(
|
||||
temperature=0.1,
|
||||
top_p = 0.2,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0,
|
||||
model=MODEL,
|
||||
|
|
@ -434,7 +433,7 @@ def cleanTranslatedText(translatedText, varResponse):
|
|||
'ー': '-',
|
||||
'ッ': '',
|
||||
'。': '.',
|
||||
'This is a line of text': ''
|
||||
'Placeholder Text': ''
|
||||
# Add more replacements as needed
|
||||
}
|
||||
for target, replacement in placeholders.items():
|
||||
|
|
@ -468,7 +467,7 @@ def countTokens(characters, system, user, history):
|
|||
inputTotalTokens += len(enc.encode(user))
|
||||
|
||||
# Output
|
||||
outputTotalTokens += round(len(enc.encode(user))/2)
|
||||
outputTotalTokens += round(len(enc.encode(user))/1.5)
|
||||
|
||||
return [inputTotalTokens, outputTotalTokens]
|
||||
|
||||
|
|
@ -488,8 +487,8 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
for index, tItem in enumerate(tList):
|
||||
# Before sending to translation, if we have a list of items, add the formatting
|
||||
if isinstance(tItem, list):
|
||||
payload = '\\n'.join([f'<Line{i}>\`{item}\`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = payload.replace('\`\`', '\`This is a line of text\`')
|
||||
payload = '\\n'.join([f'<Line{i}>`{item}`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = payload.replace('``', '`Placeholder Text`')
|
||||
varResponse = subVars(payload)
|
||||
subbedT = varResponse[0]
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -512,23 +512,18 @@ def batchList(input_list, batch_size):
|
|||
|
||||
def createContext(fullPromptFlag, subbedT):
|
||||
characters = 'Game Characters:\n\
|
||||
航 (Wataru) - Male\n\
|
||||
漣 (Ren) - Female\n\
|
||||
悠帆 (Yuuho) - Female\n\
|
||||
穂村 (Homura) - Female\n,\
|
||||
マリー (Marie) - Female\n,\
|
||||
マル子 (Maruko) - Female\n\
|
||||
瑞樹 (Mizuki) - Female\n\
|
||||
壬 (Jin) - Male\n\
|
||||
緒織 (Inori) - Female\n\
|
||||
浩助 (Kousuke) - Male\n\
|
||||
太宰 (Dazai) - Male\n\
|
||||
大嶋 (Oshima) - Male\n\
|
||||
セスカ (Sesuka) - Female\n\
|
||||
重吉 (Shigeyoshi) - Male\n\
|
||||
忠彦 (Tadahiko) - Male\n\
|
||||
和歌 (Waka) - Female\n\
|
||||
吉野 (Yoshino) - Female\n\
|
||||
林つかさ (Tsukasa Hayashi) - Female\n\
|
||||
山田美兎 (Miyato Yamada) - Female\n\
|
||||
鈴木赤音 (Akane Suzuki) - Female\n\
|
||||
佐藤莉伊南 (Riina Satou) - Female\n\
|
||||
佐々木万梨美 (Marimi Sasaki) - Female\n\
|
||||
渡辺登樹子 (Tokiko Watanabe) - Female\n\
|
||||
桃乃夢 (Yume Momono) - Female\n\
|
||||
吉浦美雪 (Miyuki Yoshiura) - Female\n\
|
||||
三ツ門まあな (Maana Mitsukado) - Female\n\
|
||||
モリー・ボイド (Molly Boyd) - Female\n\
|
||||
オルガ・ブヤチッチ (Olga Buyachich) - Female\n\
|
||||
アッチャラー ギッティ (Atchara Gitti) - Female\n\
|
||||
'
|
||||
|
||||
system = PROMPT if fullPromptFlag else \
|
||||
|
|
@ -553,9 +548,8 @@ def translateText(characters, system, user, history):
|
|||
msg.append({"role": "user", "content": f'{user}'})
|
||||
response = openai.chat.completions.create(
|
||||
temperature=0.1,
|
||||
top_p = 0.2,
|
||||
frequency_penalty=0.1,
|
||||
presence_penalty=0.1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0,
|
||||
model=MODEL,
|
||||
messages=msg,
|
||||
)
|
||||
|
|
@ -569,7 +563,8 @@ def cleanTranslatedText(translatedText, varResponse):
|
|||
'〜': '~',
|
||||
'ー': '-',
|
||||
'ッ': '',
|
||||
'。': '.'
|
||||
'。': '.',
|
||||
'Placeholder Text': ''
|
||||
# Add more replacements as needed
|
||||
}
|
||||
for target, replacement in placeholders.items():
|
||||
|
|
@ -603,7 +598,7 @@ def countTokens(characters, system, user, history):
|
|||
inputTotalTokens += len(enc.encode(user))
|
||||
|
||||
# Output
|
||||
outputTotalTokens += round(len(enc.encode(user))/2)
|
||||
outputTotalTokens += round(len(enc.encode(user))/1.5)
|
||||
|
||||
return [inputTotalTokens, outputTotalTokens]
|
||||
|
||||
|
|
@ -623,7 +618,8 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
for index, tItem in enumerate(tList):
|
||||
# Before sending to translation, if we have a list of items, add the formatting
|
||||
if isinstance(tItem, list):
|
||||
payload = '\\n'.join([f'<Line{i}>\`{item}\`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = '\\n'.join([f'<Line{i}>`{item}`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = payload.replace('``', '`Placeholder Text`')
|
||||
varResponse = subVars(payload)
|
||||
subbedT = varResponse[0]
|
||||
else:
|
||||
|
|
@ -655,7 +651,7 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
if isinstance(tItem, list):
|
||||
extractedTranslations = extractTranslation(translatedTextList, True)
|
||||
tList[index] = extractedTranslations
|
||||
if len(tList[index]) != len(translatedTextList):
|
||||
if len(tItem) != len(translatedTextList):
|
||||
mismatch = True # Just here so breakpoint can be set
|
||||
history = extractedTranslations[-10:] # Update history if we have a list
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1874,21 +1874,23 @@ def batchList(input_list, batch_size):
|
|||
return [input_list[i:i + batch_size] for i in range(0, len(input_list), batch_size)]
|
||||
|
||||
def createContext(fullPromptFlag, subbedT):
|
||||
characters = 'Game Characters:\
|
||||
雪音 (Yukine) - Female\
|
||||
朔 (Saku) - Female'
|
||||
system = PROMPT if fullPromptFlag else \
|
||||
f'Output ONLY the {LANGUAGE} translation in the following format: \
|
||||
`Translation: <{LANGUAGE.upper()}_TRANSLATION>`\n\
|
||||
Never include any notes, explanations, dislaimers, or anything similar in your response\n\
|
||||
- "Game Characters" - The names, nicknames, and genders of the game characters.\
|
||||
Reference this to know the names, nicknames, and gender of characters in the game.\n\
|
||||
Sometimes, the text may contain "tags" in the format of "TAGNAME_TAGNUMBER".\
|
||||
Maintain these tags only if they exist in the untranslated text.\n\
|
||||
* Color_# - A tag that colors the wrapped text.\n\
|
||||
* Noun_# - A tag that holds a noun. Maintain as is.\n\
|
||||
* FCode_# - A tag that formats the text in a unique way.\n'
|
||||
characters = 'Game Characters:\n\
|
||||
林つかさ (Tsukasa Hayashi) - Female\n\
|
||||
山田美兎 (Miyato Yamada) - Female\n\
|
||||
鈴木赤音 (Akane Suzuki) - Female\n\
|
||||
佐藤莉伊南 (Riina Satou) - Female\n\
|
||||
佐々木万梨美 (Marimi Sasaki) - Female\n\
|
||||
渡辺登樹子 (Tokiko Watanabe) - Female\n\
|
||||
桃乃夢 (Yume Momono) - Female\n\
|
||||
吉浦美雪 (Miyuki Yoshiura) - Female\n\
|
||||
三ツ門まあな (Maana Mitsukado) - Female\n\
|
||||
モリー・ボイド (Molly Boyd) - Female\n\
|
||||
オルガ・ブヤチッチ (Olga Buyachich) - Female\n\
|
||||
アッチャラー ギッティ (Atchara Gitti) - Female\n\
|
||||
'
|
||||
|
||||
system = PROMPT if fullPromptFlag else \
|
||||
f'Output ONLY the {LANGUAGE} translation in the following format: `Translation: <{LANGUAGE.upper()}_TRANSLATION>`'
|
||||
user = f'{subbedT}'
|
||||
return characters, system, user
|
||||
|
||||
|
|
@ -1909,9 +1911,8 @@ def translateText(characters, system, user, history):
|
|||
msg.append({"role": "user", "content": f'{user}'})
|
||||
response = openai.chat.completions.create(
|
||||
temperature=0.1,
|
||||
top_p = 0.2,
|
||||
frequency_penalty=0.1,
|
||||
presence_penalty=0.1,
|
||||
frequency_penalty=0,
|
||||
presence_penalty=0,
|
||||
model=MODEL,
|
||||
messages=msg,
|
||||
)
|
||||
|
|
@ -1924,7 +1925,9 @@ def cleanTranslatedText(translatedText, varResponse):
|
|||
'っ': '',
|
||||
'〜': '~',
|
||||
'ー': '-',
|
||||
'ッ': ''
|
||||
'ッ': '',
|
||||
'。': '.',
|
||||
'Placeholder Text': ''
|
||||
# Add more replacements as needed
|
||||
}
|
||||
for target, replacement in placeholders.items():
|
||||
|
|
@ -1958,7 +1961,7 @@ def countTokens(characters, system, user, history):
|
|||
inputTotalTokens += len(enc.encode(user))
|
||||
|
||||
# Output
|
||||
outputTotalTokens += round(len(enc.encode(user))/2)
|
||||
outputTotalTokens += round(len(enc.encode(user))/1.5)
|
||||
|
||||
return [inputTotalTokens, outputTotalTokens]
|
||||
|
||||
|
|
@ -1978,7 +1981,8 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
for index, tItem in enumerate(tList):
|
||||
# Before sending to translation, if we have a list of items, add the formatting
|
||||
if isinstance(tItem, list):
|
||||
payload = '\\n'.join([f'<Line{i}>\`{item}\`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = '\\n'.join([f'<Line{i}>`{item}`</Line{i}>' for i, item in enumerate(tItem)])
|
||||
payload = payload.replace('``', '`Placeholder Text`')
|
||||
varResponse = subVars(payload)
|
||||
subbedT = varResponse[0]
|
||||
else:
|
||||
|
|
@ -2010,7 +2014,7 @@ def translateGPT(text, history, fullPromptFlag):
|
|||
if isinstance(tItem, list):
|
||||
extractedTranslations = extractTranslation(translatedTextList, True)
|
||||
tList[index] = extractedTranslations
|
||||
if len(tList[index]) != len(translatedTextList):
|
||||
if len(tItem) != len(translatedTextList):
|
||||
mismatch = True # Just here so breakpoint can be set
|
||||
history = extractedTranslations[-10:] # Update history if we have a list
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue