Skip to content

Commit ded9fac

Browse files
ilayaperumalgmarkpollack
authored andcommitted
Remove deprecations from 1.0.0-M6
- Remove deprecations from models, vector stores and usage - Deprecations from FunctionCallback and ObservationContext/Convention will be in a separate PR Models updates - Remove AbstractToolCallSupport from the models which use ToolCallingManager - Remove deprecated constructors and their usage - Remove FunctionCallbackResolver and FunctionCallbacks usage in the models - Add back deprecations for VectorStoreChatMemoryAdvisor until builder is fixed - Update OpenAiPaymentTransactionIT to use ToolCallbackResolver in config Signed-off-by: Ilayaperumal Gopinathan <[email protected]>
1 parent a1e417f commit ded9fac

File tree

80 files changed

+296
-1962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+296
-1962
lines changed

models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java

+6-147
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
33-
import org.springframework.ai.model.tool.LegacyToolCallingManager;
34-
import org.springframework.ai.model.tool.ToolCallingChatOptions;
35-
import org.springframework.ai.model.tool.ToolCallingManager;
36-
import org.springframework.ai.model.tool.ToolExecutionResult;
37-
import org.springframework.ai.tool.definition.ToolDefinition;
38-
import org.springframework.ai.util.json.JsonParser;
39-
import org.springframework.lang.Nullable;
4033
import reactor.core.publisher.Flux;
4134
import reactor.core.publisher.Mono;
4235
import reactor.core.scheduler.Schedulers;
@@ -59,7 +52,6 @@
5952
import org.springframework.ai.chat.metadata.EmptyUsage;
6053
import org.springframework.ai.chat.metadata.Usage;
6154
import org.springframework.ai.chat.metadata.UsageUtils;
62-
import org.springframework.ai.chat.model.AbstractToolCallSupport;
6355
import org.springframework.ai.chat.model.ChatModel;
6456
import org.springframework.ai.chat.model.ChatResponse;
6557
import org.springframework.ai.chat.model.Generation;
@@ -72,10 +64,12 @@
7264
import org.springframework.ai.chat.prompt.Prompt;
7365
import org.springframework.ai.model.Media;
7466
import org.springframework.ai.model.ModelOptionsUtils;
75-
import org.springframework.ai.model.function.FunctionCallback;
76-
import org.springframework.ai.model.function.FunctionCallbackResolver;
77-
import org.springframework.ai.model.function.FunctionCallingOptions;
67+
import org.springframework.ai.model.tool.ToolCallingChatOptions;
68+
import org.springframework.ai.model.tool.ToolCallingManager;
69+
import org.springframework.ai.model.tool.ToolExecutionResult;
7870
import org.springframework.ai.retry.RetryUtils;
71+
import org.springframework.ai.tool.definition.ToolDefinition;
72+
import org.springframework.ai.util.json.JsonParser;
7973
import org.springframework.http.ResponseEntity;
8074
import org.springframework.retry.support.RetryTemplate;
8175
import org.springframework.util.Assert;
@@ -94,7 +88,7 @@
9488
* @author Alexandros Pappas
9589
* @since 1.0.0
9690
*/
97-
public class AnthropicChatModel extends AbstractToolCallSupport implements ChatModel {
91+
public class AnthropicChatModel implements ChatModel {
9892

9993
public static final String DEFAULT_MODEL_NAME = AnthropicApi.ChatModel.CLAUDE_3_7_SONNET.getValue();
10094

@@ -135,111 +129,9 @@ public class AnthropicChatModel extends AbstractToolCallSupport implements ChatM
135129
*/
136130
private ChatModelObservationConvention observationConvention = DEFAULT_OBSERVATION_CONVENTION;
137131

138-
/**
139-
* Construct a new {@link AnthropicChatModel} instance.
140-
* @param anthropicApi the lower-level API for the Anthropic service.
141-
* @deprecated Use {@link AnthropicChatModel.Builder}.
142-
*/
143-
@Deprecated
144-
public AnthropicChatModel(AnthropicApi anthropicApi) {
145-
this(anthropicApi,
146-
AnthropicChatOptions.builder()
147-
.model(DEFAULT_MODEL_NAME)
148-
.maxTokens(DEFAULT_MAX_TOKENS)
149-
.temperature(DEFAULT_TEMPERATURE)
150-
.build());
151-
}
152-
153-
/**
154-
* Construct a new {@link AnthropicChatModel} instance.
155-
* @param anthropicApi the lower-level API for the Anthropic service.
156-
* @param defaultOptions the default options used for the chat completion requests.
157-
* @deprecated Use {@link AnthropicChatModel.Builder}.
158-
*/
159-
@Deprecated
160-
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions) {
161-
this(anthropicApi, defaultOptions, RetryUtils.DEFAULT_RETRY_TEMPLATE);
162-
}
163-
164-
/**
165-
* Construct a new {@link AnthropicChatModel} instance.
166-
* @param anthropicApi the lower-level API for the Anthropic service.
167-
* @param defaultOptions the default options used for the chat completion requests.
168-
* @param retryTemplate the retry template used to retry the Anthropic API calls.
169-
* @deprecated Use {@link AnthropicChatModel.Builder}.
170-
*/
171-
@Deprecated
172-
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions,
173-
RetryTemplate retryTemplate) {
174-
this(anthropicApi, defaultOptions, retryTemplate, null);
175-
}
176-
177-
/**
178-
* Construct a new {@link AnthropicChatModel} instance.
179-
* @param anthropicApi the lower-level API for the Anthropic service.
180-
* @param defaultOptions the default options used for the chat completion requests.
181-
* @param retryTemplate the retry template used to retry the Anthropic API calls.
182-
* @param functionCallbackResolver the function callback resolver used to resolve the
183-
* function by its name.
184-
* @deprecated Use {@link AnthropicChatModel.Builder}.
185-
*/
186-
@Deprecated
187-
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions,
188-
RetryTemplate retryTemplate, FunctionCallbackResolver functionCallbackResolver) {
189-
this(anthropicApi, defaultOptions, retryTemplate, functionCallbackResolver, List.of());
190-
}
191-
192-
/**
193-
* Construct a new {@link AnthropicChatModel} instance.
194-
* @param anthropicApi the lower-level API for the Anthropic service.
195-
* @param defaultOptions the default options used for the chat completion requests.
196-
* @param retryTemplate the retry template used to retry the Anthropic API calls.
197-
* @param functionCallbackResolver the function callback resolver used to resolve the
198-
* function by its name.
199-
* @param toolFunctionCallbacks the tool function callbacks used to handle the tool
200-
* calls.
201-
* @deprecated Use {@link AnthropicChatModel.Builder}.
202-
*/
203-
@Deprecated
204-
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions,
205-
RetryTemplate retryTemplate, FunctionCallbackResolver functionCallbackResolver,
206-
List<FunctionCallback> toolFunctionCallbacks) {
207-
this(anthropicApi, defaultOptions, retryTemplate, functionCallbackResolver, toolFunctionCallbacks,
208-
ObservationRegistry.NOOP);
209-
}
210-
211-
/**
212-
* Construct a new {@link AnthropicChatModel} instance.
213-
* @param anthropicApi the lower-level API for the Anthropic service.
214-
* @param defaultOptions the default options used for the chat completion requests.
215-
* @param retryTemplate the retry template used to retry the Anthropic API calls.
216-
* @param functionCallbackResolver the function callback resolver used to resolve the
217-
* function by its name.
218-
* @param toolFunctionCallbacks the tool function callbacks used to handle the tool
219-
* calls.
220-
* @deprecated Use {@link AnthropicChatModel.Builder}.
221-
*/
222-
@Deprecated
223-
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions,
224-
RetryTemplate retryTemplate, @Nullable FunctionCallbackResolver functionCallbackResolver,
225-
@Nullable List<FunctionCallback> toolFunctionCallbacks, ObservationRegistry observationRegistry) {
226-
this(anthropicApi, defaultOptions,
227-
LegacyToolCallingManager.builder()
228-
.functionCallbackResolver(functionCallbackResolver)
229-
.functionCallbacks(toolFunctionCallbacks)
230-
.build(),
231-
retryTemplate, observationRegistry);
232-
logger.warn("This constructor is deprecated and will be removed in the next milestone. "
233-
+ "Please use the MistralAiChatModel.Builder or the new constructor accepting ToolCallingManager instead.");
234-
}
235-
236132
public AnthropicChatModel(AnthropicApi anthropicApi, AnthropicChatOptions defaultOptions,
237133
ToolCallingManager toolCallingManager, RetryTemplate retryTemplate,
238134
ObservationRegistry observationRegistry) {
239-
// We do not pass the 'defaultOptions' to the AbstractToolSupport,
240-
// because it modifies them. We are using ToolCallingManager instead,
241-
// so we just pass empty options here.
242-
super(null, AnthropicChatOptions.builder().build(), List.of());
243135

244136
Assert.notNull(anthropicApi, "anthropicApi cannot be null");
245137
Assert.notNull(defaultOptions, "defaultOptions cannot be null");
@@ -488,10 +380,6 @@ Prompt buildRequestPrompt(Prompt prompt) {
488380
runtimeOptions = ModelOptionsUtils.copyToTarget(toolCallingChatOptions, ToolCallingChatOptions.class,
489381
AnthropicChatOptions.class);
490382
}
491-
else if (prompt.getOptions() instanceof FunctionCallingOptions functionCallingOptions) {
492-
runtimeOptions = ModelOptionsUtils.copyToTarget(functionCallingOptions, FunctionCallingOptions.class,
493-
AnthropicChatOptions.class);
494-
}
495383
else {
496384
runtimeOptions = ModelOptionsUtils.copyToTarget(prompt.getOptions(), ChatOptions.class,
497385
AnthropicChatOptions.class);
@@ -648,10 +536,6 @@ public static final class Builder {
648536

649537
private RetryTemplate retryTemplate = RetryUtils.DEFAULT_RETRY_TEMPLATE;
650538

651-
private FunctionCallbackResolver functionCallbackResolver;
652-
653-
private List<FunctionCallback> toolCallbacks;
654-
655539
private ToolCallingManager toolCallingManager;
656540

657541
private ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
@@ -679,41 +563,16 @@ public Builder toolCallingManager(ToolCallingManager toolCallingManager) {
679563
return this;
680564
}
681565

682-
@Deprecated
683-
public Builder functionCallbackResolver(FunctionCallbackResolver functionCallbackResolver) {
684-
this.functionCallbackResolver = functionCallbackResolver;
685-
return this;
686-
}
687-
688-
@Deprecated
689-
public Builder toolCallbacks(List<FunctionCallback> toolCallbacks) {
690-
this.toolCallbacks = toolCallbacks;
691-
return this;
692-
}
693-
694566
public Builder observationRegistry(ObservationRegistry observationRegistry) {
695567
this.observationRegistry = observationRegistry;
696568
return this;
697569
}
698570

699571
public AnthropicChatModel build() {
700572
if (toolCallingManager != null) {
701-
Assert.isNull(functionCallbackResolver,
702-
"functionCallbackResolver cannot be set when toolCallingManager is set");
703-
Assert.isNull(toolCallbacks, "toolCallbacks cannot be set when toolCallingManager is set");
704-
705573
return new AnthropicChatModel(anthropicApi, defaultOptions, toolCallingManager, retryTemplate,
706574
observationRegistry);
707575
}
708-
if (functionCallbackResolver != null) {
709-
Assert.isNull(toolCallingManager,
710-
"toolCallingManager cannot be set when functionCallbackResolver is set");
711-
List<FunctionCallback> toolCallbacks = this.toolCallbacks != null ? this.toolCallbacks : List.of();
712-
713-
return new AnthropicChatModel(anthropicApi, defaultOptions, retryTemplate, functionCallbackResolver,
714-
toolCallbacks, observationRegistry);
715-
}
716-
717576
return new AnthropicChatModel(anthropicApi, defaultOptions, DEFAULT_TOOL_CALLING_MANAGER, retryTemplate,
718577
observationRegistry);
719578
}

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelObservationIT.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.springframework.ai.chat.observation.DefaultChatModelObservationConvention;
3535
import org.springframework.ai.chat.prompt.Prompt;
3636
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
37+
import org.springframework.ai.model.tool.DefaultToolCallingManager;
38+
import org.springframework.ai.model.tool.ToolCallingManager;
3739
import org.springframework.ai.observation.conventions.AiOperationType;
3840
import org.springframework.ai.observation.conventions.AiProvider;
3941
import org.springframework.beans.factory.annotation.Autowired;
@@ -171,8 +173,7 @@ public AnthropicApi anthropicApi() {
171173
public AnthropicChatModel anthropicChatModel(AnthropicApi anthropicApi,
172174
TestObservationRegistry observationRegistry) {
173175
return new AnthropicChatModel(anthropicApi, AnthropicChatOptions.builder().build(),
174-
RetryTemplate.defaultInstance(), new DefaultFunctionCallbackResolver(), List.of(),
175-
observationRegistry);
176+
ToolCallingManager.builder().build(), RetryTemplate.defaultInstance(), observationRegistry);
176177
}
177178

178179
}

0 commit comments

Comments
 (0)