Skip to content

Commit 9049a7e

Browse files
committed
push
1 parent e3b21ab commit 9049a7e

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

langfuse/langchain/CallbackHandler.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -875,22 +875,28 @@ def _parse_usage_model(usage: typing.Union[pydantic.BaseModel, dict]) -> Any:
875875
usage_model = cast(Dict, usage.copy()) # Copy all existing key-value pairs
876876

877877
# Skip OpenAI usage types as they are handled server side
878-
if not all(
878+
if all(
879879
openai_key in usage_model
880-
for openai_key in ["prompt_tokens", "completion_tokens", "total_tokens"]
880+
for openai_key in [
881+
"prompt_tokens",
882+
"completion_tokens",
883+
"total_tokens",
884+
"prompt_tokens_details",
885+
"completion_tokens_details",
886+
]
881887
):
882-
for model_key, langfuse_key in conversion_list:
883-
if model_key in usage_model:
884-
captured_count = usage_model.pop(model_key)
885-
final_count = (
886-
sum(captured_count)
887-
if isinstance(captured_count, list)
888-
else captured_count
889-
) # For Bedrock, the token count is a list when streamed
890-
891-
usage_model[langfuse_key] = (
892-
final_count # Translate key and keep the value
893-
)
888+
return usage_model
889+
890+
for model_key, langfuse_key in conversion_list:
891+
if model_key in usage_model:
892+
captured_count = usage_model.pop(model_key)
893+
final_count = (
894+
sum(captured_count)
895+
if isinstance(captured_count, list)
896+
else captured_count
897+
) # For Bedrock, the token count is a list when streamed
898+
899+
usage_model[langfuse_key] = final_count # Translate key and keep the value
894900

895901
if isinstance(usage_model, dict):
896902
if "input_token_details" in usage_model:

0 commit comments

Comments
 (0)