Skip to content

Commit a591f0d

Browse files
committed
check for both prompt / completion and input / output tokens
1 parent 9c8614a commit a591f0d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

ddtrace/llmobs/_constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
INPUT_TOKENS_METRIC_KEY = "input_tokens"
3333
OUTPUT_TOKENS_METRIC_KEY = "output_tokens"
3434
TOTAL_TOKENS_METRIC_KEY = "total_tokens"
35-
INTEGRATIONS_USING_INPUT_OUTPUT_TOKENS = {"anthropic"}
3635

3736
EVP_PROXY_AGENT_BASE_PATH = "evp_proxy/v2"
3837
EVP_PROXY_AGENT_ENDPOINT = "{}/api/v2/llmobs".format(EVP_PROXY_AGENT_BASE_PATH)

ddtrace/llmobs/_integrations/utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from ddtrace.llmobs._constants import INPUT_TOKENS_METRIC_KEY
55
from ddtrace.llmobs._constants import OUTPUT_TOKENS_METRIC_KEY
66
from ddtrace.llmobs._constants import TOTAL_TOKENS_METRIC_KEY
7-
from ddtrace.llmobs._constants import INTEGRATIONS_USING_INPUT_OUTPUT_TOKENS
87
from ddtrace.llmobs._utils import _get_attr
98

109

@@ -131,13 +130,9 @@ def get_llmobs_metrics_tags(integration_name, span):
131130
usage[TOTAL_TOKENS_METRIC_KEY] = input_tokens + output_tokens
132131
return usage
133132

134-
prompt_tokens_name = "prompt_tokens"
135-
completion_tokens_name = "completion_tokens"
136-
if integration_name in INTEGRATIONS_USING_INPUT_OUTPUT_TOKENS:
137-
prompt_tokens_name = "input_tokens"
138-
completion_tokens_name = "output_tokens"
139-
input_tokens = span.get_metric("%s.response.usage.%s" % (integration_name, prompt_tokens_name))
140-
output_tokens = span.get_metric("%s.response.usage.%s" % (integration_name, completion_tokens_name))
133+
# check for both prompt / completion or input / output tokens
134+
input_tokens = span.get_metric("%s.response.usage.prompt_tokens" % integration_name) or span.get_metric("%s.response.usage.input_tokens" % integration_name)
135+
output_tokens = span.get_metric("%s.response.usage.completion_tokens" % integration_name) or span.get_metric("%s.response.usage.output_tokens" % integration_name)
141136
total_tokens = span.get_metric("%s.response.usage.total_tokens" % integration_name)
142137

143138
if input_tokens is not None:

0 commit comments

Comments
 (0)