Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore(quota): Update deduct quota (#14337)
-LAN-7a71498a3e2a
diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.pyindex 349d1a7fca2..aff3d2b7c68 100644--- a/api/core/workflow/nodes/llm/node.py+++ b/api/core/workflow/nodes/llm/node.py@@ -1,6 +1,7 @@import jsonimport loggingfrom collections.abc import Generator, Mapping, Sequence+from datetime import UTC, datetimefrom typing import TYPE_CHECKING, Any, Optional, castfrom configs import dify_config@@ -29,6 +30,7 @@ from core.model_runtime.entities.message_entities import (from core.model_runtime.entities.model_entities import ModelFeature, ModelPropertyKey, ModelTypefrom core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModelfrom core.model_runtime.utils.encoders import jsonable_encoder+from core.plugin.entities.plugin import ModelProviderIDfrom core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfigfrom core.prompt.utils.prompt_message_util import PromptMessageUtilfrom core.variables import (@@ -758,11 +760,17 @@ class LLMNode(BaseNode[LLMNodeData]):if used_quota is not None and system_configuration.current_quota_type is not None:db.session.query(Provider).filter(Provider.tenant_id == tenant_id,- Provider.provider_name == model_instance.provider,+ # TODO: Use provider name with prefix after the data migration.+ Provider.provider_name == ModelProviderID(model_instance.provider).provider_name,Provider.provider_type == ProviderType.SYSTEM.value,Provider.quota_type == system_configuration.current_quota_type.value,Provider.quota_limit > Provider.quota_used,- ).update({"quota_used": Provider.quota_used + used_quota})+ ).update(+ {+ "quota_used": Provider.quota_used + used_quota,+ "last_used": datetime.now(tz=UTC).replace(tzinfo=None),+ }+ )db.session.commit()@classmethoddiff --git a/api/events/event_handlers/deduct_quota_when_message_created.py b/api/events/event_handlers/deduct_quota_when_message_created.pyindex b1b2d2a0864..b8e7019446c 100644--- a/api/events/event_handlers/deduct_quota_when_message_created.py+++ b/api/events/event_handlers/deduct_quota_when_message_created.py@@ -1,6 +1,9 @@+from datetime import UTC, datetime+from configs import dify_configfrom core.app.entities.app_invoke_entities import AgentChatAppGenerateEntity, ChatAppGenerateEntityfrom core.entities.provider_entities import QuotaUnit+from core.plugin.entities.plugin import ModelProviderIDfrom events.message_event import message_was_createdfrom extensions.ext_database import dbfrom models.provider import Provider, ProviderType@@ -48,9 +51,15 @@ def handle(sender, **kwargs):if used_quota is not None and system_configuration.current_quota_type is not None:db.session.query(Provider).filter(Provider.tenant_id == application_generate_entity.app_config.tenant_id,- Provider.provider_name == model_config.provider,+ # TODO: Use provider name with prefix after the data migration.+ Provider.provider_name == ModelProviderID(model_config.provider).provider_name,Provider.provider_type == ProviderType.SYSTEM.value,Provider.quota_type == system_configuration.current_quota_type.value,Provider.quota_limit > Provider.quota_used,- ).update({"quota_used": Provider.quota_used + used_quota})+ ).update(+ {+ "quota_used": Provider.quota_used + used_quota,+ "last_used": datetime.now(tz=UTC).replace(tzinfo=None),+ }+ )db.session.commit()