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

public class TitanStreamParser extends Object implements StreamResponseParser
Parser for Amazon Titan model streaming responses

Titan streaming response format: {"outputText": "chunk text", "index": 0, "totalOutputTextTokenCount": null, "completionReason": null} {"outputText": "more text", "index": 1, "totalOutputTextTokenCount": null, "completionReason": null} {"outputText": "", "index": 2, "totalOutputTextTokenCount": 150, "completionReason": "FINISH"}

  • Constructor Details

    • TitanStreamParser

      public TitanStreamParser()
  • 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