diff --git a/modules/csv.py b/modules/csv.py index b3dd9b4..af7406e 100644 --- a/modules/csv.py +++ b/modules/csv.py @@ -14,7 +14,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -49,29 +49,12 @@ BRACKETNAMES = False # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # tqdm Globals BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}" @@ -148,11 +131,12 @@ def openFilesEstimate(filename): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/images.py b/modules/images.py index 334b7ef..46a9000 100644 --- a/modules/images.py +++ b/modules/images.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Globals MODEL = os.getenv("model") @@ -43,29 +43,12 @@ openai.api_key = os.getenv("key") # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -159,11 +142,12 @@ def openFiles(folderName): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/json.py b/modules/json.py index df23d1a..2bef315 100644 --- a/modules/json.py +++ b/modules/json.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -54,29 +54,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -143,11 +126,12 @@ def openFiles(filename): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/kirikiri.py b/modules/kirikiri.py index 73b09fb..00d57f2 100644 --- a/modules/kirikiri.py +++ b/modules/kirikiri.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -58,29 +58,12 @@ DIALOGUE = True # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -147,11 +130,12 @@ def handleKirikiri(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/lune.py b/modules/lune.py index d6210bc..87ed4fa 100644 --- a/modules/lune.py +++ b/modules/lune.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -53,29 +53,12 @@ LEAVE = False # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -143,11 +126,12 @@ def openFiles(filename): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/nscript.py b/modules/nscript.py index c00206c..9f2afa6 100644 --- a/modules/nscript.py +++ b/modules/nscript.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -60,29 +60,12 @@ wide_to_ascii.update({0x3000: " ", 0x2212: "-"}) # space and minus # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -144,11 +127,12 @@ def handleOnscripter(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/regex.py b/modules/regex.py index 5e0baf3..4cdba16 100644 --- a/modules/regex.py +++ b/modules/regex.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -55,29 +55,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -130,11 +113,12 @@ def handleRegex(filename, estimate): def getResultString(translatedData, translationTime, filename): global TIMETOTAL # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) if filename != "TOTAL": diff --git a/modules/renpy.py b/modules/renpy.py index 1d0f8f9..8899b71 100644 --- a/modules/renpy.py +++ b/modules/renpy.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -53,29 +53,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -138,11 +121,12 @@ def handleRenpy(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 684a865..a317fb9 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -15,7 +15,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost from ruamel.yaml import YAML @@ -49,29 +49,12 @@ TIMETOTAL = 0 # Total Time Taken for all translations # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing ($ Price Per 1M) -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # tqdm Globals BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}" @@ -232,11 +215,12 @@ def openFiles(filename): def getResultString(translatedData, translationTime, filename): global TIMETOTAL # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) if filename != "TOTAL": diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index ae88a83..8b8a73e 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -14,7 +14,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -46,29 +46,12 @@ TIMETOTAL = 0 # Total Time Taken for all translations # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing ($ Price Per 1M) -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # tqdm Globals BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}" @@ -222,11 +205,12 @@ def openFiles(filename): def getResultString(translatedData, translationTime, filename): global TIMETOTAL # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) if filename != "TOTAL": diff --git a/modules/rpgmakerplugin.py b/modules/rpgmakerplugin.py index ab2c675..5844f7b 100644 --- a/modules/rpgmakerplugin.py +++ b/modules/rpgmakerplugin.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -52,29 +52,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -135,11 +118,12 @@ def handlePlugin(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/text.py b/modules/text.py index 9d61c46..8dc19b9 100644 --- a/modules/text.py +++ b/modules/text.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -53,29 +53,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -127,11 +110,12 @@ def handleText(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/tyrano.py b/modules/tyrano.py index b0701f4..babc6f1 100644 --- a/modules/tyrano.py +++ b/modules/tyrano.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -53,29 +53,12 @@ PBAR = None # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -127,11 +110,12 @@ def handleTyrano(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/unity.py b/modules/unity.py index 5efd741..c9b7b3b 100644 --- a/modules/unity.py +++ b/modules/unity.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -59,29 +59,12 @@ wide_to_ascii.update({0x3000: " ", 0x2212: "-"}) # space and minus # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.14 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 50 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -143,11 +126,12 @@ def handleUnity(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/modules/wolf.py b/modules/wolf.py index ece9fa9..a21881a 100644 --- a/modules/wolf.py +++ b/modules/wolf.py @@ -14,7 +14,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -50,29 +50,12 @@ BRACKETNAMES = False # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # tqdm Globals BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}" @@ -182,11 +165,12 @@ def openFiles(filename): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" @@ -329,13 +313,13 @@ def searchCodes(events, pbar, jobList, filename): match = re.search(speakerRegex, jaString) if match: # TL Speaker - response = getSpeaker(match.group(2)) + response = getSpeaker(match.group(1)) speaker = response[0] totalTokens[0] += response[1][0] totalTokens[1] += response[1][1] # Set nametag and remove from string - codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][0].replace(match.group(2), speaker) + codeList[i]["stringArgs"][0] = codeList[i]["stringArgs"][0].replace(match.group(1), speaker) jaString = jaString.replace(match.group(1), "") # Grab Only Text diff --git a/modules/wolf2.py b/modules/wolf2.py index 17f2ef5..ed59ee1 100644 --- a/modules/wolf2.py +++ b/modules/wolf2.py @@ -13,7 +13,7 @@ from colorama import Fore from dotenv import load_dotenv from retry import retry from tqdm import tqdm -from util.translation import TranslationConfig, translateAI as sharedtranslateAI +from util.translation import TranslationConfig, translateAI as sharedtranslateAI, getPricingConfig, calculateCost # Open AI load_dotenv() @@ -51,29 +51,12 @@ LEAVE = False # Regex - Need to change this if you want to translate from/to other languages. Default is Japanese Regex LANGREGEX = r"[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9\uFF61-\uFF9F]+" -# Pricing - Depends on the model https://openai.com/pricing -# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request -# If you are getting a MISMATCH LENGTH error, lower the batch size. -if "gpt-3.5" in MODEL: - INPUTAPICOST = 3.00 - OUTPUTAPICOST = 5.00 - BATCHSIZE = 10 - FREQUENCY_PENALTY = 0.2 -elif "gpt-5" in MODEL: - INPUTAPICOST = 1.25 - OUTPUTAPICOST = 10.00 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -elif "deepseek" in MODEL: - INPUTAPICOST = 0.27 - OUTPUTAPICOST = 1.10 - BATCHSIZE = 30 - FREQUENCY_PENALTY = 0.05 -else: - INPUTAPICOST = float(os.getenv("input_cost")) - OUTPUTAPICOST = float(os.getenv("output_cost")) - BATCHSIZE = int(os.getenv("batchsize")) - FREQUENCY_PENALTY = float(os.getenv("frequency_penalty")) +# Get pricing configuration based on the model +PRICING_CONFIG = getPricingConfig(MODEL) +INPUTAPICOST = PRICING_CONFIG["inputAPICost"] +OUTPUTAPICOST = PRICING_CONFIG["outputAPICost"] +BATCHSIZE = PRICING_CONFIG["batchSize"] +FREQUENCY_PENALTY = PRICING_CONFIG["frequencyPenalty"] # Initialize Translation Config TRANSLATION_CONFIG = TranslationConfig( @@ -134,11 +117,12 @@ def handleWOLF2(filename, estimate): def getResultString(translatedData, translationTime, filename): # File Print String + cost = calculateCost(translatedData[1][0], translatedData[1][1], MODEL) totalTokenstring = ( Fore.YELLOW + "[Input: " + str(translatedData[1][0]) + "]" "[Output: " + str(translatedData[1][1]) - + "]" "[Cost: ${:,.4f}".format(((translatedData[1][0] / 1000000) * INPUTAPICOST) + ((translatedData[1][1] / 1000000) * OUTPUTAPICOST)) + + "]" "[Cost: ${:,.4f}".format(cost) + "]" ) timeString = Fore.BLUE + "[" + str(round(translationTime, 1)) + "s]" diff --git a/util/translation.py b/util/translation.py index d81cc16..0104ab4 100644 --- a/util/translation.py +++ b/util/translation.py @@ -75,6 +75,50 @@ class TranslationConfig: self.mismatchLogPath = mismatchLogPath +def getPricingConfig(model): + """ + Get pricing configuration for a given model. + + Args: + model: The model name string + + Returns: + dict: Dictionary containing inputAPICost, outputAPICost, batchSize, and frequencyPenalty + """ + # Pricing - Depends on the model https://openai.com/pricing ($ Price Per 1M) + # Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request + # If you are getting a MISMATCH LENGTH error, lower the batch size. + if "gpt-3.5" in model: + return { + "inputAPICost": 3.00, + "outputAPICost": 5.00, + "batchSize": 10, + "frequencyPenalty": 0.2 + } + elif "gpt-5" in model: + return { + "inputAPICost": 1.25, + "outputAPICost": 10.00, + "batchSize": 30, + "frequencyPenalty": 0.05 + } + elif "deepseek" in model: + return { + "inputAPICost": 0.27, + "outputAPICost": 1.10, + "batchSize": 30, + "frequencyPenalty": 0.05 + } + else: + # Fallback to environment variables + return { + "inputAPICost": float(os.getenv("input_cost", 3.00)), + "outputAPICost": float(os.getenv("output_cost", 6.00)), + "batchSize": int(os.getenv("batchsize", 10)), + "frequencyPenalty": float(os.getenv("frequency_penalty", 0.2)) + } + + def batchList(inputList, batchSize): """Split a list into batches of specified size""" if not isinstance(batchSize, int) or batchSize <= 0: @@ -294,6 +338,24 @@ def extractTranslation(translatedTextList, isList, pbar=None): return None +def calculateCost(inputTokens, outputTokens, model): + """ + Calculate the cost of translation based on token usage and model pricing. + + Args: + inputTokens: Number of input tokens used + outputTokens: Number of output tokens generated + model: The model name string + + Returns: + float: Total cost in USD + """ + pricing = getPricingConfig(model) + inputCost = (inputTokens / 1000000) * pricing["inputAPICost"] + outputCost = (outputTokens / 1000000) * pricing["outputAPICost"] + return inputCost + outputCost + + def countTokens(system, user, history): """Count tokens for cost estimation""" inputTotalTokens = 0