Package dev.langchain4j.model.listener
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 TypeMethodDescriptiondefault voidThis method is called when an error occurs.default voidThis method is called before the request is sent to the model.default voidonResponse(Response response, Request request) This method is called after the response is received from the model.
-
Method Details
-
onRequest
This method is called before the request is sent to the model.- Parameters:
request- The request to the model.
-
onResponse
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
This method is called when an error occurs.
When streaming (e.g., usingStreamingChatLanguageModel), theresponsemight 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.
-