mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix cached tokens (#7679)
Co-authored-by: OpenHands Bot <openhands@all-hands.dev>
This commit is contained in:
parent
5b3921586f
commit
d7f651a06c
@ -551,14 +551,16 @@ class LLM(RetryMixin, DebugMixin):
|
||||
'prompt_tokens_details'
|
||||
)
|
||||
cache_hit_tokens = (
|
||||
prompt_tokens_details.cached_tokens if prompt_tokens_details else 0
|
||||
prompt_tokens_details.cached_tokens
|
||||
if prompt_tokens_details and prompt_tokens_details.cached_tokens
|
||||
else 0
|
||||
)
|
||||
if cache_hit_tokens:
|
||||
stats += 'Input tokens (cache hit): ' + str(cache_hit_tokens) + '\n'
|
||||
|
||||
# For Anthropic, the cache writes have a different cost than regular input tokens
|
||||
# but litellm doesn't separate them in the usage stats
|
||||
# so we can read it from the provider-specific extra field
|
||||
# we can read it from the provider-specific extra field
|
||||
model_extra = usage.get('model_extra', {})
|
||||
cache_write_tokens = model_extra.get('cache_creation_input_tokens', 0)
|
||||
if cache_write_tokens:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user