-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add model_name, agent_name, and response_id to RequestUsage for better tracking #2114
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
11e97c4
6e6ca81
cfa7c1e
8ecd03b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import field | ||
|
|
||
| from openai.types.responses.response_usage import InputTokensDetails, OutputTokensDetails | ||
|
|
@@ -23,6 +25,15 @@ class RequestUsage: | |
| output_tokens_details: OutputTokensDetails | ||
| """Details about the output tokens for this individual request.""" | ||
|
|
||
| model_name: str | ||
| """The model name used for this request.""" | ||
|
|
||
| agent_name: str | ||
| """The agent name that made this request.""" | ||
|
|
||
| response_id: str | None = None | ||
| """The response ID for this request (i.e. ModelResponse.response_id).""" | ||
|
|
||
|
|
||
| @dataclass | ||
| class Usage: | ||
|
|
@@ -70,13 +81,22 @@ def __post_init__(self) -> None: | |
| if self.output_tokens_details.reasoning_tokens is None: | ||
| self.output_tokens_details = OutputTokensDetails(reasoning_tokens=0) | ||
|
|
||
| def add(self, other: "Usage") -> None: | ||
| def add( | ||
| self, | ||
| other: Usage, | ||
| model_name: str, | ||
|
||
| agent_name: str, | ||
| response_id: str | None = None, | ||
| ) -> None: | ||
| """Add another Usage object to this one, aggregating all fields. | ||
|
|
||
| This method automatically preserves request_usage_entries. | ||
|
|
||
| Args: | ||
| other: The Usage object to add to this one. | ||
| model_name: The model name used for this request. | ||
| agent_name: The agent name that made this request. | ||
| response_id: The response ID for this request. | ||
| """ | ||
| self.requests += other.requests if other.requests else 0 | ||
| self.input_tokens += other.input_tokens if other.input_tokens else 0 | ||
|
|
@@ -101,6 +121,9 @@ def add(self, other: "Usage") -> None: | |
| total_tokens=other.total_tokens, | ||
| input_tokens_details=other.input_tokens_details, | ||
| output_tokens_details=other.output_tokens_details, | ||
| model_name=model_name, | ||
| agent_name=agent_name, | ||
| response_id=response_id, | ||
| ) | ||
| self.request_usage_entries.append(request_usage) | ||
| elif other.request_usage_entries: | ||
|
|
||
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.
in fact, it seems available models have self.model but this could be potentially a breaking change for some custom models. it will require a minor version upgrade and release note annoucements