From 8701bcfd8ca01e6db8e10a0ec84fe400258e7b80 Mon Sep 17 00:00:00 2001 From: DazedAnon Date: Thu, 10 Oct 2024 18:26:39 -0500 Subject: [PATCH] Sync wolf with rpgmv --- modules/wolf.py | 259 ++++++++++++++++++------------------------------ vocab.txt | 54 ++++++++-- 2 files changed, 141 insertions(+), 172 deletions(-) diff --git a/modules/wolf.py b/modules/wolf.py index 30a17aa..a9d86c8 100644 --- a/modules/wolf.py +++ b/modules/wolf.py @@ -1776,12 +1776,13 @@ def getSpeaker(speaker): # Store Speaker if speaker not in str(NAMESLIST): response = translateGPT( - speaker, + f'Speaker: {speaker}', "Reply with the " + LANGUAGE + " translation of the NPC name.", - False, + True, ) response[0] = response[0].title() response[0] = response[0].replace("'S", "'s") + response[0] = response[0].replace("Speaker: ", "") # Retry if name doesn't translate for some reason if re.search(r"([a-zA-Z??])", response[0]) == None: @@ -1810,27 +1811,18 @@ def subVars(jaString): # Formatting count = 0 - codeList = re.findall(r"[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]", jaString) + codeList = re.findall(r"[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+?\]", jaString) codeList = set(codeList) if len(codeList) != 0: for var in codeList: jaString = jaString.replace(var, "[FCode_" + str(count) + "]") count += 1 - # WOLF Images - count = 0 - humList = re.findall(r"(\\?r?\\?n?_.*?\d\r\n@?)", jaString) - humList = set(humList) - if len(humList) != 0: - for var in humList: - jaString = jaString.replace(var, "[ICode_" + str(count) + "]") - count += 1 - # Put all lists in list and return - return [jaString, [codeList, humList]] + return [jaString, codeList] -def resubVars(translatedText, varList): +def resubVars(translatedText, codeList): # Fix Spacing and ChatGPT Nonsense matchList = re.findall(r"\[\s?.+?\s?\]", translatedText) if len(matchList) > 0: @@ -1840,18 +1832,11 @@ def resubVars(translatedText, varList): # Formatting count = 0 - if len(varList[0]) != 0: - for var in varList[0]: + if len(codeList) != 0: + for var in codeList: translatedText = translatedText.replace("[FCode_" + str(count) + "]", var) count += 1 - # Formatting - count = 0 - if len(varList[1]) != 0: - for var in varList[1]: - translatedText = translatedText.replace("[ICode_" + str(count) + "]", var) - count += 1 - return translatedText @@ -1864,54 +1849,7 @@ def batchList(input_list, batch_size): ] -def createContext(fullPromptFlag, subbedT): - characters = "Game Characters:\n\ -ロラン (Roland) - Male\n\ -リュカ (Ryuka) - Male\n\ -レックス (Rex) - Male\n\ -タバサ (Tabasa) - Female\n\ -アルス (Ars) - Male\n\ -アマカラ (Amakara) - Male\n\ -エリー (Eri) - Female\n\ -リオ (Rio) - Female\n\ -サマル (Samal) - Male\n\ -ムーン (Moon) - Female\n\ -アリーナ (Arina) - Female\n\ -クリフト (Cliff) - Male\n\ -マーニャ (Manya) - Female\n\ -ミネア (Minea) - Female\n\ -デボラ (Debora) - Female\n\ -ビアンカ (Bianca) - Female\n\ -フローラ (Flora) - Female\n\ -バーバラ (Barbara) - Female\n\ -ミレーユ (Mireyu) - Female\n\ -アイラ (Aira) - Female\n\ -フォズ (Foz) - Female\n\ -マリベル (Maribel) - Female\n\ -ククール (Kukool) - Male\n\ -ゲルダ (Gerda) - Female\n\ -ゼシカ (Jessica) - Female\n\ -ヤンガス (Yangus) - Male\n\ -ラヴィエル (Raviel) - Female\n\ -セティア (Setia) - Female\n\ -ダイ (Dai) - Male\n\ -ヒュンケル (Hyunckel) - Male\n\ -ポップ (Pop) - Male\n\ -マァム (Maam) - Female\n\ -レオナ (Leona) - Female\n\ -アステア (Astea) - Female\n\ -イヨ (Iyo) - Female\n\ -ジャガン (Jagan) - Male\n\ -ヤオ (Yao) - Female\n\ -デイジィ (Daisy) - Female\n\ -バイシュン (Baishun) - Male\n\ -ブライ (Buraimu) - Male\n\ -ハッサン (Hassan) - Male\n\ -アロマ (Aroma) - Female\n\ -ピッケ (Pikke) - Female\n\ -ドラオ (Dorao) - Male\n\ -" - +def createContext(fullPromptFlag, subbedT, format): system = ( PROMPT + VOCAB if fullPromptFlag @@ -1928,20 +1866,17 @@ Output ONLY the {LANGUAGE} translation in the following format: `Translation: <{ {VOCAB}\n\ " ) - if isinstance(subbedT, list): - user = f"```json\n{subbedT}```" + if format == "json": + user = f"```json\n{subbedT}\n```" else: user = subbedT - return characters, system, user + return system, user -def translateText(characters, system, user, history, penalty, format): +def translateText(system, user, history, penalty, format, model=MODEL): # Prompt msg = [{"role": "system", "content": system}] - # Characters - msg.append({"role": "system", "content": characters}) - # History if isinstance(history, list): msg.extend([{"role": "system", "content": h} for h in history]) @@ -1959,7 +1894,7 @@ def translateText(characters, system, user, history, penalty, format): response = openai.chat.completions.create( temperature=0, frequency_penalty=penalty, - model=MODEL, + model=model, response_format=responseFormat, messages=msg, ) @@ -2007,6 +1942,7 @@ def elongateCharacters(text): def extractTranslation(translatedTextList, is_list): try: translatedTextList = re.sub(r'\\"+\"([^,\n}])', r'\\"\1', translatedTextList) + translatedTextList = re.sub(r'(?