Skip to content

armgit / dify

Public Imported from GitHub
0

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.

fix: deduct LLM quota after processing invoke result (#13075)

-LAN-b47669b80bbe
diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py
index 6909b30c9e8..6a4f8c4e207 100644
--- a/api/core/workflow/nodes/llm/node.py
+++ b/api/core/workflow/nodes/llm/node.py
@@ -185,6 +185,8 @@ class LLMNode(BaseNode[LLMNodeData]):
result_text = event.text
usage = event.usage
finish_reason = event.finish_reason
+ # deduct quota
+ self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
break
except LLMNodeError as e:
yield RunCompletedEvent(
@@ -240,17 +242,7 @@ class LLMNode(BaseNode[LLMNodeData]):
user=self.user_id,
)
- # handle invoke result
- generator = self._handle_invoke_result(invoke_result=invoke_result)
-
- usage = LLMUsage.empty_usage()
- for event in generator:
- yield event
- if isinstance(event, ModelInvokeCompletedEvent):
- usage = event.usage
-
- # deduct quota
- self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
+ return self._handle_invoke_result(invoke_result=invoke_result)
def _handle_invoke_result(self, invoke_result: LLMResult | Generator) -> Generator[NodeEvent, None, None]:
if isinstance(invoke_result, LLMResult):