Package org.springframework.ai.anthropic
Class AnthropicChatModel
java.lang.Object
org.springframework.ai.chat.model.AbstractToolCallSupport
org.springframework.ai.anthropic.AnthropicChatModel
- All Implemented Interfaces:
ChatModel
,StreamingChatModel
,Model<Prompt,
,ChatResponse> StreamingModel<Prompt,
ChatResponse>
The
ChatModel
implementation for the Anthropic service.- Since:
- 1.0.0
- Author:
- Christian Tzolov, luocongqiu, Mariusz Bernacki, Thomas Vitale, Claudio Silva Junior
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Integer
static final String
static final Double
final org.springframework.retry.support.RetryTemplate
The retry template used to retry the OpenAI API calls.Fields inherited from class org.springframework.ai.chat.model.AbstractToolCallSupport
functionCallbackContext, functionCallbackRegister, IS_RUNTIME_CALL
-
Constructor Summary
ConstructorDescriptionAnthropicChatModel
(AnthropicApi anthropicApi) Construct a newAnthropicChatModel
instance.AnthropicChatModel
(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions) Construct a newAnthropicChatModel
instance.AnthropicChatModel
(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate) Construct a newAnthropicChatModel
instance.AnthropicChatModel
(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext) Construct a newAnthropicChatModel
instance.AnthropicChatModel
(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext, List<FunctionCallback> toolFunctionCallbacks) Construct a newAnthropicChatModel
instance.AnthropicChatModel
(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext, List<FunctionCallback> toolFunctionCallbacks, io.micrometer.observation.ObservationRegistry observationRegistry) Construct a newAnthropicChatModel
instance. -
Method Summary
Modifier and TypeMethodDescriptionExecutes a method call to the AI model.void
setObservationConvention
(ChatModelObservationConvention observationConvention) Use the provided convention for reporting observation datareactor.core.publisher.Flux<ChatResponse>
Executes a method call to the AI model.Methods inherited from class org.springframework.ai.chat.model.AbstractToolCallSupport
buildToolCallConversation, executeFunctions, getFunctionCallbackRegister, handleToolCalls, isProxyToolCalls, isToolCall, isToolCall, resolveFunctionCallbacks, runtimeFunctionCallbackConfigurations
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.chat.model.StreamingChatModel
stream, stream
-
Field Details
-
DEFAULT_MODEL_NAME
-
DEFAULT_MAX_TOKENS
-
DEFAULT_TEMPERATURE
-
retryTemplate
public final org.springframework.retry.support.RetryTemplate retryTemplateThe retry template used to retry the OpenAI API calls.
-
-
Constructor Details
-
AnthropicChatModel
Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.
-
AnthropicChatModel
Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.defaultOptions
- the default options used for the chat completion requests.
-
AnthropicChatModel
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate) Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.defaultOptions
- the default options used for the chat completion requests.retryTemplate
- the retry template used to retry the Anthropic API calls.
-
AnthropicChatModel
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext) Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.defaultOptions
- the default options used for the chat completion requests.retryTemplate
- the retry template used to retry the Anthropic API calls.functionCallbackContext
- the function callback context used to store the state of the function calls.
-
AnthropicChatModel
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext, List<FunctionCallback> toolFunctionCallbacks) Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.defaultOptions
- the default options used for the chat completion requests.retryTemplate
- the retry template used to retry the Anthropic API calls.functionCallbackContext
- the function callback context used to store the state of the function calls.toolFunctionCallbacks
- the tool function callbacks used to handle the tool calls.
-
AnthropicChatModel
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions, org.springframework.retry.support.RetryTemplate retryTemplate, FunctionCallbackContext functionCallbackContext, List<FunctionCallback> toolFunctionCallbacks, io.micrometer.observation.ObservationRegistry observationRegistry) Construct a newAnthropicChatModel
instance.- Parameters:
anthropicApi
- the lower-level API for the Anthropic service.defaultOptions
- the default options used for the chat completion requests.retryTemplate
- the retry template used to retry the Anthropic API calls.functionCallbackContext
- the function callback context used to store the state of the function calls.toolFunctionCallbacks
- the tool function callbacks used to handle the tool calls.
-
-
Method Details
-
call
Description copied from interface:Model
Executes a method call to the AI model. -
stream
Description copied from interface:StreamingModel
Executes a method call to the AI model.- Specified by:
stream
in interfaceChatModel
- Specified by:
stream
in interfaceStreamingChatModel
- Specified by:
stream
in interfaceStreamingModel<Prompt,
ChatResponse> - Parameters:
prompt
- the request object to be sent to the AI model- Returns:
- the streaming response from the AI model
-
getDefaultOptions
- Specified by:
getDefaultOptions
in interfaceChatModel
-
setObservationConvention
Use the provided convention for reporting observation data- Parameters:
observationConvention
- The provided convention
-