-
Notifications
You must be signed in to change notification settings - Fork 201
Description
Describe the bug
In langfuse-haystack>=3.0.0 we now use _sanitize_usage_data for better feeding into Langfuse specification. However, this unexpectedly flattens the usage data format in OpenAI style, e.g.:
{
"completion_tokens": 1080,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens": 4126,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 4096
},
"total_tokens": 5206
}After the flattening, it seems like the data is no longer recognized by Langfuse, and it falls back to the default behavior, showing 0->0 (14508) instead.
Langfuse summarizes all usage types that include the string input as input usage types, similarly output as output usage types. If no total usage type is ingested, Langfuse sums up all usage type units to a total.
Digging deeper inside Langfuse handling, it expects a yaml structure for OpenAI Usage as follows:
OpenAICompletionUsageSchema:
docs: OpenAI Usage schema from (Chat-)Completion APIs
properties:
prompt_tokens: integer
completion_tokens: integer
total_tokens: integer
prompt_tokens_details: optional<map<string, optional<integer>>>
completion_tokens_details: optional<map<string, optional<integer>>>To Reproduce
Run an OpenAI model in a pipeline and observe the trace.
Suggestion on Fixing
The easiest solution should be skip sanitizing if we found OpenAI-style usage pattern.