Class SpringAiLlmService
-
- All Implemented Interfaces:
-
com.embabel.agent.spi.LlmService,com.embabel.common.ai.model.AiModel,com.embabel.common.ai.model.LlmMetadata,com.embabel.common.ai.model.ModelMetadata,com.embabel.common.ai.prompt.PromptContributorConsumer,com.embabel.common.core.types.HasInfoString
public final class SpringAiLlmService implements LlmService<SpringAiLlmService>, AiModel<ChatModel>
Spring AI implementation that provides decoupled LLM operations.
Wraps a Spring AI ChatModel and provides the ability to create LlmMessageSender instances for making LLM calls without tight coupling to Spring AI throughout the codebase.
This class is the recommended replacement for the deprecated com.embabel.common.ai.model.Llm class.
-
-
Field Summary
Fields Modifier and Type Field Description private final ChatModelmodelprivate final Stringnameprivate final Stringproviderprivate final ChatModelchatModelprivate final OptionsConverter<?>optionsConverterprivate final LocalDateknowledgeCutoffDateprivate final List<PromptContributor>promptContributorsprivate final PricingModelpricingModelprivate final ModelTypetype
-
Constructor Summary
Constructors Constructor Description SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate, List<PromptContributor> promptContributors, PricingModel pricingModel)SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate, List<PromptContributor> promptContributors)SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate)SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter)SpringAiLlmService(String name, String provider, ChatModel chatModel)
-
Method Summary
Modifier and Type Method Description ChatModelgetModel()StringgetName()StringgetProvider()final ChatModelgetChatModel()final OptionsConverter<?>getOptionsConverter()LocalDategetKnowledgeCutoffDate()List<PromptContributor>getPromptContributors()PricingModelgetPricingModel()LlmMessageSendercreateMessageSender(LlmOptions options)Create a message sender for this LLM configured with the given options. SpringAiLlmServicewithKnowledgeCutoffDate(LocalDate date)Returns a copy of this LLM service with the specified knowledge cutoff date. SpringAiLlmServicewithPromptContributor(PromptContributor promptContributor)Returns a copy of this LLM service with an additional prompt contributor. final SpringAiLlmServicewithOptionsConverter(OptionsConverter<?> converter)Returns a copy with a different options converter. -
-
Constructor Detail
-
SpringAiLlmService
SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate, List<PromptContributor> promptContributors, PricingModel pricingModel)
- Parameters:
name- Name of the LLMprovider- Name of the provider (e.g.chatModel- The Spring AI ChatModel to use for LLM callsoptionsConverter- Function to convert LlmOptions to Spring AI ChatOptionsknowledgeCutoffDate- Model's knowledge cutoff date, if knownpromptContributors- List of prompt contributors for this model.pricingModel- Pricing model for this LLM, if known
-
SpringAiLlmService
SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate, List<PromptContributor> promptContributors)
- Parameters:
name- Name of the LLMprovider- Name of the provider (e.g.chatModel- The Spring AI ChatModel to use for LLM callsoptionsConverter- Function to convert LlmOptions to Spring AI ChatOptionsknowledgeCutoffDate- Model's knowledge cutoff date, if knownpromptContributors- List of prompt contributors for this model.
-
SpringAiLlmService
SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter, LocalDate knowledgeCutoffDate)
- Parameters:
name- Name of the LLMprovider- Name of the provider (e.g.chatModel- The Spring AI ChatModel to use for LLM callsoptionsConverter- Function to convert LlmOptions to Spring AI ChatOptionsknowledgeCutoffDate- Model's knowledge cutoff date, if known
-
SpringAiLlmService
SpringAiLlmService(String name, String provider, ChatModel chatModel, OptionsConverter<?> optionsConverter)
- Parameters:
name- Name of the LLMprovider- Name of the provider (e.g.chatModel- The Spring AI ChatModel to use for LLM callsoptionsConverter- Function to convert LlmOptions to Spring AI ChatOptions
-
-
Method Detail
-
getModel
ChatModel getModel()
-
getProvider
String getProvider()
-
getChatModel
final ChatModel getChatModel()
-
getOptionsConverter
final OptionsConverter<?> getOptionsConverter()
-
getKnowledgeCutoffDate
LocalDate getKnowledgeCutoffDate()
-
getPromptContributors
List<PromptContributor> getPromptContributors()
-
getPricingModel
PricingModel getPricingModel()
-
createMessageSender
LlmMessageSender createMessageSender(LlmOptions options)
Create a message sender for this LLM configured with the given options.
The message sender handles the actual LLM API calls but does NOT execute tools - it returns the LLM's response including any tool call requests.
- Parameters:
options- Configuration options for the LLM call (temperature, max tokens, etc.- Returns:
A message sender configured for this LLM
-
withKnowledgeCutoffDate
SpringAiLlmService withKnowledgeCutoffDate(LocalDate date)
Returns a copy of this LLM service with the specified knowledge cutoff date.
- Parameters:
date- The knowledge cutoff date for the model- Returns:
A new instance with the updated cutoff date
-
withPromptContributor
SpringAiLlmService withPromptContributor(PromptContributor promptContributor)
Returns a copy of this LLM service with an additional prompt contributor.
- Parameters:
promptContributor- The prompt contributor to add- Returns:
A new instance with the added contributor
-
withOptionsConverter
final SpringAiLlmService withOptionsConverter(OptionsConverter<?> converter)
Returns a copy with a different options converter.
-
-
-
-