mirror of
https://github.com/father-bot/chatgpt_telegram_bot.git
synced 2026-08-03 13:27:16 +03:00
Skip unconfigured models in /balance
Existing users may have token usage recorded against models that have since been removed from models.yml. Skip any model key not present in the config when building the balance breakdown so /balance no longer raises a KeyError for them.
This commit is contained in:
@@ -752,6 +752,11 @@ async def show_balance_handle(update: Update, context: CallbackContext):
|
||||
|
||||
details_text = "🏷️ Details:\n"
|
||||
for model_key in sorted(n_used_tokens_dict.keys()):
|
||||
# skip models that are no longer configured (e.g. removed legacy models
|
||||
# a user spent tokens on in the past) to avoid a KeyError
|
||||
if model_key not in config.models["info"]:
|
||||
continue
|
||||
|
||||
n_input_tokens, n_output_tokens = n_used_tokens_dict[model_key]["n_input_tokens"], n_used_tokens_dict[model_key]["n_output_tokens"]
|
||||
total_n_used_tokens += n_input_tokens + n_output_tokens
|
||||
|
||||
|
||||
Reference in New Issue
Block a user