-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(gemini): token count #3039
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
fix(gemini): token count #3039
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR fixes token counting for Gemini models by including thinking tokens in the output token count for accurate billing. Main Changes:
Impact: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User as User/Form Input
participant AgentHandler as AgentBlockHandler
participant Provider as Gemini Provider
participant GeminiAPI as Gemini API
participant Utils as Google Utils
participant Billing as Cost Calculation
User->>AgentHandler: Submit agent block with temperature & maxTokens (as strings)
AgentHandler->>AgentHandler: Check temperature != null && !== ''
AgentHandler->>AgentHandler: Check maxTokens != null && !== ''
AgentHandler->>AgentHandler: Convert strings to numbers using Number()
AgentHandler->>Provider: Send request with numeric temperature & maxTokens
Provider->>GeminiAPI: Execute model with thinkingConfig
GeminiAPI-->>Provider: Response with usageMetadata (promptTokenCount, candidatesTokenCount, thoughtsTokenCount)
Provider->>Utils: Call convertUsageMetadata(usageMetadata)
Utils->>Utils: Extract thoughtsTokenCount from usageMetadata
Utils->>Utils: Calculate candidatesTokenCount = candidatesTokenCount + thoughtsTokenCount
Utils->>Utils: Calculate totalTokenCount
Utils-->>Provider: Return GeminiUsage with updated counts
Provider->>Billing: calculateCost(promptTokenCount, candidatesTokenCount)
Billing-->>Provider: Cost for input + output tokens (including thinking)
Provider-->>AgentHandler: Return response with correct token counts and cost
|
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.
No files reviewed, no comments
|
@cursor review |
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
Token count should include thinking tokens.
Type of Change
Testing
Tested manually
Checklist