mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(streaming): avoid rebinding usage helper arguments
This commit is contained in:
parent
b16dfa2cd9
commit
34cd139f53
1 changed files with 20 additions and 9 deletions
|
|
@ -762,19 +762,30 @@ class ChunkProcessor:
|
|||
prompt_tokens_provided = "prompt_tokens" in usage_chunk
|
||||
completion_tokens_provided = "completion_tokens" in usage_chunk
|
||||
|
||||
if prompt_tokens_provided and (usage_chunk_dict["prompt_tokens"] > 0 or prompt_tokens == 0):
|
||||
prompt_tokens = usage_chunk_dict["prompt_tokens"]
|
||||
if completion_tokens_provided and (usage_chunk_dict["completion_tokens"] > 0 or completion_tokens == 0):
|
||||
completion_tokens = usage_chunk_dict["completion_tokens"]
|
||||
if completion_tokens > 0:
|
||||
completion_usage_updates += 1
|
||||
updated_prompt_tokens = (
|
||||
usage_chunk_dict["prompt_tokens"]
|
||||
if prompt_tokens_provided and (usage_chunk_dict["prompt_tokens"] > 0 or prompt_tokens == 0)
|
||||
else prompt_tokens
|
||||
)
|
||||
updated_completion_tokens = (
|
||||
usage_chunk_dict["completion_tokens"]
|
||||
if completion_tokens_provided and (usage_chunk_dict["completion_tokens"] > 0 or completion_tokens == 0)
|
||||
else completion_tokens
|
||||
)
|
||||
updated_completion_usage_updates = (
|
||||
completion_usage_updates + 1
|
||||
if completion_tokens_provided
|
||||
and (usage_chunk_dict["completion_tokens"] > 0 or completion_tokens == 0)
|
||||
and updated_completion_tokens > 0
|
||||
else completion_usage_updates
|
||||
)
|
||||
|
||||
return (
|
||||
prompt_tokens,
|
||||
completion_tokens,
|
||||
updated_prompt_tokens,
|
||||
updated_completion_tokens,
|
||||
prompt_tokens_provided,
|
||||
completion_tokens_provided,
|
||||
completion_usage_updates,
|
||||
updated_completion_usage_updates,
|
||||
)
|
||||
|
||||
def _calculate_usage_per_chunk(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue