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 classMarker that is used to tell Quarkus to use theChatLanguageModelthat has been configured as a CDI bean by any of the extensions providing such capability (such asquarkus-langchain4j-openaiandquarkus-langchain4j-hugging-face).static final classMarker that is used to tell Quarkus to use the retriever that the user has configured as a CDI bean.static final classMarker that is used to tell Quarkus to use theAuditServicethat the user has configured as a CDI bean.static final classMarker that is used to tell Quarkus to use theChatMemoryProviderthat the user has configured as a CDI bean.static final classMarker that is used to tell Quarkus to use theRetrieverthat the user has configured as a CDI bean.static final classMarker that is used to tell Quarkus to use the retriever that the user has configured as a CDI beanstatic final classMarker class to indicate that no chat memory should be usedstatic final classMarker 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 theAuditServiceto use.Configures the way to obtain theChatLanguageModelto use.Configures the way to obtain theChatMemoryProviderto use.Class<? extends Supplier<dev.langchain4j.retriever.Retriever<dev.langchain4j.data.segment.TextSegment>>>Configures the way to obtain theRetrieverto use (when using RAG).Class<?>[]Tool classes to use.
-
Element Details
-
chatLanguageModelSupplier
Configures the way to obtain theChatLanguageModelto 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-openaiorquarkus-langchain4j-hugging-face- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanChatLanguageModelSupplier.class
-
tools
Class<?>[] toolsTool classes to use. All tools are expected to be CDI beans.NOTE: when this is used, either a
ChatMemoryProviderbean must be present in the application, or a customSupplier<dev.langchain4j.memory.chat.ChatMemoryProvider>must be set.- Default:
- {}
-
chatMemoryProviderSupplier
Class<? extends Supplier<dev.langchain4j.memory.chat.ChatMemoryProvider>> chatMemoryProviderSupplierConfigures the way to obtain theChatMemoryProviderto use. By default, Quarkus will look for a CDI bean that implementsChatMemoryProvider, but will fall back to not using any memory if no such bean exists. If an arbitraryChatMemoryProviderinstance is needed, a custom implementation ofSupplier<dev.langchain4j.memory.chat.ChatMemoryProvider>needs to be provided.If the memory provider to use is exposed as a CDI bean exposing the type
ChatMemoryProvider, then set the value toRegisterAiService.BeanChatMemoryProviderSupplierNOTE: when
tools()is set, the default is changed toRegisterAiService.BeanChatMemoryProviderSupplierwhich means that a bean aChatMemoryProviderbean must be present. The alternative in this case is to set a customSupplier<dev.langchain4j.memory.chat.ChatMemoryProvider>.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanIfExistsChatMemoryProviderSupplier.class
-
retrieverSupplier
Class<? extends Supplier<dev.langchain4j.retriever.Retriever<dev.langchain4j.data.segment.TextSegment>>> retrieverSupplierConfigures the way to obtain theRetrieverto use (when using RAG). By default, no chat memory is used. If a CDI bean of typeChatMemoryis needed, the value should beRegisterAiService.BeanRetrieverSupplier. If an arbitraryChatMemoryinstance is needed, a custom implementation ofSupplier<dev.langchain4j.memory.ChatMemory>needs to be provided.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.NoRetrieverSupplier.class
-
auditServiceSupplier
Class<? extends Supplier<AuditService>> auditServiceSupplierConfigures the way to obtain theAuditServiceto 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 arbitraryAuditServiceinstance is needed, a custom implementation ofSupplier<AuditService>needs to be provided.- Default:
- io.quarkiverse.langchain4j.RegisterAiService.BeanIfExistsAuditServiceSupplier.class
-