Class ClaudeStreamParser
java.lang.Object
org.apache.camel.component.aws2.bedrock.runtime.stream.ClaudeStreamParser
- All Implemented Interfaces:
StreamResponseParser
Parser for Anthropic Claude model streaming responses (v3+ format)
Claude streaming response format: {"type": "message_start", "message": {...}} {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}} {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "chunk"}} {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": " more"}} {"type": "content_block_stop", "index": 0} {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null}, "usage": {"output_tokens": 150}} {"type": "message_stop"}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionextractCompletionReason(String chunk) Extract the completion reason from a streaming chunk (if present)extractText(String chunk) Extract text content from a streaming chunkextractTokenCount(String chunk) Extract the token count from a streaming chunk (if present)booleanisFinalChunk(String chunk) Check if this chunk represents the end of the stream
-
Constructor Details
-
ClaudeStreamParser
public ClaudeStreamParser()
-
-
Method Details
-
extractText
Description copied from interface:StreamResponseParserExtract text content from a streaming chunk- Specified by:
extractTextin interfaceStreamResponseParser- Parameters:
chunk- the JSON chunk from the stream- Returns:
- the extracted text content, or empty string if no text in this chunk
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
extractCompletionReason
public String extractCompletionReason(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException Description copied from interface:StreamResponseParserExtract the completion reason from a streaming chunk (if present)- Specified by:
extractCompletionReasonin interfaceStreamResponseParser- Parameters:
chunk- the JSON chunk from the stream- Returns:
- the completion reason, or null if not present in this chunk
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
extractTokenCount
public Integer extractTokenCount(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException Description copied from interface:StreamResponseParserExtract the token count from a streaming chunk (if present)- Specified by:
extractTokenCountin interfaceStreamResponseParser- Parameters:
chunk- the JSON chunk from the stream- Returns:
- the token count, or null if not present in this chunk
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
isFinalChunk
Description copied from interface:StreamResponseParserCheck if this chunk represents the end of the stream- Specified by:
isFinalChunkin interfaceStreamResponseParser- Parameters:
chunk- the JSON chunk from the stream- Returns:
- true if this is the final chunk
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-