Skip to content

Commit a1a24c6

Browse files
committed
quick fix usage
1 parent 4ded927 commit a1a24c6

File tree

1 file changed

+6
-3
lines changed
  • src/langtrace_python_sdk/utils

1 file changed

+6
-3
lines changed

src/langtrace_python_sdk/utils/llm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,25 @@ def set_usage_attributes(span, usage):
148148
if usage is None:
149149
return
150150

151+
input_tokens = usage.get("input_tokens") or usage.get("prompt_tokens") or 0
152+
output_tokens = usage.get("output_tokens") or usage.get("completion_tokens") or 0
153+
151154
set_span_attributes(
152155
span,
153156
SpanAttributes.LLM_USAGE_PROMPT_TOKENS.value,
154-
usage["input_tokens"] or 0,
157+
input_tokens,
155158
)
156159

157160
set_span_attributes(
158161
span,
159162
SpanAttributes.LLM_USAGE_COMPLETION_TOKENS.value,
160-
usage["output_tokens"] or 0,
163+
output_tokens,
161164
)
162165

163166
set_span_attributes(
164167
span,
165168
SpanAttributes.LLM_USAGE_TOTAL_TOKENS.value,
166-
(usage["input_tokens"] or 0) + (usage["output_tokens"] or 0),
169+
input_tokens + output_tokens,
167170
)
168171

169172
if "search_units" in usage:

0 commit comments

Comments
 (0)