Class ClaudeStreamParser

java.lang.Object
org.apache.camel.component.aws2.bedrock.runtime.stream.ClaudeStreamParser
All Implemented Interfaces:
StreamResponseParser

public class ClaudeStreamParser extends Object implements 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 Details

    • ClaudeStreamParser

      public ClaudeStreamParser()
  • Method Details

    • extractText

      public String extractText(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Description copied from interface: StreamResponseParser
      Extract text content from a streaming chunk
      Specified by:
      extractText in interface StreamResponseParser
      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: StreamResponseParser
      Extract the completion reason from a streaming chunk (if present)
      Specified by:
      extractCompletionReason in interface StreamResponseParser
      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: StreamResponseParser
      Extract the token count from a streaming chunk (if present)
      Specified by:
      extractTokenCount in interface StreamResponseParser
      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

      public boolean isFinalChunk(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Description copied from interface: StreamResponseParser
      Check if this chunk represents the end of the stream
      Specified by:
      isFinalChunk in interface StreamResponseParser
      Parameters:
      chunk - the JSON chunk from the stream
      Returns:
      true if this is the final chunk
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException