Package io.jmix.aitools
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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.ObjectProvider<org.springframework.ai.chat.client.ChatClient.Builder> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected org.springframework.ai.chat.client.ChatClient.Builderorg.springframework.ai.chat.client.ChatClientCreates a simple chat client with no extra configurations.org.springframework.ai.chat.client.ChatClientcreateChatClient(Consumer<org.springframework.ai.chat.client.ChatClient.Builder> builderCustomizer) Creates a chat client, applying the given customizer to the builder before building.Optional<org.springframework.ai.chat.client.ChatClient> Creates aChatClientwith the default advisors, or an emptyOptionalwhen Spring AI is not configured (seeisConfigured()).booleanWhether a usableChatClient.Builderis available, i.e.
-
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:
afterPropertiesSetin interfaceorg.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 aChatClientwith the default advisors, or an emptyOptionalwhen Spring AI is not configured (seeisConfigured()).- Returns:
- a new chat client with default advisors, or empty when Spring AI is not configured
-
isConfigured
public boolean isConfigured()Whether a usableChatClient.Builderis available, i.e. the application has a configured Spring AI model.- Returns:
trueif a Spring AI model is configured
-
createBuilder
protected org.springframework.ai.chat.client.ChatClient.Builder createBuilder()
-