Class ResponseAccumulator
-
- All Implemented Interfaces:
public final class ResponseAccumulator
An accumulator that constructs a Response from a sequence of streamed events. Pass all events to accumulate and then call response to get the final accumulated response. The final
Response
will be similar to what would have been received had the non-streaming API been used.A ResponseAccumulator may only be used to accumulate one response. To accumulate another response, create another instance of
ResponseAccumulator
.
-
-
Method Summary
Modifier and Type Method Description final Response
response()
Gets the final accumulated response. final <T extends Any> StructuredResponse<T>
response(Class<T> responseType)
Gets the final accumulated response with support for structured outputs. final ResponseStreamEvent
accumulate(ResponseStreamEvent event)
Accumulates a streamed event and uses it to construct a Response. final static ResponseAccumulator
create()
-
-
Method Detail
-
response
final Response response()
Gets the final accumulated response. Until the last event has been accumulated, a Response will not be available. Wait until all events have been handled by accumulate before calling this method.
-
response
final <T extends Any> StructuredResponse<T> response(Class<T> responseType)
Gets the final accumulated response with support for structured outputs. Until the last event has been accumulated, a StructuredResponse 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:
responseType
- The Java class from which the JSON schema in the request was derived.
-
accumulate
final ResponseStreamEvent accumulate(ResponseStreamEvent event)
Accumulates a streamed event and uses it to construct a Response. When all events have been accumulated, the response can be retrieved by calling response. The last event is detected if one of
ResponseCompletedEvent
,ResponseIncompleteEvent
, orResponseFailedEvent
is accumulated. After that event, no more events are expected.- Returns:
The given event for convenience, such as when chaining method calls.
-
create
final static ResponseAccumulator create()
-
-
-
-