Class ObservationChatModelListener
java.lang.Object
dev.langchain4j.observation.listener.ObservationChatModelListener
- All Implemented Interfaces:
ChatModelListener
Will use observations and micrometer metrics to generate telemetry based on the
ChatModelListener lifecycle.
Observations will handle request durations and tracing. Observation lifecycle and context management is handled here.
There is a Micrometer DistributionSummary responsible to record token usage.
-
Constructor Summary
ConstructorsConstructorDescriptionObservationChatModelListener(io.micrometer.observation.ObservationRegistry observationRegistry, io.micrometer.core.instrument.MeterRegistry meterRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoidonError(ChatModelErrorContext errorContext) This method is called when an error occurs during interaction with the model.voidonRequest(ChatModelRequestContext requestContext) This method is called before the request is sent to the model.voidonResponse(ChatModelResponseContext responseContext) This method is called after the response is received from the model.
-
Constructor Details
-
ObservationChatModelListener
public ObservationChatModelListener(io.micrometer.observation.ObservationRegistry observationRegistry, io.micrometer.core.instrument.MeterRegistry meterRegistry)
-
-
Method Details
-
onRequest
Description copied from interface:ChatModelListenerThis method is called before the request is sent to the model.- Specified by:
onRequestin interfaceChatModelListener- Parameters:
requestContext- The request context. It contains theChatRequestand attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-
onResponse
Description copied from interface:ChatModelListenerThis method is called after the response is received from the model.- Specified by:
onResponsein interfaceChatModelListener- Parameters:
responseContext- The response context. It containsChatResponse, correspondingChatRequestand attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-
onError
Description copied from interface:ChatModelListenerThis method is called when an error occurs during interaction with the model.- Specified by:
onErrorin interfaceChatModelListener- Parameters:
errorContext- The error context. It contains the error, correspondingChatRequest, partialChatResponse(if available) and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
-