-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DRAFT: Dev/add usage details to Usage class #726
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a08fe82
feat: implemented class using InputTokenDetails, will revert for comp…
WJPBProjects 361ec20
feat: implemented tokens_details throughout src
WJPBProjects 6cc68f4
feat: updated tests
WJPBProjects e26abd6
feat: simplify adder
WJPBProjects 02f9c7f
feat: updated current tests
WJPBProjects 43bca12
test: added test to cover Usage.add method
WJPBProjects 2c8221c
chore: revert unneeded file change
WJPBProjects d26b329
fix: updated tests to use Optional for legacy python CI test
WJPBProjects 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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from openai.types.responses.response_usage import InputTokensDetails, OutputTokensDetails | ||
|
||
from agents.usage import Usage | ||
|
||
|
||
def test_usage_add_aggregates_all_fields(): | ||
u1 = Usage( | ||
requests=1, | ||
input_tokens=10, | ||
input_tokens_details=InputTokensDetails(cached_tokens=3), | ||
output_tokens=20, | ||
output_tokens_details=OutputTokensDetails(reasoning_tokens=5), | ||
total_tokens=30, | ||
) | ||
u2 = Usage( | ||
requests=2, | ||
input_tokens=7, | ||
input_tokens_details=InputTokensDetails(cached_tokens=4), | ||
output_tokens=8, | ||
output_tokens_details=OutputTokensDetails(reasoning_tokens=6), | ||
total_tokens=15, | ||
) | ||
|
||
u1.add(u2) | ||
|
||
assert u1.requests == 3 | ||
assert u1.input_tokens == 17 | ||
assert u1.output_tokens == 28 | ||
assert u1.total_tokens == 45 | ||
assert u1.input_tokens_details.cached_tokens == 7 | ||
assert u1.output_tokens_details.reasoning_tokens == 11 | ||
|
||
|
||
def test_usage_add_aggregates_with_none_values(): | ||
u1 = Usage() | ||
u2 = Usage( | ||
requests=2, | ||
input_tokens=7, | ||
input_tokens_details=InputTokensDetails(cached_tokens=4), | ||
output_tokens=8, | ||
output_tokens_details=OutputTokensDetails(reasoning_tokens=6), | ||
total_tokens=15, | ||
) | ||
|
||
u1.add(u2) | ||
|
||
assert u1.requests == 2 | ||
assert u1.input_tokens == 7 | ||
assert u1.output_tokens == 8 | ||
assert u1.total_tokens == 15 | ||
assert u1.input_tokens_details.cached_tokens == 4 | ||
assert u1.output_tokens_details.reasoning_tokens == 6 |
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.
Uh oh!
There was an error while loading. Please reload this page.