Skip to content

Commit dfc9068

Browse files
fix: bug in html report that led to a crash for non-cached executions
1 parent d135838 commit dfc9068

1 file changed

Lines changed: 46 additions & 42 deletions

File tree

src/askui/reporting.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -789,51 +789,55 @@ def generate(self) -> None:
789789
<td>{{ "%.2f"|format(execution_time_seconds) }} seconds</td>
790790
</tr>
791791
{% endif %}
792-
{% if usage_summary.get('input_tokens') is not none %}
793-
<tr>
794-
<th>Input Tokens</th>
795-
<td>
796-
{{ "{:,}".format(usage_summary.get('input_tokens')) }}
797-
{% if cache_original_usage and cache_original_usage.get('input_tokens') %}
798-
{% set original = cache_original_usage.get('input_tokens') %}
799-
{% set current = usage_summary.get('input_tokens') %}
800-
{% set saved = original - current %}
801-
{% if saved > 0 and original > 0 %}
802-
{% set savings_pct = (saved / original * 100) %}
803-
<span style="color: #22c55e; margin-left: 8px;">({{ "%.1f"|format(savings_pct) }}% saved via trajectory caching)</span>
792+
{% if usage_summary is not none %}
793+
{% if usage_summary.get('input_tokens') is not none %}
794+
<tr>
795+
<th>Input Tokens</th>
796+
<td>
797+
{{ "{:,}".format(usage_summary.get('input_tokens')) }}
798+
{% if cache_original_usage and cache_original_usage.get('input_tokens') %}
799+
{% set original = cache_original_usage.get('input_tokens') %}
800+
{% set current = usage_summary.get('input_tokens') %}
801+
{% set saved = original - current %}
802+
{% if saved > 0 and original > 0 %}
803+
{% set savings_pct = (saved / original * 100) %}
804+
<span style="color: #22c55e; margin-left: 8px;">({{ "%.1f"|format(savings_pct) }}% saved via trajectory caching)</span>
805+
{% endif %}
804806
{% endif %}
805-
{% endif %}
806-
</td>
807-
</tr>
808-
{% endif %}
809-
{% if usage_summary.get('output_tokens') is not none %}
810-
<tr>
811-
<th>Output Tokens</th>
812-
<td>
813-
{{ "{:,}".format(usage_summary.get('output_tokens')) }}
814-
{% if cache_original_usage and cache_original_usage.get('output_tokens') %}
815-
{% set original = cache_original_usage.get('output_tokens') %}
816-
{% set current = usage_summary.get('output_tokens') %}
817-
{% set saved = original - current %}
818-
{% if saved > 0 and original > 0 %}
819-
{% set savings_pct = (saved / original * 100) %}
820-
<span style="color: #22c55e; margin-left: 8px;">({{ "%.1f"|format(savings_pct) }}% saved via trajectory caching)</span>
807+
</td>
808+
</tr>
809+
{% endif %}
810+
{% if usage_summary.get('output_tokens') is not none %}
811+
<tr>
812+
<th>Output Tokens</th>
813+
<td>
814+
{{ "{:,}".format(usage_summary.get('output_tokens')) }}
815+
{% if cache_original_usage and cache_original_usage.get('output_tokens') %}
816+
{% set original = cache_original_usage.get('output_tokens') %}
817+
{% set current = usage_summary.get('output_tokens') %}
818+
{% set saved = original - current %}
819+
{% if saved > 0 and original > 0 %}
820+
{% set savings_pct = (saved / original * 100) %}
821+
<span style="color: #22c55e; margin-left: 8px;">({{ "%.1f"|format(savings_pct) }}% saved via trajectory caching)</span>
822+
{% endif %}
821823
{% endif %}
822-
{% endif %}
823-
</td>
824-
</tr>
825-
{% endif %}
826-
{% if cache_original_usage.get('input_tokens') is not none %}
827-
<tr>
828-
<th>Original Input Tokens</th>
829-
<td>{{ "{:,}".format(cache_original_usage.get('input_tokens')) }}</td>
830-
</tr>
824+
</td>
825+
</tr>
826+
{% endif %}
831827
{% endif %}
832-
{% if cache_original_usage.get('output_tokens') is not none %}
833-
<tr>
834-
<th>Original Output Tokens</th>
835-
<td>{{ "{:,}".format(cache_original_usage.get('output_tokens')) }}</td>
836-
</tr>
828+
{% if cache_original_usage is not none %}
829+
{% if cache_original_usage.get('input_tokens') is not none %}
830+
<tr>
831+
<th>Original Input Tokens</th>
832+
<td>{{ "{:,}".format(cache_original_usage.get('input_tokens')) }}</td>
833+
</tr>
834+
{% endif %}
835+
{% if cache_original_usage.get('output_tokens') is not none %}
836+
<tr>
837+
<th>Original Output Tokens</th>
838+
<td>{{ "{:,}".format(cache_original_usage.get('output_tokens')) }}</td>
839+
</tr>
840+
{% endif %}
837841
{% endif %}
838842
</table>
839843
</div>

0 commit comments

Comments
 (0)