Skip to content

Commit 0c2b6cd

Browse files
committed
Refactor Minimax model builder methods
- Refactor minimax chat and embedded options builder methods to remove the prefix `with`
1 parent d3d34c9 commit 0c2b6cd

File tree

13 files changed

+250
-71
lines changed

13 files changed

+250
-71
lines changed

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public class MiniMaxChatModel extends AbstractToolCallSupport implements ChatMod
119119
* @throws IllegalArgumentException if MiniMaxApi is null
120120
*/
121121
public MiniMaxChatModel(MiniMaxApi miniMaxApi) {
122-
this(miniMaxApi,
123-
MiniMaxChatOptions.builder().withModel(MiniMaxApi.DEFAULT_CHAT_MODEL).withTemperature(0.7).build());
122+
this(miniMaxApi, MiniMaxChatOptions.builder().model(MiniMaxApi.DEFAULT_CHAT_MODEL).temperature(0.7).build());
124123
}
125124

126125
/**
@@ -501,7 +500,7 @@ else if (message.getMessageType() == MessageType.TOOL) {
501500
if (!CollectionUtils.isEmpty(enabledToolsToUse)) {
502501

503502
request = ModelOptionsUtils.merge(
504-
MiniMaxChatOptions.builder().withTools(this.getFunctionTools(enabledToolsToUse)).build(), request,
503+
MiniMaxChatOptions.builder().tools(this.getFunctionTools(enabledToolsToUse)).build(), request,
505504
ChatCompletionRequest.class);
506505
}
507506

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatOptions.java

Lines changed: 189 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* @see ChatOptions
4343
* @author Geng Rong
4444
* @author Thomas Vitale
45+
* @author Ilayaperumal Gopinathan
4546
* @since 1.0.0 M1
4647
*/
4748
@JsonInclude(Include.NON_NULL)
@@ -154,23 +155,23 @@ public static Builder builder() {
154155
}
155156

156157
public static MiniMaxChatOptions fromOptions(MiniMaxChatOptions fromOptions) {
157-
return builder().withModel(fromOptions.getModel())
158-
.withFrequencyPenalty(fromOptions.getFrequencyPenalty())
159-
.withMaxTokens(fromOptions.getMaxTokens())
160-
.withN(fromOptions.getN())
161-
.withPresencePenalty(fromOptions.getPresencePenalty())
162-
.withResponseFormat(fromOptions.getResponseFormat())
163-
.withSeed(fromOptions.getSeed())
164-
.withStop(fromOptions.getStop())
165-
.withTemperature(fromOptions.getTemperature())
166-
.withTopP(fromOptions.getTopP())
167-
.withMaskSensitiveInfo(fromOptions.getMaskSensitiveInfo())
168-
.withTools(fromOptions.getTools())
169-
.withToolChoice(fromOptions.getToolChoice())
170-
.withFunctionCallbacks(fromOptions.getFunctionCallbacks())
171-
.withFunctions(fromOptions.getFunctions())
172-
.withProxyToolCalls(fromOptions.getProxyToolCalls())
173-
.withToolContext(fromOptions.getToolContext())
158+
return builder().model(fromOptions.getModel())
159+
.frequencyPenalty(fromOptions.getFrequencyPenalty())
160+
.maxTokens(fromOptions.getMaxTokens())
161+
.N(fromOptions.getN())
162+
.presencePenalty(fromOptions.getPresencePenalty())
163+
.responseFormat(fromOptions.getResponseFormat())
164+
.seed(fromOptions.getSeed())
165+
.stop(fromOptions.getStop())
166+
.temperature(fromOptions.getTemperature())
167+
.topP(fromOptions.getTopP())
168+
.maskSensitiveInfo(fromOptions.getMaskSensitiveInfo())
169+
.tools(fromOptions.getTools())
170+
.toolChoice(fromOptions.getToolChoice())
171+
.functionCallbacks(fromOptions.getFunctionCallbacks())
172+
.functions(fromOptions.getFunctions())
173+
.proxyToolCalls(fromOptions.getProxyToolCalls())
174+
.toolContext(fromOptions.getToolContext())
174175
.build();
175176
}
176177

@@ -515,93 +516,264 @@ public Builder(MiniMaxChatOptions options) {
515516
this.options = options;
516517
}
517518

