~cytrogen/evi-run

ref: b4084f5eac89c4d164c014e297cff02678b07125 evi-run/bot/utils/calculate_tokens.py -rw-r--r-- 928 bytes
b4084f5e — Bendy Merge branch 'main' of https://github.com/pipedude/evi-run 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from database.models import User
from database.repositories.user import UserRepository

from config import TYPE_USAGE, CREDITS_INPUT_TEXT, CREDITS_OUTPUT_TEXT, CREDITS_INPUT_IMAGE, CREDITS_OUTPUT_IMAGE


async def calculate_tokens(user_repo: UserRepository, user: User,
                           input_tokens_text: int, output_tokens_text: int,
                           input_tokens_img: int, output_tokens_img: int):
    if TYPE_USAGE != 'private':
        credits_input_text = (input_tokens_text / 1000) * CREDITS_INPUT_TEXT
        credits_output_text = (output_tokens_text / 1000) * CREDITS_OUTPUT_TEXT

        credits_input_img = (input_tokens_img / 1000) * CREDITS_INPUT_IMAGE
        credits_output_img = (output_tokens_img / 1000) * CREDITS_OUTPUT_IMAGE

        credits = credits_input_text + credits_output_text + credits_input_img + credits_output_img
        await user_repo.update(user, balance_credits=credits)