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
feat: use Gemini response metadata for token counting (#11743)
Shota Totsuka7d5a38581162
diff --git a/api/core/model_runtime/model_providers/google/llm/llm.py b/api/core/model_runtime/model_providers/google/llm/llm.pyindex 9a1b13f96f4..86865757770 100644--- a/api/core/model_runtime/model_providers/google/llm/llm.py+++ b/api/core/model_runtime/model_providers/google/llm/llm.py@@ -292,8 +292,12 @@ class GoogleLargeLanguageModel(LargeLanguageModel):)else:# calculate num tokens- prompt_tokens = self.get_num_tokens(model, credentials, prompt_messages)- completion_tokens = self.get_num_tokens(model, credentials, [assistant_prompt_message])+ if hasattr(response, "usage_metadata") and response.usage_metadata:+ prompt_tokens = response.usage_metadata.prompt_token_count+ completion_tokens = response.usage_metadata.candidates_token_count+ else:+ prompt_tokens = self.get_num_tokens(model, credentials, prompt_messages)+ completion_tokens = self.get_num_tokens(model, credentials, [assistant_prompt_message])# transform usageusage = self._calc_response_usage(model, credentials, prompt_tokens, completion_tokens)