Skip to content

Commit 3e0cfd2

Browse files
ericbottardilayaperumalg
authored andcommitted
Remove ChatOptions setters
Signed-off-by: Eric Bottard <eric.bottard@broadcom.com>
1 parent b5fa65b commit 3e0cfd2

20 files changed

Lines changed: 92 additions & 709 deletions

File tree

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -315,46 +315,21 @@ public List<ToolCallback> getToolCallbacks() {
315315
return this.toolCallbacks;
316316
}
317317

318-
@Override
319-
public void setToolCallbacks(List<ToolCallback> toolCallbacks) {
320-
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
321-
Assert.noNullElements(toolCallbacks, "toolCallbacks cannot contain null elements");
322-
this.toolCallbacks = toolCallbacks;
323-
}
324-
325318
@Override
326319
public Set<String> getToolNames() {
327320
return this.toolNames;
328321
}
329322

330-
@Override
331-
public void setToolNames(Set<String> toolNames) {
332-
Assert.notNull(toolNames, "toolNames cannot be null");
333-
Assert.noNullElements(toolNames, "toolNames cannot contain null elements");
334-
toolNames.forEach(tool -> Assert.hasText(tool, "toolNames cannot contain empty elements"));
335-
this.toolNames = toolNames;
336-
}
337-
338323
@Override
339324
public @Nullable Boolean getInternalToolExecutionEnabled() {
340325
return this.internalToolExecutionEnabled;
341326
}
342327

343-
@Override
344-
public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecutionEnabled) {
345-
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
346-
}
347-
348328
@Override
349329
public Map<String, Object> getToolContext() {
350330
return this.toolContext;
351331
}
352332

353-
@Override
354-
public void setToolContext(Map<String, Object> toolContext) {
355-
this.toolContext = toolContext;
356-
}
357-
358333
public List<AnthropicCitationDocument> getCitationDocuments() {
359334
return this.citationDocuments;
360335
}
@@ -422,30 +397,6 @@ public Map<String, String> getHttpHeaders() {
422397
}).orElse(null);
423398
}
424399

