-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: output cached tokens for <RequestLogsRow />
#20974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+165
−0
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
553824d
feat: v1 of requestlogsrow cached tokens
jakehwll be38c10
feat: implement `magicMetadataMerge()`
jakehwll 362b29e
chore: add `TODO` comment
jakehwll e6f320f
fix: convert to `function` and use correct type
jakehwll 6dc7f70
chore: remove unnecessary lodash
jakehwll 374a899
fix: update heading in result
jakehwll 52656f1
Merge branch 'main' into jakehwll/requestlogsrow-cached-tokens
jakehwll 4c49d23
Merge branch 'main' into jakehwll/requestlogsrow-cached-tokens
jakehwll d73ed23
feat: address feedback for merging fields
jakehwll 396e1c3
fix: add handling for `null` objects
jakehwll 52cadd3
fix: add a merged type for `tokenUsageMetadata`
jakehwll 55b606e
Merge branch 'main' into jakehwll/requestlogsrow-cached-tokens
jakehwll 38c9a7c
Merge branch 'main' into jakehwll/requestlogsrow-cached-tokens
jakehwll d178022
feat: add test suite
jakehwll f735fdb
Merge branch 'main' into jakehwll/requestlogsrow-cached-tokens
jakehwll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
site/src/pages/AIBridgePage/RequestLogsPage/RequestLogsRow/RequestLogsRow.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { tokenUsageMetadataMerge } from "./RequestLogsRow"; | ||
|
|
||
| describe("tokenUsageMetadataMerge", () => { | ||
| it("returns null when inputs are null or empty", () => { | ||
| const result = tokenUsageMetadataMerge(null, {}, null); | ||
|
|
||
| expect(result).toBeNull(); | ||
| }); | ||
|
|
||
| it("returns data when there are no shared keys across metadata", () => { | ||
| const metadataA = { input_tokens: 5 }; | ||
| const metadataB = { output_tokens: 2 }; | ||
|
|
||
| const result = tokenUsageMetadataMerge(metadataA, metadataB); | ||
|
|
||
| expect(result).toEqual([metadataA, metadataB]); | ||
| }); | ||
|
|
||
| it("sums numeric values for common keys and keeps non-common keys", () => { | ||
| const metadataA = { | ||
| input_tokens: 5, | ||
| model: "gpt-4", | ||
| }; | ||
| const metadataB = { | ||
| input_tokens: 3, | ||
| output_tokens: 2, | ||
| }; | ||
|
|
||
| const result = tokenUsageMetadataMerge(metadataA, metadataB); | ||
|
|
||
| expect(result).toEqual({ | ||
| input_tokens: 8, | ||
| model: "gpt-4", | ||
| output_tokens: 2, | ||
| }); | ||
| }); | ||
|
|
||
| it("preserves identical non-numeric values for common keys", () => { | ||
| const metadataA = { | ||
| note: "sync", | ||
| status: "ok", | ||
| }; | ||
| const metadataB = { | ||
| note: "sync", | ||
| status: "ok", | ||
| }; | ||
|
|
||
| const result = tokenUsageMetadataMerge(metadataA, metadataB); | ||
|
|
||
| expect(result).toEqual({ | ||
| note: "sync", | ||
| status: "ok", | ||
| }); | ||
| }); | ||
|
|
||
| it("returns the original metadata array when a conflict cannot be resolved", () => { | ||
| const metadataA = { | ||
| input_tokens: 1, | ||
| label: "a", | ||
| }; | ||
| const metadataB = { | ||
| input_tokens: 3, | ||
| label: "b", | ||
| }; | ||
|
|
||
| const result = tokenUsageMetadataMerge(metadataA, metadataB); | ||
|
|
||
| expect(result).toEqual([metadataA, metadataB]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.