Class BetaMessageAccumulator
-
- All Implemented Interfaces:
public final class BetaMessageAccumulatorAn accumulator that constructs a BetaMessage from a sequence of streamed events. Pass all events from the
message_startevent to themessage_stopevent to accumulate and then call message to get the final accumulated message. The final BetaMessage will be similar to what would have been received had the non-streaming API been used.A BetaMessageAccumulator may only be used to accumulate one message. To accumulate another message, create another instance of BetaMessageAccumulator.
-
-
Method Summary
Modifier and Type Method Description final BetaMessagemessage()Gets the final accumulated message. final <T extends Any> StructuredMessage<T>message(Class<T> outputType)Gets the final accumulated message with support for structured outputs. final BetaRawMessageStreamEventaccumulate(BetaRawMessageStreamEvent event)Accumulates a streamed event and uses it to construct a BetaMessage. final static BetaMessageAccumulatorcreate()-
-
Method Detail
-
message
final BetaMessage message()
Gets the final accumulated message. Until the
message_stopevent has been received, a message will not be available. Wait until all events have been handled by accumulate before calling this method.
-
message
final <T extends Any> StructuredMessage<T> message(Class<T> outputType)
Gets the final accumulated message with support for structured outputs. Until the last event has been accumulated, a StructuredMessage will not be available. Wait until all events have been handled by accumulate before calling this method. See that method for more details on how the last event is detected. See the SDK documentation for more details and example code.
- Parameters:
outputType- The Java class from which the JSON schema in the request was derived.
-
accumulate
final BetaRawMessageStreamEvent accumulate(BetaRawMessageStreamEvent event)
Accumulates a streamed event and uses it to construct a BetaMessage. When all events, including the
message_stopevent, have been accumulated, the message can be retrieved by calling message.- Returns:
The given event for convenience, such as when chaining method calls.
-
create
final static BetaMessageAccumulator create()
-
-
-
-