Skip to content

Commit d56d681

Browse files
committed
support for amazon nova model
1 parent 4a89bf6 commit d56d681

File tree

4 files changed

+279
-199
lines changed

4 files changed

+279
-199
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_bedrock_patches.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _extract_nova_attributes(self, attributes, request_body):
295295
self._set_if_not_none(attributes, GEN_AI_REQUEST_TEMPERATURE, config.get("temperature"))
296296
self._set_if_not_none(attributes, GEN_AI_REQUEST_TOP_P, config.get("top_p"))
297297
self._set_if_not_none(attributes, GEN_AI_REQUEST_MAX_TOKENS, config.get("max_new_tokens"))
298-
298+
299299
def _extract_claude_attributes(self, attributes, request_body):
300300
self._set_if_not_none(attributes, GEN_AI_REQUEST_MAX_TOKENS, request_body.get("max_tokens"))
301301
self._set_if_not_none(attributes, GEN_AI_REQUEST_TEMPERATURE, request_body.get("temperature"))
@@ -384,12 +384,15 @@ def _handle_amazon_titan_response(self, span: Span, response_body: Dict[str, Any
384384
span.set_attribute(GEN_AI_USAGE_OUTPUT_TOKENS, result["tokenCount"])
385385
if "completionReason" in result:
386386
span.set_attribute(GEN_AI_RESPONSE_FINISH_REASONS, [result["completionReason"]])
387-
387+
388+
# pylint: disable=no-self-use
388389
def _handle_amazon_nova_response(self, span: Span, response_body: Dict[str, Any]):
389-
if "inputTokenCount" in response_body:
390-
span.set_attribute(GEN_AI_USAGE_INPUT_TOKENS, response_body["inputTokenCount"])
391-
if "outputTokenCount" in response_body:
392-
span.set_attribute(GEN_AI_USAGE_OUTPUT_TOKENS, response_body["outputTokenCount"])
390+
if "usage" in response_body:
391+
usage = response_body["usage"]
392+
if "inputTokens" in usage:
393+
span.set_attribute(GEN_AI_USAGE_INPUT_TOKENS, usage["inputTokens"])
394+
if "outputTokens" in usage:
395+
span.set_attribute(GEN_AI_USAGE_OUTPUT_TOKENS, usage["outputTokens"])
393396
if "stopReason" in response_body:
394397
span.set_attribute(GEN_AI_RESPONSE_FINISH_REASONS, [response_body["stopReason"]])
395398

0 commit comments

Comments
 (0)