Interface ModelListener<Request,Response>


public interface ModelListener<Request,Response>
A generic model listener. It can listen for requests to and responses from various model types, such as ChatLanguageModel, StreamingChatLanguageModel, EmbeddingModel, etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    onError(Throwable error, Response response, Request request)
    This method is called when an error occurs.
    default void
    onRequest(Request request)
    This method is called before the request is sent to the model.
    default void
    onResponse(Response response, Request request)
    This method is called after the response is received from the model.
  • Method Details

    • onRequest

      default void onRequest(Request request)
      This method is called before the request is sent to the model.
      Parameters:
      request - The request to the model.
    • onResponse

      default void onResponse(Response response, Request request)
      This method is called after the response is received from the model.
      Parameters:
      response - The response from the model.
      request - The request this response corresponds to.
    • onError

      default void onError(Throwable error, Response response, Request request)
      This method is called when an error occurs.
      When streaming (e.g., using StreamingChatLanguageModel), the response might contain a partial response that was received before the error occurred.
      Parameters:
      error - The error that occurred.
      response - The partial response, if available.
      request - The request this error corresponds to.