[docs]@dataclassclassModelPriceInfo:"""Cost information for input and output tokens of a model. Attributes: input_token_cost (Money): Cost per input token. output_token_cost (Money): Cost per output token. """input_token_cost:Moneyoutput_token_cost:Money
[docs]defget_cost_for(self,token_type:TokenType)->Money:"""Return the cost for the specified token type. Args: token_type (TokenType): The type of token (INPUT or OUTPUT). Returns: Money: The cost associated with the token type. Raises: ValueError: If an unsupported token type is provided. """iftoken_type==TokenType.INPUT:returnself.input_token_costeliftoken_type==TokenType.OUTPUT:returnself.output_token_costraiseValueError("Wrong token type")
[docs]classTokenPriceCalculator:"""Calculator for determining token costs of supported assistant models."""model_price_infos:dict[AssistantChatModel,ModelPriceInfo]={AssistantChatModel.GPT_4O:ModelPriceInfo(Money(2.5e-6),Money(10e-6)),AssistantChatModel.GPT_4O_MINI:ModelPriceInfo(Money(0.15e-6),Money(0.6e-6)),AssistantChatModel.GPT_4_1:ModelPriceInfo(Money(2e-6),Money(8e-6)),AssistantChatModel.GPT_4_1_MINI:ModelPriceInfo(Money(0.40e-6),Money(1.60e-6)),AssistantChatModel.GPT_4_1_NANO:ModelPriceInfo(Money(0.1e-6),Money(0.4e-6)),AssistantChatModel.LLAMA_70B:ModelPriceInfo(Money(0.12e-6),Money(0.3e-6)),AssistantChatModel.QWEN_2_5_7B:ModelPriceInfo(Money(0.025e-6),Money(0.05e-6)),AssistantChatModel.LLAMA_3B:ModelPriceInfo(Money(0.015e-6),Money(0.025e-6)),AssistantChatModel.QWEN_2_5_7B_TOGETHER:ModelPriceInfo(Money(0.3e-6),Money(0.3e-6)),AssistantChatModel.DEEP_SEEK_R1:ModelPriceInfo(Money(0.5e-6),Money(2.15e-6)),}
[docs]defget_cost(self,model:AssistantChatModel,token_type:TokenType)->Money:"""Calculate the cost for a given model and token type. Args: model (AssistantChatModel): The chat model to query. token_type (TokenType): The type of token (INPUT or OUTPUT). Returns: Money: The cost for one token of the specified type for the given model. Raises: ValueError: If the model is not found in the price information. """ifmodelinself.model_price_infos:returnself.model_price_infos[model].get_cost_for(token_type)raiseValueError(f"Model not found in Token Price Calculator {model.value}")