Class CohereStreamParser
java.lang.Object
org.apache.camel.component.aws2.bedrock.runtime.stream.CohereStreamParser
- All Implemented Interfaces:
StreamResponseParser
Parser for Cohere model streaming responses
Cohere streaming response format: {"is_finished": false, "event_type": "text-generation", "text": "chunk"} {"is_finished": false, "event_type": "text-generation", "text": " more"} {"is_finished": true, "event_type": "stream-end", "finish_reason": "COMPLETE", "response": {...}}
-
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
-
CohereStreamParser
public CohereStreamParser()
-
-
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
-