425-
@Override
426-
public void setOutputSchema(@Nullable String outputSchema) {
427-
if (outputSchema == null) {
428-
this.outputConfig = null;
429-
return;
430-
}
431-
Map<String, Object> schemaMap = JSON_MAPPER.readValue(outputSchema, new TypeReference<Map<String, Object>>() {
432-
});
433-
JsonOutputFormat.Schema.Builder schemaBuilder = JsonOutputFormat.Schema.builder();
434-
for (Map.Entry<String, Object> entry : schemaMap.entrySet()) {
435-
// Strip JSON Schema meta-fields not supported by the Anthropic API
436-
if ("$schema".equals(entry.getKey()) || "$defs".equals(entry.getKey())) {
437-
continue;
438-
}
439-
schemaBuilder.putAdditionalProperty(entry.getKey(), JsonValue.from(entry.getValue()));
440-
}
441-
JsonOutputFormat jsonOutputFormat = JsonOutputFormat.builder().schema(schemaBuilder.build()).build();
442-
OutputConfig.Builder configBuilder = OutputConfig.builder().format(jsonOutputFormat);
443-
if (this.outputConfig != null) {
444-
this.outputConfig.effort().ifPresent(configBuilder::effort);
445-
}
446-
this.outputConfig = configBuilder.build();
447-
}
448-
449400
/**
450401
* Converts a {@link JsonValue} to a native Java object using the visitor pattern.
451402
* Maps to null, Boolean, Number, String, List, or Map recursively.

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,16 @@ void testEqualsAndHashCode() {
229229

230230
@Test
231231
void testToolCallbacksValidationRejectsNull() {
232-
AnthropicChatOptions options = new AnthropicChatOptions();
233-
234-
assertThatThrownBy(() -> options.setToolCallbacks(null)).isInstanceOf(IllegalArgumentException.class)
232+
assertThatThrownBy(
233+
() -> AnthropicChatOptions.builder().toolCallbacks((org.springframework.ai.tool.ToolCallback[]) null))
234+
.isInstanceOf(IllegalArgumentException.class)
235235
.hasMessageContaining("toolCallbacks cannot be null");
236236
}
237237

238238
@Test
239239
void testToolNamesValidationRejectsNull() {
240-
AnthropicChatOptions options = new AnthropicChatOptions();
241-
242-
assertThatThrownBy(() -> options.setToolNames(null)).isInstanceOf(IllegalArgumentException.class)
240+
assertThatThrownBy(() -> AnthropicChatOptions.builder().toolNames((String[]) null))
241+
.isInstanceOf(IllegalArgumentException.class)
243242
.hasMessageContaining("toolNames cannot be null");
244243
}
245244

@@ -251,7 +250,7 @@ void testDefaultConstants() {
251250

252251
@Test
253252
void testUnsupportedPenaltyMethodsReturnNull() {
254-
AnthropicChatOptions options = new AnthropicChatOptions();
253+
AnthropicChatOptions options = AnthropicChatOptions.builder().build();
255254

256255
// Anthropic API does not support these OpenAI-specific parameters
257256
assertThat(options.getFrequencyPenalty()).isNull();
@@ -349,9 +348,9 @@ void testOutputConfigNullSchemaResetsConfig() {
349348
AnthropicChatOptions options = AnthropicChatOptions.builder().outputSchema("{\"type\":\"object\"}").build();
350349
assertThat(options.getOutputConfig()).isNotNull();
351350

352-
options.setOutputSchema(null);
353-
assertThat(options.getOutputConfig()).isNull();
354-
assertThat(options.getOutputSchema()).isNull();
351+
AnthropicChatOptions options2 = options.mutate().outputSchema(null).build();
352+
assertThat(options2.getOutputConfig()).isNull();
353+
assertThat(options2.getOutputSchema()).isNull();
355354
}
356355

357356
@Test

models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/BedrockChatOptions.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.ai.model.tool.StructuredOutputChatOptions;
3333
import org.springframework.ai.model.tool.ToolCallingChatOptions;
3434
import org.springframework.ai.tool.ToolCallback;
35-
import org.springframework.util.Assert;
3635

3736
/**
3837
* The options to be used when sending a chat request to the Bedrock API.
@@ -157,46 +156,21 @@ public List<ToolCallback> getToolCallbacks() {
157156
return this.toolCallbacks;
158157
}
159158

160-
@Override
161-
public void setToolCallbacks(List<ToolCallback> toolCallbacks) {
162-
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
163-
Assert.noNullElements(toolCallbacks, "toolCallbacks cannot contain null elements");
164-
this.toolCallbacks = toolCallbacks;
165-
}
166-
167159
@Override
168160
public Set<String> getToolNames() {
169161
return Set.copyOf(this.toolNames);
170162
}
171163

172-
@Override
173-
public void setToolNames(Set<String> toolNames) {
174-
Assert.notNull(toolNames, "toolNames cannot be null");
175-
Assert.noNullElements(toolNames, "toolNames cannot contain null elements");
176-
toolNames.forEach(toolName -> Assert.hasText(toolName, "toolNames cannot contain empty elements"));
177-
this.toolNames = toolNames;
178-
}
179-
180164
@Override
181165
public Map<String, Object> getToolContext() {
182166
return this.toolContext;
183167
}
184168

185-
@Override
186-
public void setToolContext(Map<String, Object> toolContext) {
187-
this.toolContext = toolContext;
188-
}
189-
190169
@Override
191170
@Nullable public Boolean getInternalToolExecutionEnabled() {
192171
return this.internalToolExecutionEnabled;
193172
}
194173

195-
@Override
196-
public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecutionEnabled) {
197-
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
198-
}
199-
200174
public @Nullable BedrockCacheOptions getCacheOptions() {
201175
return this.cacheOptions;
202176
}
@@ -206,11 +180,6 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
206180
return this.outputSchema;
207181
}
208182

209-
@Override
210-
public void setOutputSchema(@Nullable String outputSchema) {
211-
this.outputSchema = outputSchema;
212-
}
213-
214183
@Override
215184
public BedrockChatOptions copy() {
216185
return mutate().build();

models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockChatOptionsTests.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,4 @@ void testImplementsStructuredOutputChatOptions() {
113113
assertThat(options).isInstanceOf(StructuredOutputChatOptions.class);
114114
}
115115

116-
@Test
117-
void testOutputSchemaOverwrite() {
118-
BedrockChatOptions options = BedrockChatOptions.builder().outputSchema("{\"type\":\"object\"}").build();
119-
120-
options.setOutputSchema("{\"type\":\"array\"}");
121-
122-
assertThat(options.getOutputSchema()).isEqualTo("{\"type\":\"array\"}");
123-
}
124-
125116
}

models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/DeepSeekChatOptions.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.ai.model.tool.DefaultToolCallingChatOptions;
3333
import org.springframework.ai.model.tool.ToolCallingChatOptions;
3434
import org.springframework.ai.tool.ToolCallback;
35-
import org.springframework.util.Assert;
3635

3736
/**
3837
* Chat completions options for the DeepSeek chat API.
@@ -176,148 +175,76 @@ public String getModel() {
176175
return this.model;
177176
}
178177

179-
public void setModel(String model) {
180-
this.model = model;
181-
}
182-
183178
@Override
184179
public @Nullable Double getFrequencyPenalty() {
185180
return this.frequencyPenalty;
186181
}
187182

188-
public void setFrequencyPenalty(@Nullable Double frequencyPenalty) {
189-
this.frequencyPenalty = frequencyPenalty;
190-
}
191-
192183
@Override
193184
public @Nullable Integer getMaxTokens() {
194185
return this.maxTokens;
195186
}
196187

197-
public void setMaxTokens(@Nullable Integer maxTokens) {
198-
this.maxTokens = maxTokens;
199-
}
200-
201188
@Override
202189
public @Nullable Double getPresencePenalty() {
203190
return this.presencePenalty;
204191
}
205192

206-
public void setPresencePenalty(@Nullable Double presencePenalty) {
207-
this.presencePenalty = presencePenalty;
208-
}
209-
210193
public @Nullable ResponseFormat getResponseFormat() {
211194
return this.responseFormat;
212195
}
213196

214-
public void setResponseFormat(@Nullable ResponseFormat responseFormat) {
215-
this.responseFormat = responseFormat;
216-
}
217-
218197
@Override
219198
public @Nullable List<String> getStopSequences() {
220199
return getStop();
221200
}
222201

223-
public void setStopSequences(@Nullable List<String> stopSequences) {
224-
setStop(stopSequences);
225-
}
226-
227202
public @Nullable List<String> getStop() {
228203
return this.stop;
229204
}
230205

231-
public void setStop(@Nullable List<String> stop) {
232-
this.stop = stop;
233-
}
234-
235206
@Override
236207
public @Nullable Double getTemperature() {
237208
return this.temperature;
238209
}
239210

240-
public void setTemperature(@Nullable Double temperature) {
241-
this.temperature = temperature;
242-
}
243-
244211
@Override
245212
public @Nullable Double getTopP() {
246213
return this.topP;
247214
}
248215

249-
public void setTopP(@Nullable Double topP) {
250-
this.topP = topP;
251-
}
252-
253216
public @Nullable List<DeepSeekApi.FunctionTool> getTools() {
254217
return this.tools;
255218
}
256219

257-
public void setTools(@Nullable List<DeepSeekApi.FunctionTool> tools) {
258-
this.tools = tools;
259-
}
260-
261220
public @Nullable Object getToolChoice() {
262221
return this.toolChoice;
263222
}
264223

265-
public void setToolChoice(@Nullable Object toolChoice) {
266-
this.toolChoice = toolChoice;
267-
}
268-
269224

270225
@Override
271226
public List<ToolCallback> getToolCallbacks() {
272227
return this.toolCallbacks;
273228
}
274229

275-
@Override
276-
public void setToolCallbacks(List<ToolCallback> toolCallbacks) {
277-
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
278-
Assert.noNullElements(toolCallbacks, "toolCallbacks cannot contain null elements");
279-
this.toolCallbacks = toolCallbacks;
280-
}
281-
282230
@Override
283231
public Set<String> getToolNames() {
284232
return this.toolNames;
285233
}
286234

287-
@Override
288-
public void setToolNames(Set<String> toolNames) {
289-
Assert.notNull(toolNames, "toolNames cannot be null");
290-
Assert.noNullElements(toolNames, "toolNames cannot contain null elements");
291-
toolNames.forEach(tool -> Assert.hasText(tool, "toolNames cannot contain empty elements"));
292-
this.toolNames = toolNames;
293-
}
294-
295235
@Override
296236
public @Nullable Boolean getInternalToolExecutionEnabled() {
297237
return this.internalToolExecutionEnabled;
298238
}
299239

300-
@Override
301-
public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecutionEnabled) {
302-
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
303-
}
304-
305240
public @Nullable Boolean getLogprobs() {
306241
return this.logprobs;
307242
}
308243

309-
public void setLogprobs(@Nullable Boolean logprobs) {
310-
this.logprobs = logprobs;
311-
}
312-
313244
public @Nullable Integer getTopLogprobs() {
314245
return this.topLogprobs;
315246
}
316247

317-
public void setTopLogprobs(@Nullable Integer topLogprobs) {
318-
this.topLogprobs = topLogprobs;
319-
}
320-
321248
@Override
322249
public @Nullable Integer getTopK() {
323250
return null;
@@ -329,11 +256,6 @@ public Map<String, Object> getToolContext() {
329256
return this.toolContext;
330257
}
331258

332-
@Override
333-
public void setToolContext(Map<String, Object> toolContext) {
334-
this.toolContext = toolContext;
335-
}
336-
337259
@Override
338260
public DeepSeekChatOptions copy() {
339261
return mutate().build();

0 commit comments

Comments
 (0)