Interface StreamResponseParser

All Known Implementing Classes:
ClaudeStreamParser, CohereStreamParser, LlamaStreamParser, MistralStreamParser, TitanStreamParser

public interface StreamResponseParser
Parser interface for extracting text and metadata from streaming responses of different Bedrock models
  • Method Details

    • extractText

      String extractText(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Extract text content from a streaming chunk
      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

      String extractCompletionReason(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Extract the completion reason from a streaming chunk (if present)
      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

      Integer extractTokenCount(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Extract the token count from a streaming chunk (if present)
      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

      boolean isFinalChunk(String chunk) throws com.fasterxml.jackson.core.JsonProcessingException
      Check if this chunk represents the end of the stream
      Parameters:
      chunk - the JSON chunk from the stream
      Returns:
      true if this is the final chunk
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException