-
Notifications
You must be signed in to change notification settings - Fork 2k
refactor: enhance ChatGenerationMetadata with metadata Map and Builder #1806
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,12 +78,17 @@ public Flux<ChatResponse> stream(Prompt prompt) { | |
| ChatGenerationMetadata chatGenerationMetadata = null; | ||
| if (chunk.amazonBedrockInvocationMetrics() != null) { | ||
| String completionReason = chunk.completionReason().name(); | ||
| chatGenerationMetadata = ChatGenerationMetadata.from(completionReason, | ||
| chunk.amazonBedrockInvocationMetrics()); | ||
| chatGenerationMetadata = ChatGenerationMetadata.builder() | ||
| .finishReason(completionReason) | ||
| .metadata("usage", chunk.amazonBedrockInvocationMetrics()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be "metrics" ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class BedrockUsage has |
||
| .build(); | ||
| } | ||
| else if (chunk.inputTextTokenCount() != null && chunk.totalOutputTextTokenCount() != null) { | ||
| String completionReason = chunk.completionReason().name(); | ||
| chatGenerationMetadata = ChatGenerationMetadata.from(completionReason, extractUsage(chunk)); | ||
| chatGenerationMetadata = ChatGenerationMetadata.builder() | ||
| .finishReason(completionReason) | ||
| .metadata("usage", extractUsage(chunk)) | ||
| .build(); | ||
| } | ||
| return new ChatResponse( | ||
| List.of(new Generation(new AssistantMessage(chunk.outputText()), chatGenerationMetadata))); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move all these common metadata keys to constants?