Annotation Interface RegisterAiService


@Retention(RUNTIME) @Target(TYPE) public @interface RegisterAiService
Used to create Langchain4j's 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 ApplicationScoped.

  • Element Details

    • chatLanguageModelSupplier

      Class<? extends Supplier<dev.langchain4j.model.chat.ChatLanguageModel>> chatLanguageModelSupplier
      Configures the way to obtain the ChatLanguageModel to use. If not configured, the default CDI bean implementing the model is looked up. Such a bean provided automatically by extensions such as quarkus-langchain4j-openai, quarkus-langchain4j-azure-openai or quarkus-langchain4j-hugging-face
      Default:
      io.quarkiverse.langchain4j.RegisterAiService.BeanChatLanguageModelSupplier.class
    • tools

      Class<?>[] tools
      Tool classes to use. All tools are expected to be CDI beans.

      NOTE: when this is used, chatMemoryProviderSupplier must NOT be set to RegisterAiService.NoChatMemoryProviderSupplier.

      Default:
      {}
    • chatMemoryProviderSupplier

      Class<? extends Supplier<dev.langchain4j.memory.chat.ChatMemoryProvider>> chatMemoryProviderSupplier
      Configures the way to obtain the ChatMemoryProvider to use. By default, Quarkus will look for a CDI bean that implements ChatMemoryProvider, but will fall back to not using any memory if no such bean exists. If an arbitrary ChatMemoryProvider instance is needed, a custom implementation of Supplier<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 to RegisterAiService.BeanChatMemoryProviderSupplier

      Default:
      io.quarkiverse.langchain4j.RegisterAiService.BeanIfExistsChatMemoryProviderSupplier.class
    • retrieverSupplier

      Class<? extends Supplier<dev.langchain4j.retriever.Retriever<dev.langchain4j.data.segment.TextSegment>>> retrieverSupplier
      Configures the way to obtain the Retriever to use (when using RAG). By default, no chat memory is used. If a CDI bean of type ChatMemory is needed, the value should be RegisterAiService.BeanRetrieverSupplier. If an arbitrary ChatMemory instance is needed, a custom implementation of Supplier<dev.langchain4j.memory.ChatMemory> needs to be provided.
      Default:
      io.quarkiverse.langchain4j.RegisterAiService.NoRetrieverSupplier.class