Skip to content

Commit

Permalink
fix token calculate error,if cached_tokens is None
Browse files Browse the repository at this point in the history
  • Loading branch information
LAB422PanTong committed Feb 17, 2025
1 parent 1b488b6 commit 8f16473
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/crewai/utilities/token_counter_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def log_success_event(
self.token_cost_process.sum_prompt_tokens(usage.prompt_tokens)
if hasattr(usage, "completion_tokens"):
self.token_cost_process.sum_completion_tokens(usage.completion_tokens)
if hasattr(usage, "prompt_tokens_details") and usage.prompt_tokens_details:
if hasattr(usage, "prompt_tokens_details") and usage.prompt_tokens_details and usage.prompt_tokens_details.cached_tokens:
self.token_cost_process.sum_cached_prompt_tokens(
usage.prompt_tokens_details.cached_tokens
)

0 comments on commit 8f16473

Please sign in to comment.