Refactor:improve the logic for rerank models to cal the total token count (#10882)

### What problem does this PR solve?

improve the logic for rerank models to cal the total token count

### Type of change

- [x] Refactoring
This commit is contained in:
Stephen Hu
2025-10-31 09:46:16 +08:00
committed by GitHub
parent 5a830ea68b
commit 0ecccd27eb
2 changed files with 10 additions and 7 deletions

View File

@ -69,6 +69,12 @@ def total_token_count_from_response(resp):
return resp["usage"]["input_tokens"] + resp["usage"]["output_tokens"]
except Exception:
pass
if 'meta' in resp and 'tokens' in resp['meta'] and 'input_tokens' in resp['meta']['tokens'] and 'output_tokens' in resp['meta']['tokens']:
try:
return resp["meta"]["tokens"]["input_tokens"] + resp["meta"]["tokens"]["output_tokens"]
except Exception:
pass
return 0