Class TitanStreamParser
java.lang.Object
org.apache.camel.component.aws2.bedrock.runtime.stream.TitanStreamParser
- All Implemented Interfaces:
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 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
-
TitanStreamParser
public TitanStreamParser()
-
-
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
-