Refactor: improve cv model logics (#10414)

1. improve how to get total token count

Improve how to get total token count

### Type of change
- [x] Refactoring
This commit is contained in:
Stephen Hu
2025-10-09 09:47:36 +08:00
committed by GitHub
parent dba9158f9a
commit 4585edc20e
2 changed files with 22 additions and 21 deletions

View File

@ -95,6 +95,12 @@ def total_token_count_from_response(resp):
except Exception:
pass
if hasattr(resp, "usage_metadata") and hasattr(resp.usage_metadata, "total_tokens"):
try:
return resp.usage_metadata.total_tokens
except Exception:
pass
if 'usage' in resp and 'total_tokens' in resp['usage']:
try:
return resp["usage"]["total_tokens"]