Commit de28291
authored
fix(langchain): avoid double-counting cached input tokens (#445)
Only fold cache tokens into prompt and total metrics when LangChain
reports cache tokens separately from input tokens. This preserves
Anthropic-style cache normalization while avoiding double-counting for
OpenAI-style responses where cached tokens are already included in
input_tokens.
Adds regression coverage for OpenAI cached token metrics.
resolves
https://linear.app/braintrustdata/issue/BT-5310/langchain-callback-double-counts-cache-tokens-for-openai-after-pr-4111 parent 3651b0b commit de28291
2 files changed
Lines changed: 57 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
620 | 638 | | |
621 | 639 | | |
622 | 640 | | |
| |||
646 | 664 | | |
647 | 665 | | |
648 | 666 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
653 | 675 | | |
654 | 676 | | |
655 | 677 | | |
| |||
665 | 687 | | |
666 | 688 | | |
667 | 689 | | |
| 690 | + | |
668 | 691 | | |
669 | 692 | | |
670 | 693 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
906 | 908 | | |
907 | 909 | | |
908 | 910 | | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
909 | 939 | | |
910 | 940 | | |
911 | 941 | | |
| |||
0 commit comments