@@ -35,3 +35,5 @@ def calculate_predict_price(request, body: PredictPriceInputSchema): return PredictPriceSchema(price=predicted_price) + + @@ -12,24 +12,32 @@ from tools.public_api.models import APIStore class Deepseek(SimpleService): TOKENS_COST = { - 'deepseek/deepseek-chat': { - 'input': Decimal('390') / 1_000_000, - 'output': Decimal('390') / 1_000_000, + # 'deepseek/deepseek-chat': { + # 'input': Decimal('390') / 1_000_000, + # 'output': Decimal('390') / 1_000_000, + # }, + # 'deepseek/deepseek-r1': { + # 'input': Decimal('900') / 1_000_000, + # 'output': Decimal('900') / 1_000_000, + # }, + # 'deepseek/deepseek-r1:free': { + # 'input': Decimal('0'), + # 'output': Decimal('0'), + # }, + 'deepseek/deepseek-v4-pro': { + 'input': Decimal('218') / 1_000_000, + 'output': Decimal('435') / 1_000_000, }, - 'deepseek/deepseek-r1': { - 'input': Decimal('900') / 1_000_000, - 'output': Decimal('900') / 1_000_000, - }, - 'deepseek/deepseek-r1:free': { - 'input': Decimal('0'), - 'output': Decimal('0') + 'deepseek/deepseek-v4-flash': { + 'input': Decimal('70') / 1_000_000, + 'output': Decimal('140') / 1_000_000, }, } - PRICE_BIAS = Decimal('0.05') def calculate_price(self, version: str, input_tokens: int, output_tokens: int) -> Decimal: price_map = self.TOKENS_COST[version] - price = input_tokens * price_map['input'] + output_tokens * price_map['output'] + self.PRICE_BIAS + price = input_tokens * price_map['input'] + output_tokens * price_map['output'] + return price.quantize(Decimal('0.1'), rounding='ROUND_UP') def save_results(self, content: str, t: timedelta, save: bool = True) -> list[Message]: @@ -47,15 +55,17 @@ class Deepseek(SimpleService): def make(self, input_message: Message, save: bool = True) -> list[Message]: info = input_message.info.copy() version = info.pop('version') - system_prompt = input_message.info.pop('system_prompt', '') + system_prompt = info.pop('system_prompt', '') + callback_data = { - **input_message.info, + **info, } messages = [ {'role': 'system', 'content': system_prompt}, *self.get_chat_history(), {'role': 'user', 'content': input_message.content} ] + start_time = time.time() result = openrouter_run(version, messages, callback_data, 'Deepseek') process_time = timedelta(seconds=(time.time() - start_time)) @@ -66,8 +76,11 @@ class Deepseek(SimpleService): output_tokens=result[2], ) msgs = self.save_results(result[0], process_time) + return msgs + + def get_chat_history(self, message_limit: int = 10, max_character_limit: int = 1500) -> list[dict[str, str | list]]: if isinstance(self.store, Chat): air_messages = list( @@ -100,3 +113,4 @@ class Deepseek(SimpleService): while character_length > max_character_limit: character_length -= len(memory.pop(0)['content']) return memory + @@ -1,5 +1,4 @@ from typing import List, Optional, Any - from ninja import ModelSchema, Schema from pydantic import condecimal