Skip to content

Commit 4b1c6d2

Browse files
committed
Optimize BedrockAnthropic3ChatModel.extractUsage
1 parent 6d4c75e commit 4b1c6d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/anthropic3/BedrockAnthropic3ChatModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ChatResponse call(Prompt prompt) {
9191
ChatResponseMetadata metadata = ChatResponseMetadata.builder()
9292
.withId(response.id())
9393
.withModel(response.model())
94-
.withUsage(extractUsage(response))
94+
.withUsage(extractUsage(response.usage()))
9595
.build();
9696

9797
return new ChatResponse(generations, metadata);
@@ -124,17 +124,17 @@ public Flux<ChatResponse> stream(Prompt prompt) {
124124
});
125125
}
126126

127-
private Usage extractUsage(AnthropicChatResponse response) {
127+
private Usage extractUsage(Anthropic3ChatBedrockApi.AnthropicUsage usage) {
128128
return new Usage() {
129129

130130
@Override
131131
public Long getPromptTokens() {
132-
return response.usage().inputTokens().longValue();
132+
return usage.inputTokens().longValue();
133133
}
134134

135135
@Override
136136
public Long getGenerationTokens() {
137-
return response.usage().outputTokens().longValue();
137+
return usage.outputTokens().longValue();
138138
}
139139
};
140140
}

0 commit comments

Comments
 (0)