-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 issue #5383: [Bug]: LLM Cost is added to the metrics
twice
#5396
Merged
Conversation
This file contains 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
1 task
@openhands-agent This PR has a wrong approach. Instead:
|
New OpenHands update |
enyst
reviewed
Dec 4, 2024
enyst
reviewed
Dec 4, 2024
xingyaoww
reviewed
Dec 4, 2024
Most comments on this PR have been solved. The last review comment is not solved: return cost from _post_completion to use it directly. |
xingyaoww
approved these changes
Dec 4, 2024
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.
LGTM!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request fixes #5383.
The issue has been successfully resolved. The AI made targeted changes to prevent double-counting of LLM completion costs by:
_hidden_params
to store the cost when it's first calculated_completion_cost
method to check for cached costs before adding new ones to metrics_post_completion
is called, it uses the cached cost value instead of recalculating and re-adding itFor a human reviewer, I would summarize the PR as:
"This PR fixes a cost double-counting issue in the LLM completion process. Previously, the
_completion_cost
method was being called twice (once during log preparation and once during_post_completion
), causing costs to be added to metrics twice. The fix implements a caching mechanism using_hidden_params
to store the cost on first calculation and reuse it in subsequent calls, ensuring each completion's cost is only counted once. Test results confirm the fix is working as intended."This is a clean, focused fix that addresses the specific issue without introducing new complexity or side effects.
Automatic fix generated by OpenHands 🙌
To run this PR locally, use the following command: