Class ChatClientFactory

java.lang.Object
io.jmix.aitools.ChatClientFactory
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

@NullMarked @Component("aitls_ChatClientFactory") public class ChatClientFactory extends Object implements org.springframework.beans.factory.InitializingBean
Class is a ChatClient factory. It creates instances from the application's configured Spring AI model.
  • Field Details

    • chatClientBuilderProvider

      @Autowired protected org.springframework.beans.factory.ObjectProvider<org.springframework.ai.chat.client.ChatClient.Builder> chatClientBuilderProvider
  • Constructor Details

    • ChatClientFactory

      public ChatClientFactory()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • createChatClient

      public org.springframework.ai.chat.client.ChatClient createChatClient()
      Creates a simple chat client with no extra configurations.
      Returns:
      a new chat client
      Throws:
      IllegalStateException - if no Spring AI model is configured
    • createChatClient

      public org.springframework.ai.chat.client.ChatClient createChatClient(Consumer<org.springframework.ai.chat.client.ChatClient.Builder> builderCustomizer)
      Creates a chat client, applying the given customizer to the builder before building.
      Parameters:
      builderCustomizer - customizer applied to the chat client builder
      Returns:
      a new chat client
      Throws:
      IllegalStateException - if no Spring AI model is configured
    • createChatClientWithDefaultAdvisors

      public Optional<org.springframework.ai.chat.client.ChatClient> createChatClientWithDefaultAdvisors()
      Creates a ChatClient with the default advisors, or an empty Optional when Spring AI is not configured (see isConfigured()).
      Returns:
      a new chat client with default advisors, or empty when Spring AI is not configured
    • isConfigured

      public boolean isConfigured()
      Whether a usable ChatClient.Builder is available, i.e. the application has a configured Spring AI model.
      Returns:
      true if a Spring AI model is configured
    • createBuilder

      protected org.springframework.ai.chat.client.ChatClient.Builder createBuilder()