Annotation Interface RegisterAiService
AiServices
in a declarative manner that the application can then use simply by
using the class as a CDI bean.
Under the hood Langchain4j's AiServices.builder(Class)
is called
while also providing the builder with the proper ChatLanguageModel
bean (mandatory), tools
bean (optional),
ChatMemoryProvider
and Retriever
beans (which by default are configured if such beans exist).
NOTE: The resulting CDI bean is RequestScoped
by default. If you need to change the scope,
simply annotate the class with a CDI scope.
CAUTION: When using anything other than the request scope, you need to be very careful with the chat memory implementation.
NOTE: When the application also contains the quarkus-micrometer
extension, metrics are automatically generated
for the method invocations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Marker that is used to tell Quarkus to use theChatLanguageModel
that has been configured as a CDI bean by any of the extensions providing such capability (such asquarkus-langchain4j-openai
andquarkus-langchain4j-hugging-face
).static final class
Marker that is used to tell Quarkus to use the retriever that the user has configured as a CDI bean.static final class
Marker that is used to tell Quarkus to use theAuditService
that the user has configured as a CDI bean.static final class
Marker that is used to tell Quarkus to use theModerationModel
that has been configured as a CDI bean by any of the extensions providing such capability (such asquarkus-langchain4j-openai
andquarkus-langchain4j-azure-openai
).static final class
Marker class to indicate that no moderation model should be usedstatic final class
Marker class to indicate that no retriever should be used -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<? extends Supplier<AuditService>>
Configures the way to obtain theAuditService
to use.Configures the way to obtain theChatLanguageModel
to use.Configures the way to obtain theChatMemoryProvider
.Configures the way to obtain theModerationModel
to use.Class<? extends dev.langchain4j.retriever.Retriever<dev.langchain4j.data.segment.TextSegment>>
Configures the way to obtain theRetriever
to use (when using RAG).Class<?>[]
Tool classes to use.
-
Element Details
-
chatLanguageModelSupplier
Configures the way to obtain theChatLanguageModel
to use. If not configured, the default CDI bean implementing the model is looked up. Such a bean provided automatically by extensions such asquarkus-langchain4j-openai
,quarkus-langchain4j-azure-openai
orquarkus-langchain4j-hugging-face
- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanChatLanguageModelSupplier.class
-
tools
Class<?>[] toolsTool classes to use. All tools are expected to be CDI beans.- Default:
- {}
-
chatMemoryProviderSupplier
Class<? extends Supplier<dev.langchain4j.memory.chat.ChatMemoryProvider>> chatMemoryProviderSupplierConfigures the way to obtain theChatMemoryProvider
.Be default, Quarkus configures a
ChatMemoryProvider
bean that uses aInMemoryChatMemoryStore
bean as the backing store. The default type for the actualChatMemory
isMessageWindowChatMemory
and it is configured with the value of thequarkus.langchain4j.chat-memory.memory-window.max-messages
configuration property (which default to 10) as a way of limiting the number of messages in each chat.If the application provides its own
ChatMemoryProvider
bean, that takes precedence over what Quarkus provides as the default.If the application provides an implementation of
ChatMemoryStore
, then that is used instead of the defaultInMemoryChatMemoryStore
.In the most advances case, an arbitrary
ChatMemoryProvider
can be used by having a customSupplier<ChatMemoryProvider>
configured in this property.Supplier<dev.langchain4j.memory.chat.ChatMemoryProvider>
needs to be provided.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanChatMemoryProviderSupplier.class
-
retriever
Class<? extends dev.langchain4j.retriever.Retriever<dev.langchain4j.data.segment.TextSegment>> retrieverConfigures the way to obtain theRetriever
to use (when using RAG). All tools are expected to be CDI beans By default, no supplier is used.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.NoRetriever.class
-
auditServiceSupplier
Class<? extends Supplier<AuditService>> auditServiceSupplierConfigures the way to obtain theAuditService
to use. By default, Quarkus will look for a CDI bean that implementsAuditService
, but will fall back to not using any memory if no such bean exists. If an arbitraryAuditService
instance is needed, a custom implementation ofSupplier<AuditService>
needs to be provided.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanIfExistsAuditServiceSupplier.class
-
moderationModelSupplier
Configures the way to obtain theModerationModel
to use. By default, no moderation model is used. If a CDI bean of typeChatMemory
is needed, the value should beBeanRetrieverSupplier
. If an arbitraryChatMemory
instance is needed, a custom implementation ofSupplier<dev.langchain4j.memory.ChatMemory>
needs to be provided.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.NoModerationModelSupplier.class
-