@@ -248,7 +248,7 @@ class Chatgpt(SimpleService): def calculate_price(self, usage: int, model: str, *args, **kwargs) -> Decimal: price = usage * self.TOKENS_COST[model] - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def count_image_tokens( self, image: InMemoryUploadedFile, high_resolution: bool = True @@ -38,7 +38,7 @@ class Claude(SimpleService): usage['input_tokens'] * self.TOKEN_PAYMENT_RULES[model_name] + usage['output_tokens'] * self.TOKEN_PAYMENT_RULES[model_name] ) - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results(self, r: str, t: timedelta, save: bool = True) -> list[Message]: msgs = [ @@ -32,7 +32,7 @@ class Codellama(SimpleService): sum([Decimal(msg.elapsed_time.total_seconds()) for msg in messages]) * self.price ) - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, r: Iterator[Any], t: timedelta, save: bool = True @@ -85,7 +85,7 @@ class Dalle(SimpleService): price = self.TOKEN_PAYMENT_RULES[input_message.info.get('version', 'dall-e-2')][ input_message.info.get('size', '1024x1024') ] * input_message.info.get('n', 1) - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, input_prompt: str, r: list[str], t: timedelta, save: bool = True @@ -55,7 +55,7 @@ class Deepl(SimpleService): else: symbols += len(message.content) price = symbols * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, @@ -90,9 +90,8 @@ class Djourney(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - total_seconds = Decimal(process_time.total_seconds()) - return self.PRICE * total_seconds - + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True ) -> list[Message]: @@ -51,8 +51,8 @@ class Epicphotogasm(SimpleService): super().__init__(store) def calculate_price(self, process_time: timedelta) -> Decimal: - price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + price = self.price * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, input_prompt: str, r: list[str], t: timedelta, save: bool = True @@ -80,12 +80,13 @@ class Granite(SimpleService): return result.json() def calculate_price(self, result: str, input_message: Message) -> Decimal: - return Decimal( + price = Decimal( sum( [self.TOKEN_PAYMENT_RULES['granite-output'] / 1_000_000 * len(result.split(' '))] + [self.TOKEN_PAYMENT_RULES['granite-input'] / 1_000_000 * len(input_message.content.split(' '))] ) ) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, result: str, time: timedelta, save: bool = True @@ -108,8 +108,8 @@ class Iconic(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - total_seconds = Decimal(process_time.total_seconds()) - return self.PRICE * total_seconds + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True @@ -61,7 +61,7 @@ class Kandinsky(SimpleService): def calculate_price(self, process_time: timedelta) -> Decimal: price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, input_prompt: str, r: list[str], t: timedelta, save: bool = True @@ -91,8 +91,8 @@ class Lightning(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - total_seconds = Decimal(process_time.total_seconds()) - return self.PRICE * total_seconds + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True @@ -46,7 +46,7 @@ class Llama(SimpleService): def calculate_price(self, process_time: timedelta) -> Decimal: price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, r: Iterator[Any], t: timedelta, save: bool = True @@ -91,8 +91,8 @@ class Logoai(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - total_seconds = Decimal(process_time.total_seconds()) - return self.PRICE * total_seconds + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True @@ -67,7 +67,7 @@ class Mistral(SimpleService): ] ) ) - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def make_messages(self, r: Iterator[Any], t: timedelta): msgs = [] @@ -57,7 +57,7 @@ class Musicgen(SimpleService): def calculate_price(self, process_time: timedelta) -> Decimal: price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results(self, r: str, t: timedelta, save: bool = True) -> list[Message]: out: list[Message] = [ @@ -54,7 +54,7 @@ class Openjourney(SimpleService): def calculate_price(self, process_time: timedelta) -> Decimal: price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, input_prompt: str, r: list[str], t: timedelta, save: bool = True @@ -97,7 +97,8 @@ class Pulid(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - return self.PRICE * Decimal(process_time.total_seconds()) + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True @@ -90,7 +90,8 @@ class Sdxlemoji(SimpleService): ) def calculate_price(self, process_time: timedelta) -> Decimal: - return self.PRICE * Decimal(process_time.total_seconds()) + price = self.PRICE * Decimal(process_time.total_seconds()) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, prompt: str, images: list, time: timedelta, save: bool = True @@ -76,7 +76,7 @@ class Upscaleai(SimpleService): def calculate_price(self, process_time: timedelta) -> Decimal: price = Decimal(process_time.total_seconds()) * self.price - return price.quantize(Decimal('.01')) + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results( self, input_prompt: str, results: list[str], t: timedelta, save: bool = True