Skip to content

Commit aa1b9ca

Browse files
authored
Merge pull request #95 from DL4DS/token_regen_logic
initial logic
2 parents b858421 + 0d2ffa9 commit aa1b9ca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/ai_tutor/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ async def reset_tokens_for_user(user_info, TOKENS_LEFT, REGEN_TIME):
6868
# Calculate how many tokens should have been regenerated proportionally
6969
if current_tokens < max_tokens:
7070
# Calculate the regeneration rate per second based on REGEN_TIME for full regeneration
71-
regeneration_rate_per_second = (max_tokens - current_tokens) / REGEN_TIME
71+
# If current_tokens is close to 0, then the regeneration rate is relatively high, and if current_tokens is close to max_tokens, then the regeneration rate is relatively low
72+
regeneration_rate_per_second = (
73+
max_tokens - max(current_tokens, 0)
74+
) / REGEN_TIME
7275

7376
# Calculate how many tokens should have been regenerated based on the elapsed time
7477
tokens_to_regenerate = int(

0 commit comments

Comments
 (0)