-
Notifications
You must be signed in to change notification settings - Fork 10.7k
fix(llm): implement async chat methods for GoogleChat (Vertex AI Gemini) #15994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JinHai-CN
merged 2 commits into
infiniflow:main
from
glu000:fix/googlechat-async-vertex-ai
Sep 9, 2026
+96
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge infiniflow/ragflow /tmp/coderabbit-repo-knowledge/infiniflow-ragflow-4efad711/learningsLength of output: 10185
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 24661
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 24575
🤖 get_repo_knowledge executed:
get_repo_knowledge infiniflow/ragflow /tmp/coderabbit-repo-knowledge/infiniflow-ragflow-4efad711/learningsLength of output: 18205
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 16924
🌐 Web query:
infiniflow ragflow rag/llm/chat_model.py last_usage GoogleChat usage_metadata💡 Result:
In RAGFlow,
last_usageandusage_metadataare key components of the LLM token tracking and cost-accounting infrastructure, managed primarily withinrag/llm/chat_model.pyand utility files likecommon/token_utils.py[1][2][3]. Key technical details regarding these components include: 1.last_usage: This attribute is maintained within theBaseLLM class (and its subclasses, includingGoogleChat) to store token consumption (prompt/completion/total) for the most recent chat invocation [1]. To ensure accuracy, the system is designed to resetlast_usage(e.g., via_reset_last_usage()) before every new chat or stream request to prevent stale data [1]. 2.usage_metadata: This refers to the structured object returned by LLM APIs (specifically the Google GenAI SDK used byGoogleChat) that contains token count information [4][2][5]. Thecommon/token_utils.pymodule provides helper functions liketotal_token_count_from_responseto extract total token counts from varying response structures, including those that provideusage_metadata.total_token_count[2][6]. 3. GoogleChat Implementation: TheGoogleChatclass inrag/llm/chat_model.pyintegrates with Google's Vertex AI via thegoogle-genaiSDK [7][8][9]. When performing streaming requests, the implementation typically iterates through response chunks and reads theusage_metadata.total_token_countfrom the final chunk to determine total consumption for the stream [4][10]. Recent updates to the codebase have focused on improving the accuracy of this accounting, particularly by aggregating token totals across multi-round tool-calling interactions and ensuring thatusageinformation is properly propagated to logging services like Langfuse [1][3].Citations:
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 13637
Update
self.last_usagefor Gemini async completions.When
GoogleChat._async_chatsucceeds, it reads onlyresponse.usage_metadata.total_token_count. It does not updateself.last_usage, unlikeBase._async_chat. Langfuse reporting and run aggregation may therefore use stale or zero prompt and completion usage.Set
self.last_usagewithprompt_token_count,candidates_token_count, andtotal_token_count. Set all usage fields to zero whenusage_metadatais unavailable.🧰 Tools
🪛 Ruff (0.16.3)
[warning] 1803-1803: Do not catch blind exception:
Exception(BLE001)
🤖 Prompt for AI Agents