519+
public Builder model(String model) {
520+
this.options.model = model;
521+
return this;
522+
}
523+
524+
public Builder frequencyPenalty(Double frequencyPenalty) {
525+
this.options.frequencyPenalty = frequencyPenalty;
526+
return this;
527+
}
528+
529+
public Builder maxTokens(Integer maxTokens) {
530+
this.options.maxTokens = maxTokens;
531+
return this;
532+
}
533+
534+
public Builder N(Integer n) {
535+
this.options.n = n;
536+
return this;
537+
}
538+
539+
public Builder presencePenalty(Double presencePenalty) {
540+
this.options.presencePenalty = presencePenalty;
541+
return this;
542+
}
543+
544+
public Builder responseFormat(MiniMaxApi.ChatCompletionRequest.ResponseFormat responseFormat) {
545+
this.options.responseFormat = responseFormat;
546+
return this;
547+
}
548+
549+
public Builder seed(Integer seed) {
550+
this.options.seed = seed;
551+
return this;
552+
}
553+
554+
public Builder stop(List<String> stop) {
555+
this.options.stop = stop;
556+
return this;
557+
}
558+
559+
public Builder temperature(Double temperature) {
560+
this.options.temperature = temperature;
561+
return this;
562+
}
563+
564+
public Builder topP(Double topP) {
565+
this.options.topP = topP;
566+
return this;
567+
}
568+
569+
public Builder maskSensitiveInfo(Boolean maskSensitiveInfo) {
570+
this.options.maskSensitiveInfo = maskSensitiveInfo;
571+
return this;
572+
}
573+
574+
public Builder tools(List<MiniMaxApi.FunctionTool> tools) {
575+
this.options.tools = tools;
576+
return this;
577+
}
578+
579+
public Builder toolChoice(String toolChoice) {
580+
this.options.toolChoice = toolChoice;
581+
return this;
582+
}
583+
584+
public Builder functionCallbacks(List<FunctionCallback> functionCallbacks) {
585+
this.options.functionCallbacks = functionCallbacks;
586+
return this;
587+
}
588+
589+
public Builder functions(Set<String> functionNames) {
590+
Assert.notNull(functionNames, "Function names must not be null");
591+
this.options.functions = functionNames;
592+
return this;
593+
}
594+
595+
public Builder function(String functionName) {
596+
Assert.hasText(functionName, "Function name must not be empty");
597+
this.options.functions.add(functionName);
598+
return this;
599+
}
600+
601+
public Builder proxyToolCalls(Boolean proxyToolCalls) {
602+
this.options.proxyToolCalls = proxyToolCalls;
603+
return this;
604+
}
605+
606+
public Builder toolContext(Map<String, Object> toolContext) {
607+
if (this.options.toolContext == null) {
608+
this.options.toolContext = toolContext;
609+
}
610+
else {
611+
this.options.toolContext.putAll(toolContext);
612+
}
613+
return this;
614+
}
615+
616+
/**
617+
* @deprecated use {@link #model(String)} instead.
618+
*/
619+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
518620
public Builder withModel(String model) {
519621
this.options.model = model;
520622
return this;
521623
}
522624

625+
/**
626+
* @deprecated use {@link #frequencyPenalty(Double)} instead.
627+
*/
628+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
523629
public Builder withFrequencyPenalty(Double frequencyPenalty) {
524630
this.options.frequencyPenalty = frequencyPenalty;
525631
return this;
526632
}
527633

634+
/**
635+
* @deprecated use {@link #maxTokens(Integer)} instead.
636+
*/
637+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
528638
public Builder withMaxTokens(Integer maxTokens) {
529639
this.options.maxTokens = maxTokens;
530640
return this;
531641
}
532642

643+
/**
644+
* @deprecated use {@link #N(Integer)} instead.
645+
*/
646+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
533647
public Builder withN(Integer n) {
534648
this.options.n = n;
535649
return this;
536650
}
537651

652+
/**
653+
* @deprecated use {@link #presencePenalty(Double)} instead.
654+
*/
655+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
538656
public Builder withPresencePenalty(Double presencePenalty) {
539657
this.options.presencePenalty = presencePenalty;
540658
return this;
541659
}
542660

661+
/**
662+
* @deprecated use
663+
* {@link #responseFormat(MiniMaxApi.ChatCompletionRequest.ResponseFormat)}
664+
* instead.
665+
*/
666+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
543667
public Builder withResponseFormat(MiniMaxApi.ChatCompletionRequest.ResponseFormat responseFormat) {
544668
this.options.responseFormat = responseFormat;
545669
return this;
546670
}
547671

672+
/**
673+
* @deprecated use {@link #seed(Integer)} instead.
674+
*/
675+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
548676
public Builder withSeed(Integer seed) {
549677
this.options.seed = seed;
550678
return this;
551679
}
552680

681+
/**
682+
* @deprecated use {@link #stop(List)} instead.
683+
*/
684+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
553685
public Builder withStop(List<String> stop) {
554686
this.options.stop = stop;
555687
return this;
556688
}
557689

690+
/**
691+
* @deprecated use {@link #temperature(Double)} instead.
692+
*/
693+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
558694
public Builder withTemperature(Double temperature) {
559695
this.options.temperature = temperature;
560696
return this;
561697
}
562698

