Formatting

This commit is contained in:
DazedAnon 2024-12-19 13:19:23 -06:00
parent 56d67f9b78
commit 6546d56abe
12 changed files with 44 additions and 16 deletions

View file

@ -622,4 +622,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -563,4 +563,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -622,7 +622,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
if format == "json":
return [finalList, totalTokens]
else:
return [finalList[0], totalTokens]
return [finalList, totalTokens]

View file

@ -189,6 +189,24 @@ def translateRegex(data, translatedList):
lineRegexText = r"t\s'(.*)'$"
lineRegexSpeaker = r"n\s'(.*)'$"
choiceRegex = r"choice:\d+\s'(.*)'"
titleRegex = r"title\s'(.*)'$"
# Title
match = re.search(titleRegex, data[i])
if match:
response = translateGPT(
[match.group(1)],
f"Reply with the {LANGUAGE} translation of the chapter title",
True,
)
tokens[0] += response[1][0]
tokens[1] += response[1][1]
title = response[0]
# Set
if translatedList:
title = re.sub(r"(?<!\\)'", r"\\'", title[0])
data[i] = data[i].replace(match.group(1), title)
# Speaker
match = re.search(lineRegexSpeaker, data[i])
@ -198,8 +216,10 @@ def translateRegex(data, translatedList):
speaker = response[0]
tokens[0] += response[1][0]
tokens[1] += response[1][1]
if translatedList:
# Escape Quotes
speaker = re.sub(r"(?<!\\)'", r"\\'", speaker)
data[i] = data[i].replace(match.group(1), speaker)
else:
speaker = None
@ -252,6 +272,12 @@ def translateRegex(data, translatedList):
# Escape Quotes
translatedText = re.sub(r"(?<!\\)'", r"\\'", translatedText)
# Remove Repeating Characters
pattern = re.compile(r"(.)\s*\1(?:\s*\1){" + str(10 - 1) + r",}")
translatedText = pattern.sub(
lambda match: match.group(0).replace(" ", "")[:10], translatedText
)
# Textwrap
translatedText = textwrap.fill(translatedText, width=WIDTH)
translatedTextList = translatedText.split("\n")
@ -442,6 +468,9 @@ def cleanTranslatedText(translatedText, varResponse):
for target, replacement in placeholders.items():
translatedText = translatedText.replace(target, replacement)
# Remove Repeating Characters
translatedText = re.sub(r"^(.){10,}$", "\1\1\1\1\1\1\1\1\1\1", translatedText)
# Elongate Long Dashes (Since GPT Ignores them...)
translatedText = elongateCharacters(translatedText)
return translatedText
@ -559,7 +588,9 @@ def translateGPT(text, history, fullPromptFlag):
extractedTranslations = extractTranslation(translatedText, True)
if extractedTranslations == None or len(tItem) != len(extractedTranslations):
# Mismatch. Try Again
response = translateText(system, user, history, 0.05, format, "gpt-4")
response = translateText(
system, user, history, 0.05, format, "gpt-4-turbo-2024-04-09"
)
translatedText = response.choices[0].message.content
totalTokens[0] += response.usage.prompt_tokens
totalTokens[1] += response.usage.completion_tokens

View file

@ -546,4 +546,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -2678,4 +2678,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -2667,4 +2667,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -537,4 +537,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -537,4 +537,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -613,4 +613,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -2475,4 +2475,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]

View file

@ -580,4 +580,4 @@ def translateGPT(text, history, fullPromptFlag):
tList[index] = translatedText.replace("Placeholder Text", "")
finalList = combineList(tList, text)
return [finalList, totalTokens]
return [finalList, totalTokens]