diff --git a/api/events/event_handlers/update_provider_when_message_created.py b/api/events/event_handlers/update_provider_when_message_created.py index d787b23fac..9efe9a79af 100644 --- a/api/events/event_handlers/update_provider_when_message_created.py +++ b/api/events/event_handlers/update_provider_when_message_created.py @@ -133,9 +133,10 @@ def handle(sender: Message, **kwargs): system_configuration=system_configuration, model_name=model_config.model, ) - + logger.info("used_quota: %s", used_quota) if used_quota is not None: if provider_configuration.system_configuration.current_quota_type == ProviderQuotaType.TRIAL: + logger.info("deduct credits") from services.credit_pool_service import CreditPoolService CreditPoolService.check_and_deduct_credits( @@ -143,6 +144,7 @@ def handle(sender: Message, **kwargs): credits_required=used_quota, ) else: + logger.info("update provider quota") quota_update = _ProviderUpdateOperation( filters=_ProviderUpdateFilters( tenant_id=tenant_id, diff --git a/api/services/credit_pool_service.py b/api/services/credit_pool_service.py index 2bf9f4118f..f72686b9ff 100644 --- a/api/services/credit_pool_service.py +++ b/api/services/credit_pool_service.py @@ -1,3 +1,4 @@ +import logging from typing import Optional from sqlalchemy import update @@ -7,6 +8,8 @@ from core.errors.error import QuotaExceededError from extensions.ext_database import db from models import TenantCreditPool +logger = logging.getLogger(__name__) + class CreditPoolService: @classmethod @@ -72,8 +75,9 @@ class CreditPoolService: cls, tenant_id: str, credits_required: int, - ) -> bool: + ): """check and deduct credits""" + logger.info("check and deduct credits") pool = cls.get_pool(tenant_id) if not pool: raise QuotaExceededError("Credit pool not found") @@ -93,8 +97,6 @@ class CreditPoolService: stmt = update(TenantCreditPool).where(*where_conditions).values(**update_values) db.session.execute(stmt) - return True - @classmethod def check_deduct_credits(cls, tenant_id: str, credits_required: int) -> bool: """check and deduct credits"""