Class ObservabilityListeners
java.lang.Object
dev.langchain4j.internal.ObservabilityListeners
Adds the listeners of the
ObservabilityListenersProviders found with ServiceLoader to AI Services
and to model calls. The providers are looked up once, in the class loader of LangChain4j. A framework that loads the
application with class loaders of its own (for example Quarkus) finds the providers of those class loaders with
load(ClassLoader) and passes them to useFrameworkProviders(List). Only providers of LangChain4j itself (classes in
dev.langchain4j packages) are used: they receive the content of every model call, so a provider of another
library on the classpath is logged and skipped. A provider that cannot be loaded, or whose listeners cannot be
obtained, is logged and skipped: it never breaks an AI Service or a model call.-
Method Summary
Modifier and TypeMethodDescriptionstatic List<ChatModelListener> chat(List<ChatModelListener> listeners) static List<DecisionModelListener> decision(List<DecisionModelListener> listeners) static List<EmbeddingModelListener> embedding(List<EmbeddingModelListener> listeners) static List<ObservabilityListenersProvider> load(ClassLoader classLoader) Loads the providers found withServiceLoaderin the given class loader, each time it is called.static List<ModerationModelListener> moderation(List<ModerationModelListener> listeners) static voidregisterWith(AiServiceListenerRegistrar registrar) Registers the provided AI Service listeners with the given registrar, once per registrar, so that a registrar shared by several AI Services does not receive the same listener several times.static List<ScoringModelListener> scoring(List<ScoringModelListener> listeners) static voiduseFrameworkProviders(List<ObservabilityListenersProvider> frameworkProviders) Uses the given providers, found by a framework in the class loaders of the application (seeload(ClassLoader)), in addition to the providers of LangChain4j's own class loader.
-
Method Details
-
registerWith
Registers the provided AI Service listeners with the given registrar, once per registrar, so that a registrar shared by several AI Services does not receive the same listener several times. -
chat
-
embedding
-
moderation
-
scoring
-
decision
-
useFrameworkProviders
Uses the given providers, found by a framework in the class loaders of the application (seeload(ClassLoader)), in addition to the providers of LangChain4j's own class loader. They replace the providers given before: a framework calls this method each time it starts the application, and with an empty list when it stops it. A provider class found in both is used once, from the framework's providers. -
load
Loads the providers found withServiceLoaderin the given class loader, each time it is called. Only providers of LangChain4j are returned; a provider that cannot be loaded is logged and skipped.
-