Move pricing to translation.py
This commit is contained in:
parent
a65a115b1e
commit
f328f21a19
17 changed files with 208 additions and 402 deletions
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue