Interface StreamingChatResponseHandler


public interface StreamingChatResponseHandler
TODO review all javadoc in this class Represents a handler for streaming a response from a StreamingChatLanguageModel.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onCompleteResponse(ChatResponse completeResponse)
    Invoked when the model has finished streaming a response.
    void
    This method is invoked when an error occurs during streaming.
    void
    onPartialResponse(String partialResponse)
    Invoked each time the model generates a partial response (usually a single token) in a textual response.
  • Method Details

    • onPartialResponse

      void onPartialResponse(String partialResponse)
      Invoked each time the model generates a partial response (usually a single token) in a textual response. If the model decides to execute a tool instead, this method will not be invoked; onCompleteResponse(dev.langchain4j.model.chat.response.ChatResponse) will be invoked instead.
      Parameters:
      partialResponse - The partial response (usually a single token), which is a part of the complete response.
    • onCompleteResponse

      void onCompleteResponse(ChatResponse completeResponse)
      Invoked when the model has finished streaming a response. If the model requests the execution of one or multiple tools, this can be accessed via ChatResponse.aiMessage() -> AiMessage.toolExecutionRequests().
      Parameters:
      completeResponse - The complete response generated by the model. For textual responses, it contains all tokens from onPartialResponse(java.lang.String) concatenated.
    • onError

      void onError(Throwable error)
      This method is invoked when an error occurs during streaming.
      Parameters:
      error - The error that occurred