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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • 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, or ResponseFailedEvent is accumulated. After that event, no more events are expected.

        Returns:

        The given event for convenience, such as when chaining method calls.