699+
/**
700+
* @deprecated use {@link #topP(Double)} instead.
701+
*/
702+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
563703
public Builder withTopP(Double topP) {
564704
this.options.topP = topP;
565705
return this;
566706
}
567707

708+
/**
709+
* @deprecated use {@link #maskSensitiveInfo(Boolean)} instead.
710+
*/
711+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
568712
public Builder withMaskSensitiveInfo(Boolean maskSensitiveInfo) {
569713
this.options.maskSensitiveInfo = maskSensitiveInfo;
570714
return this;
571715
}
572716

717+
/**
718+
* @deprecated use {@link #tools(List)} instead.
719+
*/
720+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
573721
public Builder withTools(List<MiniMaxApi.FunctionTool> tools) {
574722
this.options.tools = tools;
575723
return this;
576724
}
577725

726+
/**
727+
* @deprecated use {@link #toolChoice(String)} instead.
728+
*/
729+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
578730
public Builder withToolChoice(String toolChoice) {
579731
this.options.toolChoice = toolChoice;
580732
return this;
581733
}
582734

735+
/**
736+
* @deprecated use {@link #functionCallbacks(List)} instead.
737+
*/
738+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
583739
public Builder withFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
584740
this.options.functionCallbacks = functionCallbacks;
585741
return this;
586742
}
587743

744+
/**
745+
* @deprecated use {@link #functions(Set)} instead.
746+
*/
747+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
588748
public Builder withFunctions(Set<String> functionNames) {
589749
Assert.notNull(functionNames, "Function names must not be null");
590750
this.options.functions = functionNames;
591751
return this;
592752
}
593753

754+
/**
755+
* @deprecated use {@link #function(String)} instead.
756+
*/
757+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
594758
public Builder withFunction(String functionName) {
595759
Assert.hasText(functionName, "Function name must not be empty");
596760
this.options.functions.add(functionName);
597761
return this;
598762
}
599763

764+
/**
765+
* @deprecated use {@link #proxyToolCalls(Boolean)} instead.
766+
*/
767+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
600768
public Builder withProxyToolCalls(Boolean proxyToolCalls) {
601769
this.options.proxyToolCalls = proxyToolCalls;
602770
return this;
603771
}
604772

773+
/**
774+
* @deprecated use {@link #toolContext(Map)} instead.
775+
*/
776+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
605777
public Builder withToolContext(Map<String, Object> toolContext) {
606778
if (this.options.toolContext == null) {
607779
this.options.toolContext = toolContext;

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxEmbeddingModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public MiniMaxEmbeddingModel(MiniMaxApi miniMaxApi) {
9090
*/
9191
public MiniMaxEmbeddingModel(MiniMaxApi miniMaxApi, MetadataMode metadataMode) {
9292
this(miniMaxApi, metadataMode,
93-
MiniMaxEmbeddingOptions.builder().withModel(MiniMaxApi.DEFAULT_EMBEDDING_MODEL).build(),
93+
MiniMaxEmbeddingOptions.builder().model(MiniMaxApi.DEFAULT_EMBEDDING_MODEL).build(),
9494
RetryUtils.DEFAULT_RETRY_TEMPLATE, ObservationRegistry.NOOP);
9595
}
9696

@@ -196,13 +196,13 @@ private MiniMaxEmbeddingOptions mergeOptions(@Nullable EmbeddingOptions runtimeO
196196

197197
var optionBuilder = MiniMaxEmbeddingOptions.builder();
198198
if (runtimeOptionsForProvider != null && runtimeOptionsForProvider.getModel() != null) {
199-
optionBuilder.withModel(runtimeOptionsForProvider.getModel());
199+
optionBuilder.model(runtimeOptionsForProvider.getModel());
200200
}
201201
else if (defaultOptions.getModel() != null) {
202-
optionBuilder.withModel(defaultOptions.getModel());
202+
optionBuilder.model(defaultOptions.getModel());
203203
}
204204
else {
205-
optionBuilder.withModel(MiniMaxApi.DEFAULT_EMBEDDING_MODEL);
205+
optionBuilder.model(MiniMaxApi.DEFAULT_EMBEDDING_MODEL);
206206
}
207207
return optionBuilder.build();
208208
}

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxEmbeddingOptions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public Builder() {
6767
this.options = new MiniMaxEmbeddingOptions();
6868
}
6969

70+
public Builder model(String model) {
71+
this.options.setModel(model);
72+
return this;
73+
}
74+
75+
/**
76+
* @deprecated use {@link #model(String)} instead.
77+
*/
78+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
7079
public Builder withModel(String model) {
7180
this.options.setModel(model);
7281
return this;

0 commit comments

Comments
 (0)