gnodet-bot commented on code in PR #29461:
URL: https://github.com/apache/camel/pull/29461#discussion_r4511804507
##########
components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/stream/NovaStreamParser.java:
##########
@@ -30,35 +31,35 @@
*/
public class NovaStreamParser implements StreamResponseParser {
- private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static final ObjectMapper MAPPER =
JsonMapper.builderWithJackson2Defaults().build();
@Override
- public String extractText(String chunk) throws JsonProcessingException {
+ public String extractText(String chunk) throws JacksonException {
JsonNode text = path(chunk, "contentBlockDelta", "delta", "text");
- return text != null ? text.asText() : "";
+ return text != null ? text.asString() : "";
}
@Override
- public String extractCompletionReason(String chunk) throws
JsonProcessingException {
+ public String extractCompletionReason(String chunk) throws
JacksonException {
JsonNode stopReason = path(chunk, "messageStop", "stopReason");
- return stopReason != null ? stopReason.asText() : null;
+ return stopReason != null ? stopReason.asString() : null;
}
@Override
- public Integer extractTokenCount(String chunk) throws
JsonProcessingException {
+ public Integer extractTokenCount(String chunk) throws JacksonException {
JsonNode outputTokens = path(chunk, "metadata", "usage",
"outputTokens");
return outputTokens != null ? outputTokens.asInt() : null;
}
@Override
- public boolean isFinalChunk(String chunk) throws JsonProcessingException {
+ public boolean isFinalChunk(String chunk) throws JacksonException {
Review Comment:
🔧 `NovaStreamParser` is the only `StreamResponseParser` implementation that
still declares `throws JacksonException` on the interface methods. All other
parsers (`ClaudeStreamParser`, `CohereStreamParser`, `LlamaStreamParser`,
`MistralStreamParser`, `TitanStreamParser`) have no `throws` clause, matching
the updated `StreamResponseParser` interface. Since `JacksonException` is
unchecked in Jackson 3 this compiles fine either way, but the inconsistency
stands out. Drop the `throws` declarations here to match the rest.
```suggestion
public String extractText(String chunk) {
JsonNode text = path(chunk, "contentBlockDelta", "delta", "text");
return text != null ? text.asString() : "";
}
@Override
public String extractCompletionReason(String chunk) {
JsonNode stopReason = path(chunk, "messageStop", "stopReason");
return stopReason != null ? stopReason.asString() : null;
}
@Override
public Integer extractTokenCount(String chunk) {
JsonNode outputTokens = path(chunk, "metadata", "usage",
"outputTokens");
return outputTokens != null ? outputTokens.asInt() : null;
}
@Override
public boolean isFinalChunk(String chunk) {
return path(chunk, "messageStop") != null;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]