Skip to content

Commit 31652d5

Browse files
authored
fix: support usage as part of generation (#192)
1 parent 6764c78 commit 31652d5

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
## 3.14.1 - 2025-02-18
3+
4+
1. Add support for Bedrock Anthropic Usage
5+
16
## 3.13.0 - 2025-02-12
27

38
1. Automatically retry connection errors

posthog/ai/langchain/callbacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ def _parse_usage_model(
597597
# Bedrock: https://docs.aws.amazon.com/bedrock/latest/userguide/monitoring-cw.html#runtime-cloudwatch-metrics
598598
("inputTokenCount", "input"),
599599
("outputTokenCount", "output"),
600+
# Bedrock Anthropic
601+
("prompt_tokens", "input"),
602+
("completion_tokens", "output"),
600603
# langchain-ibm https://pypi.org/project/langchain-ibm/
601604
("input_token_count", "input"),
602605
("generated_token_count", "output"),
@@ -627,6 +630,10 @@ def _parse_usage(response: LLMResult):
627630

628631
if hasattr(response, "generations"):
629632
for generation in response.generations:
633+
if "usage" in generation:
634+
llm_usage = _parse_usage_model(generation["usage"])
635+
break
636+
630637
for generation_chunk in generation:
631638
if generation_chunk.generation_info and ("usage_metadata" in generation_chunk.generation_info):
632639
llm_usage = _parse_usage_model(generation_chunk.generation_info["usage_metadata"])

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "3.14.0"
1+
VERSION = "3.14.1"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

0 commit comments

Comments
 (0)