mirror of https://github.com/langgenius/dify.git
add:log
This commit is contained in:
parent
2b51fc23d9
commit
db0780cfa8
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue