Skip to content

Commit

Permalink
Fix deprecated token callback, add deprecation on cost feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Kim committed Feb 5, 2025
1 parent 8f8aebe commit 6c21109
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ddtrace/contrib/internal/langchain/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ def _tag_openai_token_usage(
total_cost = span.get_metric(TOTAL_COST) or 0
if not propagate and get_openai_token_cost_for_model:
try:
completion_cost = get_openai_token_cost_for_model(
span.get_tag(MODEL),
span.get_metric(COMPLETION_TOKENS),
is_completion=True,
)
if parse_version(langchain_community.__version__) >= (0, 3, 13):
completion_cost = get_openai_token_cost_for_model(
span.get_tag(MODEL), span.get_metric(COMPLETION_TOKENS), token_type=2,
)
else:
completion_cost = get_openai_token_cost_for_model(
span.get_tag(MODEL), span.get_metric(COMPLETION_TOKENS), is_completion=True,
)
prompt_cost = get_openai_token_cost_for_model(span.get_tag(MODEL), span.get_metric(PROMPT_TOKENS))
total_cost = completion_cost + prompt_cost
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
deprecations:
- |
langchain: The `langchain.tokens.total_cost` span metric for OpenAI calls is now deprecated and will be removed in `ddtrace==4.0`.
For cost estimation of OpenAI calls, enable LLM Observability.

0 comments on commit 6c21109

Please sign in to comment.