From 5db1b888becf15ab784bbb094ed9aa01d5959ec7 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Thu, 20 Nov 2025 03:41:49 -0600 Subject: [PATCH] Lists for codes --- modules/rpgmakermvmz.py | 38 ++++++++++++++++++++------------------ util/translation.py | 27 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index 1e3c4f8..85d7c8d 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -2153,27 +2153,29 @@ def searchCodes(page, pbar, jobList, filename): # Map Plugins headerMappings = { - "LL_InfoPopupWIndow": ("messageText", None), - "QuestSystem": ("DetailNote", None), - "BalloonInBattle": ("text", None), - "MNKR_CommonPopupCoreMZ": ("text", None), - "DestinationWindow": ("destination", None), - "_TMLogWindowMZ": ("text", None), - "TorigoyaMZ_NotifyMessage": ("message", None), - "SoR_GabWindow": ("arg1", None), - "DarkPlasma_CharacterText": ("text", None), - "DTextPicture": ("text", None), - "TextPicture": ("text", None), - # "TRP_SkitMZ": ("name", None), - "LogWindow": ("text", None), - "BattleLogOutput": ("message", None), - "TorigoyaMZ_NotifyMessage_CommandMessage": ("message", None), - "NUUN_SaveScreen": ("AnyName", None), + "LL_InfoPopupWIndow": (["messageText"], None), + "QuestSystem": (["DetailNote"], None), + "BalloonInBattle": (["text"], None), + "MNKR_CommonPopupCoreMZ": (["text"], None), + "DestinationWindow": (["destination"], None), + "_TMLogWindowMZ": (["text"], None), + "TorigoyaMZ_NotifyMessage": (["message"], None), + "SoR_GabWindow": (["arg1"], None), + "DarkPlasma_CharacterText": (["text"], None), + "DTextPicture": (["text"], None), + "TextPicture": (["text"], None), + # "TRP_SkitMZ": (["name"], None), + "LogWindow": (["text"], None), + "BattleLogOutput": (["message"], None), + "TorigoyaMZ_NotifyMessage_CommandMessage": (["message"], None), + "NUUN_SaveScreen": (["AnyName"], None), + "build/ARPG_Core": (["Text", "SkillByName"], None), } - for key, (argVar, font) in headerMappings.items(): + for key, (argVars, font) in headerMappings.items(): if key in headerString: - translatePlugins(argVar, font) + for argVar in argVars: + translatePlugins(argVar, font) # AdvExtention plugin support (message event) if headerString == "AdvExtentionllk" and len(codeList[i]["parameters"]) > 3: diff --git a/util/translation.py b/util/translation.py index 1e89dae..4d9135d 100644 --- a/util/translation.py +++ b/util/translation.py @@ -9,6 +9,7 @@ import re import json import tiktoken import openai +from openai import APIError, APIConnectionError, RateLimitError, APIStatusError import hashlib import threading from dotenv import load_dotenv @@ -611,15 +612,39 @@ def translateText(system, user, history, penalty, formatType, model, numLines=No # Call API try: response = openai.chat.completions.create(**params) + except APIStatusError as e: + # Handle HTTP status errors (404, 500, etc.) + if e.status_code == 404: + raise Exception(f"API endpoint not found (404) - check your API_PROVIDER and base URL settings. Error: {e}") + elif e.status_code >= 500: + raise Exception(f"API server error ({e.status_code}) - retrying... Error: {e}") + else: + raise Exception(f"API status error ({e.status_code}): {e}") + except (APIConnectionError, RateLimitError) as e: + # These should always be retried + raise Exception(f"API connection/rate limit error - retrying... Error: {e}") except Exception as e: + # Check if it's a 404 error or other HTTP error that should be retried + error_str = str(e).lower() + if "404" in error_str or "not found" in error_str: + raise Exception(f"API returned 404 Not Found - check your API configuration. Original error: {e}") + # If structured output fails, fallback to json_object if formatType == "json" and "json_schema" in str(responseFormat): responseFormat = {"type": "json_object"} params["response_format"] = responseFormat - response = openai.chat.completions.create(**params) + try: + response = openai.chat.completions.create(**params) + except Exception as fallback_error: + # If fallback also fails, raise the original error for retry + raise Exception(f"API call failed: {e}. Fallback also failed: {fallback_error}") else: raise e + # Validate response before returning + if not response or not hasattr(response, 'choices') or not response.choices: + raise Exception("API returned invalid or empty response - retrying...") + return response