-
Notifications
You must be signed in to change notification settings - Fork 62
feat: add per-conversation duration to Html reports #266
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 1 commit
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
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 |
|---|---|---|
|
|
@@ -37,6 +37,27 @@ def normalize_to_pil_images( | |
| return [image] | ||
|
|
||
|
|
||
| def _format_duration(seconds: float) -> str: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we have a time object. Then we don't need to implement the format logic by our self |
||
| """Format a duration given in seconds as ``HH:MM:SS`` or | ||
| ``HH:MM:SS.mmm`` for sub-second precision. | ||
|
|
||
| Used by `SimpleHtmlReporter` to render both the overall execution time and | ||
| per-conversation durations consistently. | ||
| """ | ||
| total_seconds = max(float(seconds), 0.0) | ||
| whole_seconds = int(total_seconds) | ||
| millis = int(round((total_seconds - whole_seconds) * 1000)) | ||
| if millis == 1000: | ||
| whole_seconds += 1 | ||
| millis = 0 | ||
| hours, remainder = divmod(whole_seconds, 3600) | ||
| minutes, secs = divmod(remainder, 60) | ||
| base = f"{hours:02d}:{minutes:02d}:{secs:02d}" | ||
| if whole_seconds == 0 and millis > 0: | ||
| return f"{base}.{millis:03d}" | ||
| return base | ||
|
|
||
|
|
||
| def truncate_base64_images(content: Any) -> Any: | ||
| """Replace base64 image data with a placeholder to keep reports readable. | ||
|
|
||
|
|
@@ -1010,6 +1031,9 @@ def generate(self) -> None: | |
| </span> | ||
| <span class="usage-breakdown-meta"> | ||
| {{ conversation_usage.step_summaries | length }} step(s), | ||
| {% if conversation_usage.duration_seconds is not none %} | ||
| Duration: {{ format_duration(conversation_usage.duration_seconds) }}, | ||
| {% endif %} | ||
| Input {{ "{:,}".format(conversation_usage.input_tokens or 0) }}, | ||
| Output {{ "{:,}".format(conversation_usage.output_tokens or 0) }}, | ||
| Cache Create {{ "{:,}".format(conversation_usage.cache_creation_input_tokens or 0) }}, | ||
|
|
@@ -1026,6 +1050,9 @@ def generate(self) -> None: | |
| <table class="nested-table"> | ||
| <tr> | ||
| <th>Conversation ID</th> | ||
| {% if conversation_usage.duration_seconds is not none %} | ||
| <th>Duration</th> | ||
| {% endif %} | ||
| <th>Input Tokens</th> | ||
| <th>Output Tokens</th> | ||
| <th>Cache Create</th> | ||
|
|
@@ -1036,6 +1063,9 @@ def generate(self) -> None: | |
| </tr> | ||
| <tr class="system"> | ||
| <td class="mono">{{ conversation_usage.conversation_id }}</td> | ||
| {% if conversation_usage.duration_seconds is not none %} | ||
| <td>{{ format_duration(conversation_usage.duration_seconds) }}</td> | ||
| {% endif %} | ||
| <td>{{ "{:,}".format(conversation_usage.input_tokens or 0) }}</td> | ||
| <td>{{ "{:,}".format(conversation_usage.output_tokens or 0) }}</td> | ||
| <td>{{ "{:,}".format(conversation_usage.cache_creation_input_tokens or 0) }}</td> | ||
|
|
@@ -1141,10 +1171,9 @@ def generate(self) -> None: | |
| end_time = datetime.now(tz=timezone.utc) | ||
| execution_time_formatted: str | None = None | ||
| if self._start_time is not None: | ||
| total_secs = int((end_time - self._start_time).total_seconds()) | ||
| hours, remainder = divmod(total_secs, 3600) | ||
| minutes, secs = divmod(remainder, 60) | ||
| execution_time_formatted = f"{hours:02d}:{minutes:02d}:{secs:02d}" | ||
| execution_time_formatted = _format_duration( | ||
| (end_time - self._start_time).total_seconds() | ||
| ) | ||
|
|
||
| html = template.render( | ||
| timestamp=end_time, | ||
|
|
@@ -1153,6 +1182,7 @@ def generate(self) -> None: | |
| usage_summary=self.usage_summary, | ||
| cache_original_usage=self.cache_original_usage, | ||
| execution_time_formatted=execution_time_formatted, | ||
| format_duration=_format_duration, | ||
| ) | ||
|
|
||
| report_path = ( | ||
|
|
||
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.
Do we not have a times object for duration in Python lib?
Uh oh!
There was an error while loading. Please reload this page.
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.
I changed my mind. Please store the start time and end time and generate the duration in the generate function when the html is generated.
Then we have the values also for other information
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.
And why is this part of the usage tracking?
Should we change the name?
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.
both addressed in #e12eb14b25093833b46467064ccc8fcbe61ae994:
UsageTrackingCallbacktoConversationStatisticsCallbackstarted_atandended_atas datetime objects i/oduration_secondsin theConversationUsageSummary