Interface StreamingResponseHandler

  • All Implemented Interfaces:

    
    public interface StreamingResponseHandler<T>
    
                        

    Represents a handler for streaming responses from a language model. The handler is invoked each time the model generates a new token in a textual response. If the model executes a tool instead, onComplete will be invoked instead.

    • 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
    • Method Summary

      Modifier and Type Method Description
      abstract void onNext(String token) Invoked each time the language model generates a new token in a textual response.
      void onComplete(Response<T> response) Invoked when the language model has finished streaming a response.
      abstract void onError(Throwable error) This method is invoked when an error occurs during streaming.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • onNext

         abstract void onNext(String token)

        Invoked each time the language model generates a new token in a textual response. If the model executes a tool instead, this method will not be invoked; onComplete will be invoked instead.

        Parameters:
        token - The newly generated token, which is a part of the complete response.
      • onComplete

         void onComplete(Response<T> response)

        Invoked when the language model has finished streaming a response. If the model executes one or multiple tools, it is accessible via toolExecutionRequests.

        Parameters:
        response - The complete response generated by the language model.
      • onError

         abstract void onError(Throwable error)

        This method is invoked when an error occurs during streaming.

        Parameters:
        error - The error that occurred