Type of the entity in the data list. Can be a {@link String} or {@link List} of tokens (e.g.
+ * Integers). For embedding multiple inputs in a single request, You can pass a {@link List} of {@link String} or
+ * {@link List} of {@link List} of tokens. For example:
+ *
+ * {@code List.of("text1", "text2", "text3") or List.of(List.of(1, 2, 3), List.of(3, 4, 5))}
+ */
+ public ResponseEntity embeddings(EmbeddingRequest embeddingRequest) {
+
+ Assert.notNull(embeddingRequest, "The request body can not be null.");
+
+ // Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single
+ // request, pass an array of strings or array of token arrays.
+ Assert.notNull(embeddingRequest.texts(), "The input can not be null.");
+
+ Assert.isTrue(!CollectionUtils.isEmpty(embeddingRequest.texts()), "The input list can not be empty.");
+
+ return this.restClient.post()
+ .uri("/v1/embeddings")
+ .body(embeddingRequest)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<>() {
+ });
+ }
+
+}
+// @formatter:on
diff --git a/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxStreamFunctionCallingHelper.java b/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxStreamFunctionCallingHelper.java
new file mode 100644
index 00000000000..dcaa1fc073b
--- /dev/null
+++ b/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxStreamFunctionCallingHelper.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax.api;
+
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper class to support Streaming function calling. It can merge the streamed
+ * ChatCompletionChunk in case of function calling message.
+ *
+ * @author Geng Rong
+ */
+public class MiniMaxStreamFunctionCallingHelper {
+
+ /**
+ * Merge the previous and current ChatCompletionChunk into a single one.
+ * @param previous the previous ChatCompletionChunk
+ * @param current the current ChatCompletionChunk
+ * @return the merged ChatCompletionChunk
+ */
+ public MiniMaxApi.ChatCompletionChunk merge(MiniMaxApi.ChatCompletionChunk previous,
+ MiniMaxApi.ChatCompletionChunk current) {
+
+ if (previous == null) {
+ return current;
+ }
+
+ String id = (current.id() != null ? current.id() : previous.id());
+ Long created = (current.created() != null ? current.created() : previous.created());
+ String model = (current.model() != null ? current.model() : previous.model());
+ String systemFingerprint = (current.systemFingerprint() != null ? current.systemFingerprint()
+ : previous.systemFingerprint());
+ String object = (current.object() != null ? current.object() : previous.object());
+
+ MiniMaxApi.ChatCompletionChunk.ChunkChoice previousChoice0 = (CollectionUtils.isEmpty(previous.choices()) ? null
+ : previous.choices().get(0));
+ MiniMaxApi.ChatCompletionChunk.ChunkChoice currentChoice0 = (CollectionUtils.isEmpty(current.choices()) ? null
+ : current.choices().get(0));
+
+ MiniMaxApi.ChatCompletionChunk.ChunkChoice choice = merge(previousChoice0, currentChoice0);
+ List chunkChoices = choice == null ? List.of() : List.of(choice);
+ return new MiniMaxApi.ChatCompletionChunk(id, chunkChoices, created, model, systemFingerprint, object);
+ }
+
+ private MiniMaxApi.ChatCompletionChunk.ChunkChoice merge(MiniMaxApi.ChatCompletionChunk.ChunkChoice previous,
+ MiniMaxApi.ChatCompletionChunk.ChunkChoice current) {
+ if (previous == null) {
+ return current;
+ }
+
+ MiniMaxApi.ChatCompletionFinishReason finishReason = (current.finishReason() != null ? current.finishReason()
+ : previous.finishReason());
+ Integer index = (current.index() != null ? current.index() : previous.index());
+
+ MiniMaxApi.ChatCompletionMessage message = merge(previous.delta(), current.delta());
+
+ MiniMaxApi.LogProbs logprobs = (current.logprobs() != null ? current.logprobs() : previous.logprobs());
+ return new MiniMaxApi.ChatCompletionChunk.ChunkChoice(finishReason, index, message, logprobs);
+ }
+
+ private MiniMaxApi.ChatCompletionMessage merge(MiniMaxApi.ChatCompletionMessage previous,
+ MiniMaxApi.ChatCompletionMessage current) {
+ String content = (current.content() != null ? current.content()
+ : (previous.content() != null) ? previous.content() : "");
+ MiniMaxApi.ChatCompletionMessage.Role role = (current.role() != null ? current.role() : previous.role());
+ role = (role != null ? role : MiniMaxApi.ChatCompletionMessage.Role.ASSISTANT); // default
+ // to
+ // ASSISTANT
+ // (if
+ // null
+ String name = (current.name() != null ? current.name() : previous.name());
+ String toolCallId = (current.toolCallId() != null ? current.toolCallId() : previous.toolCallId());
+
+ List toolCalls = new ArrayList<>();
+ MiniMaxApi.ChatCompletionMessage.ToolCall lastPreviousTooCall = null;
+ if (previous.toolCalls() != null) {
+ lastPreviousTooCall = previous.toolCalls().get(previous.toolCalls().size() - 1);
+ if (previous.toolCalls().size() > 1) {
+ toolCalls.addAll(previous.toolCalls().subList(0, previous.toolCalls().size() - 1));
+ }
+ }
+ if (current.toolCalls() != null) {
+ if (current.toolCalls().size() > 1) {
+ throw new IllegalStateException("Currently only one tool call is supported per message!");
+ }
+ var currentToolCall = current.toolCalls().iterator().next();
+ if (currentToolCall.id() != null) {
+ if (lastPreviousTooCall != null) {
+ toolCalls.add(lastPreviousTooCall);
+ }
+ toolCalls.add(currentToolCall);
+ }
+ else {
+ toolCalls.add(merge(lastPreviousTooCall, currentToolCall));
+ }
+ }
+ else {
+ if (lastPreviousTooCall != null) {
+ toolCalls.add(lastPreviousTooCall);
+ }
+ }
+ return new MiniMaxApi.ChatCompletionMessage(content, role, name, toolCallId, toolCalls);
+ }
+
+ private MiniMaxApi.ChatCompletionMessage.ToolCall merge(MiniMaxApi.ChatCompletionMessage.ToolCall previous,
+ MiniMaxApi.ChatCompletionMessage.ToolCall current) {
+ if (previous == null) {
+ return current;
+ }
+ String id = (current.id() != null ? current.id() : previous.id());
+ String type = (current.type() != null ? current.type() : previous.type());
+ MiniMaxApi.ChatCompletionMessage.ChatCompletionFunction function = merge(previous.function(),
+ current.function());
+ return new MiniMaxApi.ChatCompletionMessage.ToolCall(id, type, function);
+ }
+
+ private MiniMaxApi.ChatCompletionMessage.ChatCompletionFunction merge(
+ MiniMaxApi.ChatCompletionMessage.ChatCompletionFunction previous,
+ MiniMaxApi.ChatCompletionMessage.ChatCompletionFunction current) {
+ if (previous == null) {
+ return current;
+ }
+ String name = (current.name() != null ? current.name() : previous.name());
+ StringBuilder arguments = new StringBuilder();
+ if (previous.arguments() != null) {
+ arguments.append(previous.arguments());
+ }
+ if (current.arguments() != null) {
+ arguments.append(current.arguments());
+ }
+ return new MiniMaxApi.ChatCompletionMessage.ChatCompletionFunction(name, arguments.toString());
+ }
+
+ /**
+ * @param chatCompletion the ChatCompletionChunk to check
+ * @return true if the ChatCompletionChunk is a streaming tool function call.
+ */
+ public boolean isStreamingToolFunctionCall(MiniMaxApi.ChatCompletionChunk chatCompletion) {
+
+ if (chatCompletion == null || CollectionUtils.isEmpty(chatCompletion.choices())) {
+ return false;
+ }
+
+ var choice = chatCompletion.choices().get(0);
+ if (choice == null || choice.delta() == null) {
+ return false;
+ }
+ return !CollectionUtils.isEmpty(choice.delta().toolCalls());
+ }
+
+ /**
+ * @param chatCompletion the ChatCompletionChunk to check
+ * @return true if the ChatCompletionChunk is a streaming tool function call and it is
+ * the last one.
+ */
+ public boolean isStreamingToolFunctionCallFinish(MiniMaxApi.ChatCompletionChunk chatCompletion) {
+
+ if (chatCompletion == null || CollectionUtils.isEmpty(chatCompletion.choices())) {
+ return false;
+ }
+
+ var choice = chatCompletion.choices().get(0);
+ if (choice == null || choice.delta() == null) {
+ return false;
+ }
+ return choice.finishReason() == MiniMaxApi.ChatCompletionFinishReason.TOOL_CALLS;
+ }
+
+ /**
+ * Convert the ChatCompletionChunk into a ChatCompletion. The Usage is set to null.
+ * @param chunk the ChatCompletionChunk to convert
+ * @return the ChatCompletion
+ */
+ public MiniMaxApi.ChatCompletion chunkToChatCompletion(MiniMaxApi.ChatCompletionChunk chunk) {
+ List choices = chunk.choices()
+ .stream()
+ .map(chunkChoice -> new MiniMaxApi.ChatCompletion.Choice(chunkChoice.finishReason(), chunkChoice.index(),
+ chunkChoice.delta(), chunkChoice.logprobs()))
+ .toList();
+
+ return new MiniMaxApi.ChatCompletion(chunk.id(), choices, chunk.created(), chunk.model(),
+ chunk.systemFingerprint(), "chat.completion", null, null);
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/common/MiniMaxApiException.java b/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/common/MiniMaxApiException.java
new file mode 100644
index 00000000000..5351bd3c116
--- /dev/null
+++ b/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/common/MiniMaxApiException.java
@@ -0,0 +1,16 @@
+package org.springframework.ai.minimax.api.common;
+
+/**
+ * @author Geng Rong
+ */
+public class MiniMaxApiException extends RuntimeException {
+
+ public MiniMaxApiException(String message) {
+ super(message);
+ }
+
+ public MiniMaxApiException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/main/resources/META-INF/spring/aot.factories b/models/spring-ai-minimax/src/main/resources/META-INF/spring/aot.factories
new file mode 100644
index 00000000000..56d21def4f2
--- /dev/null
+++ b/models/spring-ai-minimax/src/main/resources/META-INF/spring/aot.factories
@@ -0,0 +1,2 @@
+org.springframework.aot.hint.RuntimeHintsRegistrar=\
+ org.springframework.ai.minimax.aot.MiniMaxRuntimeHints
\ No newline at end of file
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/ChatCompletionRequestTests.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/ChatCompletionRequestTests.java
new file mode 100644
index 00000000000..9adf803a456
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/ChatCompletionRequestTests.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.ai.minimax.api.MockWeatherService;
+import org.springframework.ai.model.function.FunctionCallbackWrapper;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+public class ChatCompletionRequestTests {
+
+ @Test
+ public void createRequestWithChatOptions() {
+
+ var client = new MiniMaxChatClient(new MiniMaxApi("TEST"),
+ MiniMaxChatOptions.builder().withModel("DEFAULT_MODEL").withTemperature(66.6f).build());
+
+ var request = client.createRequest(new Prompt("Test message content"), false);
+
+ assertThat(request.messages()).hasSize(1);
+ assertThat(request.stream()).isFalse();
+
+ assertThat(request.model()).isEqualTo("DEFAULT_MODEL");
+ assertThat(request.temperature()).isEqualTo(66.6f);
+
+ request = client.createRequest(new Prompt("Test message content",
+ MiniMaxChatOptions.builder().withModel("PROMPT_MODEL").withTemperature(99.9f).build()), true);
+
+ assertThat(request.messages()).hasSize(1);
+ assertThat(request.stream()).isTrue();
+
+ assertThat(request.model()).isEqualTo("PROMPT_MODEL");
+ assertThat(request.temperature()).isEqualTo(99.9f);
+ }
+
+ @Test
+ public void promptOptionsTools() {
+
+ final String TOOL_FUNCTION_NAME = "CurrentWeather";
+
+ var client = new MiniMaxChatClient(new MiniMaxApi("TEST"),
+ MiniMaxChatOptions.builder().withModel("DEFAULT_MODEL").build());
+
+ var request = client.createRequest(new Prompt("Test message content",
+ MiniMaxChatOptions.builder()
+ .withModel("PROMPT_MODEL")
+ .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName(TOOL_FUNCTION_NAME)
+ .withDescription("Get the weather in location")
+ .withResponseConverter((response) -> "" + response.temp() + response.unit())
+ .build()))
+ .build()),
+ false);
+
+ assertThat(client.getFunctionCallbackRegister()).hasSize(1);
+ assertThat(client.getFunctionCallbackRegister()).containsKeys(TOOL_FUNCTION_NAME);
+
+ assertThat(request.messages()).hasSize(1);
+ assertThat(request.stream()).isFalse();
+ assertThat(request.model()).isEqualTo("PROMPT_MODEL");
+
+ assertThat(request.tools()).hasSize(1);
+ assertThat(request.tools().get(0).function().name()).isEqualTo(TOOL_FUNCTION_NAME);
+ }
+
+ @Test
+ public void defaultOptionsTools() {
+
+ final String TOOL_FUNCTION_NAME = "CurrentWeather";
+
+ var client = new MiniMaxChatClient(new MiniMaxApi("TEST"),
+ MiniMaxChatOptions.builder()
+ .withModel("DEFAULT_MODEL")
+ .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName(TOOL_FUNCTION_NAME)
+ .withDescription("Get the weather in location")
+ .withResponseConverter((response) -> "" + response.temp() + response.unit())
+ .build()))
+ .build());
+
+ var request = client.createRequest(new Prompt("Test message content"), false);
+
+ assertThat(client.getFunctionCallbackRegister()).hasSize(1);
+ assertThat(client.getFunctionCallbackRegister()).containsKeys(TOOL_FUNCTION_NAME);
+ assertThat(client.getFunctionCallbackRegister().get(TOOL_FUNCTION_NAME).getDescription())
+ .isEqualTo("Get the weather in location");
+
+ assertThat(request.messages()).hasSize(1);
+ assertThat(request.stream()).isFalse();
+ assertThat(request.model()).isEqualTo("DEFAULT_MODEL");
+
+ assertThat(request.tools()).as("Default Options callback functions are not automatically enabled!")
+ .isNullOrEmpty();
+
+ // Explicitly enable the function
+ request = client.createRequest(new Prompt("Test message content",
+ MiniMaxChatOptions.builder().withFunction(TOOL_FUNCTION_NAME).build()), false);
+
+ assertThat(request.tools()).hasSize(1);
+ assertThat(request.tools().get(0).function().name()).as("Explicitly enabled function")
+ .isEqualTo(TOOL_FUNCTION_NAME);
+
+ // Override the default options function with one from the prompt
+ request = client.createRequest(new Prompt("Test message content",
+ MiniMaxChatOptions.builder()
+ .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName(TOOL_FUNCTION_NAME)
+ .withDescription("Overridden function description")
+ .build()))
+ .build()),
+ false);
+
+ assertThat(request.tools()).hasSize(1);
+ assertThat(request.tools().get(0).function().name()).as("Explicitly enabled function")
+ .isEqualTo(TOOL_FUNCTION_NAME);
+
+ assertThat(client.getFunctionCallbackRegister()).hasSize(1);
+ assertThat(client.getFunctionCallbackRegister()).containsKeys(TOOL_FUNCTION_NAME);
+ assertThat(client.getFunctionCallbackRegister().get(TOOL_FUNCTION_NAME).getDescription())
+ .isEqualTo("Overridden function description");
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/MiniMaxTestConfiguration.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/MiniMaxTestConfiguration.java
new file mode 100644
index 00000000000..f544b4896c6
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/MiniMaxTestConfiguration.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax;
+
+import org.springframework.ai.embedding.EmbeddingClient;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author Geng Rong
+ */
+@SpringBootConfiguration
+public class MiniMaxTestConfiguration {
+
+ @Bean
+ public MiniMaxApi miniMaxApi() {
+ return new MiniMaxApi(getApiKey());
+ }
+
+ private String getApiKey() {
+ String apiKey = System.getenv("MINIMAX_API_KEY");
+ if (!StringUtils.hasText(apiKey)) {
+ throw new IllegalArgumentException(
+ "You must provide an API key. Put it in an environment variable under the name MINIMAX_API_KEY");
+ }
+ return apiKey;
+ }
+
+ @Bean
+ public MiniMaxChatClient miniMaxChatClient(MiniMaxApi api) {
+ return new MiniMaxChatClient(api);
+ }
+
+ @Bean
+ public EmbeddingClient miniMaxEmbeddingClient(MiniMaxApi api) {
+ return new MiniMaxEmbeddingClient(api);
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiIT.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiIT.java
new file mode 100644
index 00000000000..431d20ff2f3
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiIT.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax.api;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.springframework.ai.minimax.api.MiniMaxApi.*;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.Role;
+import org.springframework.http.ResponseEntity;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.Objects;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
+public class MiniMaxApiIT {
+
+ MiniMaxApi miniMaxApi = new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
+
+ @Test
+ void chatCompletionEntity() {
+ ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
+ ResponseEntity response = miniMaxApi.chatCompletionEntity(
+ new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-3-turbo", 0.7f, false));
+
+ assertThat(response).isNotNull();
+ assertThat(response.getBody()).isNotNull();
+ }
+
+ @Test
+ void chatCompletionStream() {
+ ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
+ Flux response = miniMaxApi
+ .chatCompletionStream(new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-3-turbo", 0.7f, true));
+
+ assertThat(response).isNotNull();
+ assertThat(response.collectList().block()).isNotNull();
+ }
+
+ @Test
+ void embeddings() {
+ ResponseEntity response = miniMaxApi.embeddings(new MiniMaxApi.EmbeddingRequest("Hello world"));
+
+ assertThat(response).isNotNull();
+ assertThat(Objects.requireNonNull(response.getBody()).vectors()).hasSize(1);
+ assertThat(response.getBody().vectors().get(0)).hasSize(1536);
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiToolFunctionCallIT.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiToolFunctionCallIT.java
new file mode 100644
index 00000000000..cfcd2fa0a7d
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiToolFunctionCallIT.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.minimax.api;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.model.ModelOptionsUtils;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletion;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.Role;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.ToolCall;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionRequest;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionRequest.ToolChoiceBuilder;
+import org.springframework.ai.minimax.api.MiniMaxApi.FunctionTool.Type;
+import org.springframework.http.ResponseEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.ai.minimax.api.MiniMaxApi.ChatModel.*;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".+")
+public class MiniMaxApiToolFunctionCallIT {
+
+ private final Logger logger = LoggerFactory.getLogger(MiniMaxApiToolFunctionCallIT.class);
+
+ MockWeatherService weatherService = new MockWeatherService();
+
+ MiniMaxApi miniMaxApi = new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
+
+ @SuppressWarnings("null")
+ @Test
+ public void toolFunctionCall() {
+
+ // Step 1: send the conversation and available functions to the model
+ var message = new ChatCompletionMessage("What's the weather like in San Francisco?", Role.USER);
+
+ var functionTool = new MiniMaxApi.FunctionTool(Type.FUNCTION, new MiniMaxApi.FunctionTool.Function(
+ "Get the weather in location. Return temperature in 30°F or 30°C format.", "getCurrentWeather", """
+ {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "description": "The city and state e.g. San Francisco, CA"
+ },
+ "lat": {
+ "type": "number",
+ "description": "The city latitude"
+ },
+ "lon": {
+ "type": "number",
+ "description": "The city longitude"
+ },
+ "unit": {
+ "type": "string",
+ "enum": ["C", "F"]
+ }
+ },
+ "required": ["location", "lat", "lon", "unit"]
+ }
+ """));
+
+ List messages = new ArrayList<>(List.of(message));
+
+ ChatCompletionRequest chatCompletionRequest = new ChatCompletionRequest(messages, ABAB_6_Chat.value,
+ List.of(functionTool), ToolChoiceBuilder.AUTO);
+
+ ResponseEntity chatCompletion = miniMaxApi.chatCompletionEntity(chatCompletionRequest);
+
+ assertThat(chatCompletion.getBody()).isNotNull();
+ assertThat(chatCompletion.getBody().choices()).isNotEmpty();
+
+ ChatCompletionMessage responseMessage = chatCompletion.getBody().choices().get(0).message();
+
+ assertThat(responseMessage.role()).isEqualTo(Role.ASSISTANT);
+ assertThat(responseMessage.toolCalls()).isNotNull();
+
+ messages.add(responseMessage);
+
+ // Send the info for each function call and function response to the model.
+ for (ToolCall toolCall : responseMessage.toolCalls()) {
+ var functionName = toolCall.function().name();
+ if ("getCurrentWeather".equals(functionName)) {
+ MockWeatherService.Request weatherRequest = fromJson(toolCall.function().arguments(),
+ MockWeatherService.Request.class);
+
+ MockWeatherService.Response weatherResponse = weatherService.apply(weatherRequest);
+
+ // extend conversation with function response.
+ messages.add(new ChatCompletionMessage("" + weatherResponse.temp() + weatherRequest.unit(), Role.TOOL,
+ functionName, toolCall.id(), null));
+ }
+ }
+
+ var functionResponseRequest = new ChatCompletionRequest(messages, ABAB_6_Chat.value, 0.5F);
+
+ ResponseEntity chatCompletion2 = miniMaxApi.chatCompletionEntity(functionResponseRequest);
+
+ logger.info("Final response: " + chatCompletion2.getBody());
+
+ assertThat(Objects.requireNonNull(chatCompletion2.getBody()).choices()).isNotEmpty();
+
+ assertThat(chatCompletion2.getBody().choices().get(0).message().role()).isEqualTo(Role.ASSISTANT);
+ assertThat(chatCompletion2.getBody().choices().get(0).message().content()).contains("San Francisco")
+ .containsAnyOf("30.0°C", "30°C", "30.0°F", "30°F");
+ }
+
+ private static T fromJson(String json, Class targetClass) {
+ try {
+ return new ObjectMapper().readValue(json, targetClass);
+ }
+ catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxRetryTests.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxRetryTests.java
new file mode 100644
index 00000000000..4310b87fbb4
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxRetryTests.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax.api;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.document.MetadataMode;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxChatOptions;
+import org.springframework.ai.minimax.MiniMaxEmbeddingClient;
+import org.springframework.ai.minimax.MiniMaxEmbeddingOptions;
+import org.springframework.ai.minimax.api.MiniMaxApi.*;
+import org.springframework.ai.minimax.api.MiniMaxApi.ChatCompletionMessage.Role;
+import org.springframework.ai.retry.RetryUtils;
+import org.springframework.ai.retry.TransientAiException;
+import org.springframework.http.ResponseEntity;
+import org.springframework.retry.RetryCallback;
+import org.springframework.retry.RetryContext;
+import org.springframework.retry.RetryListener;
+import org.springframework.retry.support.RetryTemplate;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Geng Rong
+ */
+@SuppressWarnings("unchecked")
+@ExtendWith(MockitoExtension.class)
+public class MiniMaxRetryTests {
+
+ private class TestRetryListener implements RetryListener {
+
+ int onErrorRetryCount = 0;
+
+ int onSuccessRetryCount = 0;
+
+ @Override
+ public void onSuccess(RetryContext context, RetryCallback callback, T result) {
+ onSuccessRetryCount = context.getRetryCount();
+ }
+
+ @Override
+ public void onError(RetryContext context, RetryCallback callback,
+ Throwable throwable) {
+ onErrorRetryCount = context.getRetryCount();
+ }
+
+ }
+
+ private TestRetryListener retryListener;
+
+ private RetryTemplate retryTemplate;
+
+ private @Mock MiniMaxApi miniMaxApi;
+
+ private MiniMaxChatClient chatClient;
+
+ private MiniMaxEmbeddingClient embeddingClient;
+
+ @BeforeEach
+ public void beforeEach() {
+ retryTemplate = RetryUtils.DEFAULT_RETRY_TEMPLATE;
+ retryListener = new TestRetryListener();
+ retryTemplate.registerListener(retryListener);
+
+ chatClient = new MiniMaxChatClient(miniMaxApi, MiniMaxChatOptions.builder().build(), null, retryTemplate);
+ embeddingClient = new MiniMaxEmbeddingClient(miniMaxApi, MetadataMode.EMBED,
+ MiniMaxEmbeddingOptions.builder().build(), retryTemplate);
+ }
+
+ @Test
+ public void miniMaxChatTransientError() {
+
+ var choice = new ChatCompletion.Choice(ChatCompletionFinishReason.STOP, 0,
+ new ChatCompletionMessage("Response", Role.ASSISTANT), null);
+ ChatCompletion expectedChatCompletion = new ChatCompletion("id", List.of(choice), 666l, "model", null, null,
+ null, new MiniMaxApi.Usage(10, 10, 10));
+
+ when(miniMaxApi.chatCompletionEntity(isA(ChatCompletionRequest.class)))
+ .thenThrow(new TransientAiException("Transient Error 1"))
+ .thenThrow(new TransientAiException("Transient Error 2"))
+ .thenReturn(ResponseEntity.of(Optional.of(expectedChatCompletion)));
+
+ var result = chatClient.call(new Prompt("text"));
+
+ assertThat(result).isNotNull();
+ assertThat(result.getResult().getOutput().getContent()).isSameAs("Response");
+ assertThat(retryListener.onSuccessRetryCount).isEqualTo(2);
+ assertThat(retryListener.onErrorRetryCount).isEqualTo(2);
+ }
+
+ @Test
+ public void miniMaxChatNonTransientError() {
+ when(miniMaxApi.chatCompletionEntity(isA(ChatCompletionRequest.class)))
+ .thenThrow(new RuntimeException("Non Transient Error"));
+ assertThrows(RuntimeException.class, () -> chatClient.call(new Prompt("text")));
+ }
+
+ @Test
+ public void miniMaxChatStreamTransientError() {
+
+ var choice = new ChatCompletionChunk.ChunkChoice(ChatCompletionFinishReason.STOP, 0,
+ new ChatCompletionMessage("Response", Role.ASSISTANT), null);
+ ChatCompletionChunk expectedChatCompletion = new ChatCompletionChunk("id", List.of(choice), 666l, "model", null,
+ null);
+
+ when(miniMaxApi.chatCompletionStream(isA(ChatCompletionRequest.class)))
+ .thenThrow(new TransientAiException("Transient Error 1"))
+ .thenThrow(new TransientAiException("Transient Error 2"))
+ .thenReturn(Flux.just(expectedChatCompletion));
+
+ var result = chatClient.stream(new Prompt("text"));
+
+ assertThat(result).isNotNull();
+ assertThat(result.collectList().block().get(0).getResult().getOutput().getContent()).isSameAs("Response");
+ assertThat(retryListener.onSuccessRetryCount).isEqualTo(2);
+ assertThat(retryListener.onErrorRetryCount).isEqualTo(2);
+ }
+
+ @Test
+ public void miniMaxChatStreamNonTransientError() {
+ when(miniMaxApi.chatCompletionStream(isA(ChatCompletionRequest.class)))
+ .thenThrow(new RuntimeException("Non Transient Error"));
+ assertThrows(RuntimeException.class, () -> chatClient.stream(new Prompt("text")));
+ }
+
+ @Test
+ public void miniMaxEmbeddingTransientError() {
+
+ EmbeddingList expectedEmbeddings = new EmbeddingList(List.of(List.of(9.9, 8.8)), "model", 10);
+
+ when(miniMaxApi.embeddings(isA(EmbeddingRequest.class)))
+ .thenThrow(new TransientAiException("Transient Error 1"))
+ .thenThrow(new TransientAiException("Transient Error 2"))
+ .thenReturn(ResponseEntity.of(Optional.of(expectedEmbeddings)));
+
+ var result = embeddingClient
+ .call(new org.springframework.ai.embedding.EmbeddingRequest(List.of("text1", "text2"), null));
+
+ assertThat(result).isNotNull();
+ assertThat(result.getResult().getOutput()).isEqualTo(List.of(9.9, 8.8));
+ assertThat(retryListener.onSuccessRetryCount).isEqualTo(2);
+ assertThat(retryListener.onErrorRetryCount).isEqualTo(2);
+ }
+
+ @Test
+ public void miniMaxEmbeddingNonTransientError() {
+ when(miniMaxApi.embeddings(isA(EmbeddingRequest.class)))
+ .thenThrow(new RuntimeException("Non Transient Error"));
+ assertThrows(RuntimeException.class, () -> embeddingClient
+ .call(new org.springframework.ai.embedding.EmbeddingRequest(List.of("text1", "text2"), null)));
+ }
+
+}
diff --git a/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MockWeatherService.java b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MockWeatherService.java
new file mode 100644
index 00000000000..d2f4a9e53d0
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MockWeatherService.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.minimax.api;
+
+import com.fasterxml.jackson.annotation.JsonClassDescription;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyDescription;
+
+import java.util.function.Function;
+
+/**
+ * @author Geng Rong
+ */
+public class MockWeatherService implements Function {
+
+ /**
+ * Weather Function request.
+ */
+ @JsonInclude(Include.NON_NULL)
+ @JsonClassDescription("Weather API request")
+ public record Request(@JsonProperty(required = true,
+ value = "location") @JsonPropertyDescription("The city and state e.g. San Francisco, CA") String location,
+ @JsonProperty(required = true, value = "lat") @JsonPropertyDescription("The city latitude") double lat,
+ @JsonProperty(required = true, value = "lon") @JsonPropertyDescription("The city longitude") double lon,
+ @JsonProperty(required = true, value = "unit") @JsonPropertyDescription("Temperature unit") Unit unit) {
+ }
+
+ /**
+ * Temperature units.
+ */
+ public enum Unit {
+
+ /**
+ * Celsius.
+ */
+ C("metric"),
+ /**
+ * Fahrenheit.
+ */
+ F("imperial");
+
+ /**
+ * Human readable unit name.
+ */
+ public final String unitName;
+
+ private Unit(String text) {
+ this.unitName = text;
+ }
+
+ }
+
+ /**
+ * Weather Function response.
+ */
+ public record Response(double temp, double feels_like, double temp_min, double temp_max, int pressure, int humidity,
+ Unit unit) {
+ }
+
+ @Override
+ public Response apply(Request request) {
+
+ double temperature = 0;
+ if (request.location().contains("Paris")) {
+ temperature = 15;
+ }
+ else if (request.location().contains("Tokyo")) {
+ temperature = 10;
+ }
+ else if (request.location().contains("San Francisco")) {
+ temperature = 30;
+ }
+
+ return new Response(temperature, 15, 20, 2, 53, 45, request.unit);
+ }
+
+}
\ No newline at end of file
diff --git a/models/spring-ai-minimax/src/test/resources/prompts/system-message.st b/models/spring-ai-minimax/src/test/resources/prompts/system-message.st
new file mode 100644
index 00000000000..579febd8d9b
--- /dev/null
+++ b/models/spring-ai-minimax/src/test/resources/prompts/system-message.st
@@ -0,0 +1,3 @@
+You are an AI assistant that helps people find information.
+Your name is {name}.
+You should reply to the user's request with your name and also in the style of a {voice}.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 1aa98332298..f85793b4509 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@
models/spring-ai-vertex-ai-gemini
models/spring-ai-anthropic
models/spring-ai-watsonx-ai
+ models/spring-ai-minimax
spring-ai-test
spring-ai-spring-boot-autoconfigure
spring-ai-spring-boot-starters/spring-ai-starter-openai
@@ -74,6 +75,7 @@
vector-stores/spring-ai-elasticsearch-store
spring-ai-spring-boot-starters/spring-ai-starter-watsonx-ai
spring-ai-spring-boot-starters/spring-ai-starter-elasticsearch-store
+ spring-ai-spring-boot-starters/spring-ai-starter-minimax
diff --git a/spring-ai-bom/pom.xml b/spring-ai-bom/pom.xml
index d1c857f9da9..a435c602424 100644
--- a/spring-ai-bom/pom.xml
+++ b/spring-ai-bom/pom.xml
@@ -124,6 +124,12 @@
${project.version}
+
+ org.springframework.ai
+ spring-ai-minimax
+ ${project.version}
+
+
@@ -384,6 +390,12 @@
spring-ai-elasticsearch-store-spring-boot-starter
${project.version}
+
+
+ org.springframework.ai
+ spring-ai-minimax-spring-boot-starter
+ ${project.version}
+
diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc
index 7d8e11bb98f..1ad4f1123b3 100644
--- a/spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc
+++ b/spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc
@@ -25,6 +25,8 @@
*** xref:api/chat/anthropic-chat.adoc[Anthropic 3]
**** xref:api/chat/functions/anthropic-chat-functions.adoc[Function Calling]
*** xref:api/chat/watsonx-ai-chat.adoc[Watsonx.AI]
+*** xref:api/chat/minimax-chat.adoc[MiniMax]
+**** xref:api/chat/functions/minimax-chat-functions.adoc[Function Calling]
** xref:api/embeddings.adoc[]
*** xref:api/embeddings/openai-embeddings.adoc[OpenAI]
*** xref:api/embeddings/ollama-embeddings.adoc[Ollama]
@@ -36,6 +38,7 @@
**** xref:api/embeddings/bedrock-titan-embedding.adoc[Titan]
*** xref:api/embeddings/onnx.adoc[Transformers (ONNX)]
*** xref:api/embeddings/mistralai-embeddings.adoc[Mistral AI]
+*** xref:api/embeddings/minimax-embeddings.adoc[MiniMax]
** xref:api/imageclient.adoc[]
*** xref:api/image/openai-image.adoc[OpenAI]
*** xref:api/image/stabilityai-image.adoc[Stability]
diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/minimax-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/minimax-chat-functions.adoc
new file mode 100644
index 00000000000..473595ca2b8
--- /dev/null
+++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/minimax-chat-functions.adoc
@@ -0,0 +1,226 @@
+= Function Calling
+
+You can register custom Java functions with the `MiniMaxChatClient` and have the MiniMax model intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
+This allows you to connect the LLM capabilities with external tools and APIs.
+The MiniMax models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
+
+The MiniMax API does not call the function directly; instead, the model generates JSON that you can use to call the function in your code and return the result back to the model to complete the conversation.
+
+Spring AI provides flexible and user-friendly ways to register and call custom functions.
+In general, the custom functions need to provide a function `name`, `description`, and the function call `signature` (as JSON schema) to let the model know what arguments the function expects. The `description` helps the model to understand when to call the function.
+
+As a developer, you need to implement a functions that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results.
+
+Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`.
+
+Under the hood, Spring wraps your POJO (the function) with the appropriate adapter code that enables interaction with the AI Model, saving you from writing tedious boilerplate code.
+The basis of the underlying infrastructure is the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java[FunctionCallback.java] interface and the companion link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java[FunctionCallbackWrapper.java] utility class to simplify the implementation and registration of Java callback functions.
+
+// Additionally, the Auto-Configuration provides a way to auto-register any Function beans definition as function calling candidates in the `ChatClient`.
+
+
+== How it works
+
+Suppose we want the AI model to respond with information that it does not have, for example the current temperature at a given location.
+
+We can provide the AI model with metadata about our own functions that it can use to retrieve that information as it processes your prompt.
+
+For example, if during the processing of a prompt, the AI Model determines that it needs additional information about the temperature in a given location, it will start a server side generated request/response interaction. The AI Model invokes a client side function.
+The AI Model provides method invocation details as JSON and it is the responsibility of the client to execute that function and return the response.
+
+The model-client interaction is illustrated in the <> diagram.
+
+Spring AI greatly simplifies code you need to write to support function invocation.
+It brokers the function invocation conversation for you.
+You can simply provide your function definition as a `@Bean` and then provide the bean name of the function in your prompt options.
+You can also reference multiple function bean names in your prompt.
+
+== Quick Start
+
+Let's create a chatbot that answer questions by calling our own function.
+To support the response of the chatbot, we will register our own function that takes a location and returns the current weather in that location.
+
+When the response to the prompt to the model needs to answer a question such as `"What’s the weather like in Boston?"` the AI model will invoke the client providing the location value as an argument to be passed to the function. This RPC-like data is passed as JSON.
+
+Our function calls some SaaS based weather service API and returns the weather response back to the model to complete the conversation. In this example we will use a simple implementation named `MockWeatherService` that hard codes the temperature for various locations.
+
+The following `MockWeatherService.java` represents the weather service API:
+
+[source,java]
+----
+public class MockWeatherService implements Function {
+
+ public enum Unit { C, F }
+ public record Request(String location, Unit unit) {}
+ public record Response(double temp, Unit unit) {}
+
+ public Response apply(Request request) {
+ return new Response(30.0, Unit.C);
+ }
+}
+----
+
+=== Registering Functions as Beans
+
+With the link:../minimax-chat.html#_auto_configuration[MiniMaxChatClient Auto-Configuration] you have multiple ways to register custom functions as beans in the Spring context.
+
+We start with describing the most POJO friendly options.
+
+
+==== Plain Java Functions
+
+In this approach you define `@Beans` in your application context as you would any other Spring managed object.
+
+Internally, Spring AI `ChatClient` will create an instance of a `FunctionCallbackWrapper` wrapper that adds the logic for it being invoked via the AI model.
+The name of the `@Bean` is passed as a `ChatOption`.
+
+
+[source,java]
+----
+@Configuration
+static class Config {
+
+ @Bean
+ @Description("Get the weather in location") // function description
+ public Function weatherFunction1() {
+ return new MockWeatherService();
+ }
+ ...
+}
+----
+
+The `@Description` annotation is optional and provides a function description (2) that helps the model to understand when to call the function. It is an important property to set to help the AI model determine what client side function to invoke.
+
+Another option to provide the description of the function is to the `@JacksonDescription` annotation on the `MockWeatherService.Request` to provide the function description:
+
+[source,java]
+----
+
+@Configuration
+static class Config {
+
+ @Bean
+ public Function currentWeather3() { // (1) bean name as function name.
+ return new MockWeatherService();
+ }
+ ...
+}
+
+@JsonClassDescription("Get the weather in location") // (2) function description
+public record Request(String location, Unit unit) {}
+----
+
+It is a best practice to annotate the request object with information such that the generates JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
+
+The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/tool/FunctionCallbackWithPlainFunctionBeanIT.java[FunctionCallbackWithPlainFunctionBeanIT.java] demonstrates this approach.
+
+
+==== FunctionCallback Wrapper
+
+Another way register a function is to create `FunctionCallbackWrapper` wrapper like this:
+
+[source,java]
+----
+@Configuration
+static class Config {
+
+ @Bean
+ public FunctionCallback weatherFunctionInfo() {
+
+ return new FunctionCallbackWrapper<>("CurrentWeather", // (1) function name
+ "Get the weather in location", // (2) function description
+ (response) -> "" + response.temp() + response.unit(), // (3) Response Converter
+ new MockWeatherService()); // function code
+ }
+ ...
+}
+----
+
+It wraps the 3rd party, `MockWeatherService` function and registers it as a `CurrentWeather` function with the `MiniMaxChatClient`.
+It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model.
+
+NOTE: By default, the response converter does a JSON serialization of the Response object.
+
+NOTE: The `FunctionCallbackWrapper` internally resolves the function call signature based on the `MockWeatherService.Request` class.
+
+=== Specifying functions in Chat Options
+
+To let the model know and call your `CurrentWeather` function you need to enable it in your prompt requests:
+
+[source,java]
+----
+MiniMaxChatClient chatClient = ...
+
+UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ChatResponse response = chatClient.call(new Prompt(List.of(userMessage),
+ MiniMaxChatOptions.builder().withFunction("CurrentWeather").build())); // (1) Enable the function
+
+logger.info("Response: {}", response);
+----
+
+// NOTE: You can can have multiple functions registered in your `ChatClient` but only those enabled in the prompt request will be considered for the function calling.
+
+Above user question will trigger 3 calls to `CurrentWeather` function (one for each city) and the final response will be something like this:
+
+----
+Here is the current weather for the requested cities:
+- San Francisco, CA: 30.0°C
+- Tokyo, Japan: 10.0°C
+- Paris, France: 15.0°C
+----
+
+The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/tool/FunctionCallbackWrapperIT.java[FunctionCallbackWrapperIT.java] test demo this approach.
+
+
+=== Register/Call Functions with Prompt Options
+
+In addition to the auto-configuration you can register callback functions, dynamically, with your Prompt requests:
+
+[source,java]
+----
+MiniMaxChatClient chatClient = ...
+
+UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+var promptOptions = MiniMaxChatOptions.builder()
+ .withFunctionCallbacks(List.of(new FunctionCallbackWrapper<>(
+ "CurrentWeather", // name
+ "Get the weather in location", // function description
+ new MockWeatherService()))) // function code
+ .build();
+
+ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), promptOptions));
+----
+
+NOTE: The in-prompt registered functions are enabled by default for the duration of this request.
+
+This approach allows to dynamically chose different functions to be called based on the user input.
+
+The https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/tool/FunctionCallbackInPromptIT.java[FunctionCallbackInPromptIT.java] integration test provides a complete example of how to register a function with the `MiniMaxChatClient` and use it in a prompt request.
+//
+// === Register Functions with Default Options
+//
+// You can programmatically register functions with the `MiniMaxChatClient` using the `MiniMaxChatOptions#withFunctionCallbacks`:
+//
+// [source,java]
+// ----
+//
+// MiniMaxApi miniMaxApi = new MiniMaxApi(apiKey);
+//
+// var defaultOptions = MiniMaxChatOptions.builder()
+// .withFunctionCallbacks(List.of(new FunctionCallbackWrapper<>(
+// "CurrentWeather", // name
+// "Get the weather in location", // function description
+// new MockWeatherService()))) // function code
+// .build();
+//
+// MiniMaxChatClient chatClient = new MiniMaxChatClient(miniMaxApi, defaultOptions);
+//
+// UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+//
+// ChatResponse response = chatClient.call(new Prompt(List.of(userMessage),
+// MiniMaxChatOptions.builder().withFunction("CurrentWeather").build())); // Enable the function
+// ----
+//
+// NOTE: Functions are registered when MiniMaxChatClient is created, by you must enable in the Prompt the functions to be used in the request.
\ No newline at end of file
diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/minimax-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/minimax-chat.adoc
new file mode 100644
index 00000000000..1f2d46b237a
--- /dev/null
+++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/minimax-chat.adoc
@@ -0,0 +1,249 @@
+= MiniMax Chat
+
+Spring AI supports the various AI language models from MiniMax. You can interact with MiniMax language models and create a multilingual conversational assistant based on MiniMax models.
+
+== Prerequisites
+
+You will need to create an API with MiniMax to access MiniMax language models.
+
+Create an account at https://www.minimaxi.com/login[MiniMax registration page] and generate the token on the https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
+The Spring AI project defines a configuration property named `spring.ai.minimax.api-key` that you should set to the value of the `API Key` obtained from https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
+Exporting an environment variable is one way to set that configuration property:
+
+[source,shell]
+----
+export SPRING_AI_MINIMAX_API_KEY=
+----
+
+=== Add Repositories and BOM
+
+Spring AI artifacts are published in Spring Milestone and Snapshot repositories.
+Refer to the xref:getting-started.adoc#repositories[Repositories] section to add these repositories to your build system.
+
+To help with dependency management, Spring AI provides a BOM (bill of materials) to ensure that a consistent version of Spring AI is used throughout the entire project. Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build system.
+
+
+
+== Auto-configuration
+
+Spring AI provides Spring Boot auto-configuration for the MiniMax Chat Client.
+To enable it add the following dependency to your project's Maven `pom.xml` file:
+
+[source, xml]
+----
+
+ org.springframework.ai
+ spring-ai-minimax-spring-boot-starter
+
+----
+
+or to your Gradle `build.gradle` build file.
+
+[source,groovy]
+----
+dependencies {
+ implementation 'org.springframework.ai:spring-ai-minimax-spring-boot-starter'
+}
+----
+
+TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
+
+=== Chat Properties
+
+==== Retry Properties
+
+The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the MiniMax Chat client.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.retry.max-attempts | Maximum number of retry attempts. | 10
+| spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec.
+| spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5
+| spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min.
+| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false
+| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty
+| spring.ai.retry.on-http-codes | List of HTTP status codes that should trigger a retry (e.g. to throw TransientAiException). | empty
+|====
+
+==== Connection Properties
+
+The prefix `spring.ai.minimax` is used as the property prefix that lets you connect to MiniMax.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.minimax.base-url | The URL to connect to | https://api.minimax.chat
+| spring.ai.minimax.api-key | The API Key | -
+|====
+
+==== Configuration Properties
+
+The prefix `spring.ai.minimax.chat` is the property prefix that lets you configure the chat client implementation for MiniMax.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.minimax.chat.enabled | Enable MiniMax chat client. | true
+| spring.ai.minimax.chat.base-url | Optional overrides the spring.ai.minimax.base-url to provide chat specific url | https://api.minimax.chat
+| spring.ai.minimax.chat.api-key | Optional overrides the spring.ai.minimax.api-key to provide chat specific api-key | -
+| spring.ai.minimax.chat.options.model | This is the MiniMax Chat model to use | `abab5.5-chat` (the `abab5.5s-chat`, `abab5.5-chat`, and `abab6-chat` point to the latest model versions)
+| spring.ai.minimax.chat.options.maxTokens | The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. | -
+| spring.ai.minimax.chat.options.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.7
+| spring.ai.minimax.chat.options.topP | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. | 1.0
+| spring.ai.minimax.chat.options.n | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Default value is 1 and cannot be greater than 5. Specifically, when the temperature is very small and close to 0, we can only return 1 result. If n is already set and>1 at this time, service will return an illegal input parameter (invalid_request_error) | 1
+| spring.ai.minimax.chat.options.presencePenalty | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. | 0.0f
+| spring.ai.minimax.chat.options.frequencyPenalty | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. | 0.0f
+| spring.ai.minimax.chat.options.stop | The model will stop generating characters specified by stop, and currently only supports a single stop word in the format of ["stop_word1"] | -
+|====
+
+NOTE: You can override the common `spring.ai.minimax.base-url` and `spring.ai.minimax.api-key` for the `ChatClient` implementations.
+The `spring.ai.minimax.chat.base-url` and `spring.ai.minimax.chat.api-key` properties if set take precedence over the common properties.
+This is useful if you want to use different MiniMax accounts for different models and different model endpoints.
+
+TIP: All properties prefixed with `spring.ai.minimax.chat.options` can be overridden at runtime by adding a request specific <> to the `Prompt` call.
+
+== Runtime Options [[chat-options]]
+
+The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatOptions.java[MiniMaxChatOptions.java] provides model configurations, such as the model to use, the temperature, the frequency penalty, etc.
+
+On start-up, the default options can be configured with the `MiniMaxChatClient(api, options)` constructor or the `spring.ai.minimax.chat.options.*` properties.
+
+At run-time you can override the default options by adding new, request specific, options to the `Prompt` call.
+For example to override the default model and temperature for a specific request:
+
+[source,java]
+----
+ChatResponse response = chatClient.call(
+ new Prompt(
+ "Generate the names of 5 famous pirates.",
+ MiniMaxChatOptions.builder()
+ .withModel(MiniMaxApi.ChatModel.GLM_3_Turbo.getValue())
+ .withTemperature(0.5f)
+ .build()
+ ));
+----
+
+TIP: In addition to the model specific link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatOptions.java[MiniMaxChatOptions] you can use a portable https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptions.java[ChatOptions] instance, created with the https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/chat/ChatOptionsBuilder.java[ChatOptionsBuilder#builder()].
+
+== Sample Controller (Auto-configuration)
+
+https://start.spring.io/[Create] a new Spring Boot project and add the `spring-ai-minimax-spring-boot-starter` to your pom (or gradle) dependencies.
+
+Add a `application.properties` file, under the `src/main/resources` directory, to enable and configure the MiniMax Chat client:
+
+[source,application.properties]
+----
+spring.ai.minimax.api-key=YOUR_API_KEY
+spring.ai.minimax.chat.options.model=glm-3-turbo
+spring.ai.minimax.chat.options.temperature=0.7
+----
+
+TIP: replace the `api-key` with your MiniMax credentials.
+
+This will create a `MiniMaxChatClient` implementation that you can inject into your class.
+Here is an example of a simple `@Controller` class that uses the chat client for text generations.
+
+[source,java]
+----
+@RestController
+public class ChatController {
+
+ private final MiniMaxChatClient chatClient;
+
+ @Autowired
+ public ChatController(MiniMaxChatClient chatClient) {
+ this.chatClient = chatClient;
+ }
+
+ @GetMapping("/ai/generate")
+ public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
+ return Map.of("generation", chatClient.call(message));
+ }
+
+ @GetMapping("/ai/generateStream")
+ public Flux generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
+ var prompt = new Prompt(new UserMessage(message));
+ return chatClient.stream(prompt);
+ }
+}
+----
+
+== Manual Configuration
+
+The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatClient.java[MiniMaxChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the <> to connect to the MiniMax service.
+
+Add the `spring-ai-minimax` dependency to your project's Maven `pom.xml` file:
+
+[source, xml]
+----
+
+ org.springframework.ai
+ spring-ai-minimax
+
+----
+
+or to your Gradle `build.gradle` build file.
+
+[source,groovy]
+----
+dependencies {
+ implementation 'org.springframework.ai:spring-ai-minimax'
+}
+----
+
+TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
+
+Next, create a `MiniMaxChatClient` and use it for text generations:
+
+[source,java]
+----
+var miniMaxApi = new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
+
+var chatClient = new MiniMaxChatClient(miniMaxApi, MiniMaxChatOptions.builder()
+ .withModel(MiniMaxApi.ChatModel.GLM_3_Turbo.getValue())
+ .withTemperature(0.4f)
+ .withMaxTokens(200)
+ .build());
+
+ChatResponse response = chatClient.call(
+ new Prompt("Generate the names of 5 famous pirates."));
+
+// Or with streaming responses
+Flux streamResponse = chatClient.stream(
+ new Prompt("Generate the names of 5 famous pirates."));
+----
+
+The `MiniMaxChatOptions` provides the configuration information for the chat requests.
+The `MiniMaxChatOptions.Builder` is fluent options builder.
+
+=== Low-level MiniMaxApi Client [[low-level-api]]
+
+The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxApi.java[MiniMaxApi] provides is lightweight Java client for link:https://www.minimaxi.com/document/guides/chat-model/V2[MiniMax API].
+
+Here is a simple snippet how to use the api programmatically:
+
+[source,java]
+----
+MiniMaxApi miniMaxApi =
+ new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
+
+ChatCompletionMessage chatCompletionMessage =
+ new ChatCompletionMessage("Hello world", Role.USER);
+
+// Sync request
+ResponseEntity response = miniMaxApi.chatCompletionEntity(
+ new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.GLM_3_Turbo.getValue(), 0.7f, false));
+
+// Streaming request
+Flux streamResponse = miniMaxApi.chatCompletionStream(
+ new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.GLM_3_Turbo.getValue(), 0.7f, true));
+----
+
+Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxApi.java[MiniMaxApi.java]'s JavaDoc for further information.
+
+==== MiniMaxApi Samples
+* The link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/api/MiniMaxApiIT.java[MiniMaxApiIT.java] test provides some general examples how to use the lightweight library.
\ No newline at end of file
diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/minimax-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/minimax-embeddings.adoc
new file mode 100644
index 00000000000..da452c69dd8
--- /dev/null
+++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/minimax-embeddings.adoc
@@ -0,0 +1,198 @@
+= MiniMax Chat
+
+Spring AI supports the various AI language models from MiniMax. You can interact with MiniMax language models and create a multilingual conversational assistant based on MiniMax models.
+
+== Prerequisites
+
+You will need to create an API with MiniMax to access MiniMax language models.
+
+Create an account at https://www.minimaxi.com/login[MiniMax registration page] and generate the token on the https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
+The Spring AI project defines a configuration property named `spring.ai.minimax.api-key` that you should set to the value of the `API Key` obtained from https://www.minimaxi.com/user-center/basic-information/interface-key[API Keys page].
+Exporting an environment variable is one way to set that configuration property:
+
+[source,shell]
+----
+export SPRING_AI_MINIMAX_API_KEY=
+----
+
+=== Add Repositories and BOM
+
+Spring AI artifacts are published in Spring Milestone and Snapshot repositories.
+Refer to the xref:getting-started.adoc#repositories[Repositories] section to add these repositories to your build system.
+
+To help with dependency management, Spring AI provides a BOM (bill of materials) to ensure that a consistent version of Spring AI is used throughout the entire project. Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build system.
+
+
+
+== Auto-configuration
+
+Spring AI provides Spring Boot auto-configuration for the Azure MiniMax Embedding Client.
+To enable it add the following dependency to your project's Maven `pom.xml` file:
+
+[source, xml]
+----
+
+ org.springframework.ai
+ spring-ai-minimax-spring-boot-starter
+
+----
+
+or to your Gradle `build.gradle` build file.
+
+[source,groovy]
+----
+dependencies {
+ implementation 'org.springframework.ai:spring-ai-minimax-spring-boot-starter'
+}
+----
+
+TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
+
+=== Embedding Properties
+
+==== Retry Properties
+
+The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the MiniMax Embedding client.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.retry.max-attempts | Maximum number of retry attempts. | 10
+| spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec.
+| spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5
+| spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min.
+| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false
+| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty
+| spring.ai.retry.on-http-codes | List of HTTP status codes that should trigger a retry (e.g. to throw TransientAiException). | empty
+|====
+
+==== Connection Properties
+
+The prefix `spring.ai.minimax` is used as the property prefix that lets you connect to MiniMax.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.minimax.base-url | The URL to connect to | https://api.minimax.chat
+| spring.ai.minimax.api-key | The API Key | -
+|====
+
+==== Configuration Properties
+
+The prefix `spring.ai.minimax.embedding` is property prefix that configures the `EmbeddingClient` implementation for MiniMax.
+
+[cols="3,5,1"]
+|====
+| Property | Description | Default
+
+| spring.ai.minimax.embedding.enabled | Enable MiniMax embedding client. | true
+| spring.ai.minimax.embedding.base-url | Optional overrides the spring.ai.minimax.base-url to provide embedding specific url | -
+| spring.ai.minimax.embedding.api-key | Optional overrides the spring.ai.minimax.api-key to provide embedding specific api-key | -
+| spring.ai.minimax.embedding.options.model | The model to use | embo-01
+|====
+
+NOTE: You can override the common `spring.ai.minimax.base-url` and `spring.ai.minimax.api-key` for the `ChatClient` and `EmbeddingClient` implementations.
+The `spring.ai.minimax.embedding.base-url` and `spring.ai.minimax.embedding.api-key` properties if set take precedence over the common properties.
+Similarly, the `spring.ai.minimax.embedding.base-url` and `spring.ai.minimax.embedding.api-key` properties if set take precedence over the common properties.
+This is useful if you want to use different MiniMax accounts for different models and different model endpoints.
+
+TIP: All properties prefixed with `spring.ai.minimax.embedding.options` can be overridden at runtime by adding a request specific <> to the `EmbeddingRequest` call.
+
+== Runtime Options [[embedding-options]]
+
+The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxEmbeddingOptions.java[MiniMaxEmbeddingOptions.java] provides the MiniMax configurations, such as the model to use and etc.
+
+The default options can be configured using the `spring.ai.minimax.embedding.options` properties as well.
+
+At start-time use the `MiniMaxEmbeddingClient` constructor to set the default options used for all embedding requests.
+At run-time you can override the default options, using a `MiniMaxEmbeddingOptions` instance as part of your `EmbeddingRequest`.
+
+For example to override the default model name for a specific request:
+
+[source,java]
+----
+EmbeddingResponse embeddingResponse = embeddingClient.call(
+ new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"),
+ MiniMaxEmbeddingOptions.builder()
+ .withModel("Different-Embedding-Model-Deployment-Name")
+ .build()));
+----
+
+== Sample Controller
+
+This will create a `EmbeddingClient` implementation that you can inject into your class.
+Here is an example of a simple `@Controller` class that uses the `EmbeddingClient` implementation.
+
+[source,application.properties]
+----
+spring.ai.minimax.api-key=YOUR_API_KEY
+spring.ai.minimax.embedding.options.model=embo-01
+----
+
+[source,java]
+----
+@RestController
+public class EmbeddingController {
+
+ private final EmbeddingClient embeddingClient;
+
+ @Autowired
+ public EmbeddingController(EmbeddingClient embeddingClient) {
+ this.embeddingClient = embeddingClient;
+ }
+
+ @GetMapping("/ai/embedding")
+ public Map embed(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
+ EmbeddingResponse embeddingResponse = this.embeddingClient.embedForResponse(List.of(message));
+ return Map.of("embedding", embeddingResponse);
+ }
+}
+----
+
+== Manual Configuration
+
+If you are not using Spring Boot, you can manually configure the MiniMax Embedding Client.
+For this add the `spring-ai-minimax` dependency to your project's Maven `pom.xml` file:
+[source, xml]
+----
+
+ org.springframework.ai
+ spring-ai-minimax
+
+----
+
+or to your Gradle `build.gradle` build file.
+
+[source,groovy]
+----
+dependencies {
+ implementation 'org.springframework.ai:spring-ai-minimax'
+}
+----
+
+TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
+
+NOTE: The `spring-ai-minimax` dependency provides access also to the `MiniMaxChatClient`.
+For more information about the `MiniMaxChatClient` refer to the link:../chat/minimax-chat.html[MiniMax Chat Client] section.
+
+Next, create an `MiniMaxEmbeddingClient` instance and use it to compute the similarity between two input texts:
+
+[source,java]
+----
+var miniMaxApi = new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
+
+var embeddingClient = new MiniMaxEmbeddingClient(miniMaxApi)
+ .withDefaultOptions(MiniMaxChatOptions.build()
+ .withModel("embo-01")
+ .build());
+
+EmbeddingResponse embeddingResponse = embeddingClient
+ .embedForResponse(List.of("Hello World", "World is big and salvation is near"));
+----
+
+The `MiniMaxEmbeddingOptions` provides the configuration information for the embedding requests.
+The options class offers a `builder()` for easy options creation.
+
+
diff --git a/spring-ai-spring-boot-autoconfigure/pom.xml b/spring-ai-spring-boot-autoconfigure/pom.xml
index d48275f3d83..1ca3a738a13 100644
--- a/spring-ai-spring-boot-autoconfigure/pom.xml
+++ b/spring-ai-spring-boot-autoconfigure/pom.xml
@@ -267,6 +267,13 @@
true
+
+ org.springframework.ai
+ spring-ai-minimax
+ ${project.parent.version}
+ true
+
+
diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfiguration.java
new file mode 100644
index 00000000000..f3c805db2ce
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfiguration.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxEmbeddingClient;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.ai.model.function.FunctionCallback;
+import org.springframework.ai.model.function.FunctionCallbackContext;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.retry.support.RetryTemplate;
+import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.client.ResponseErrorHandler;
+import org.springframework.web.client.RestClient;
+
+import java.util.List;
+
+/**
+ * @author Geng Rong
+ */
+@AutoConfiguration(after = { RestClientAutoConfiguration.class, SpringAiRetryAutoConfiguration.class })
+@ConditionalOnClass(MiniMaxApi.class)
+@EnableConfigurationProperties({ MiniMaxConnectionProperties.class, MiniMaxChatProperties.class,
+ MiniMaxEmbeddingProperties.class })
+public class MiniMaxAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnProperty(prefix = MiniMaxChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
+ matchIfMissing = true)
+ public MiniMaxChatClient miniMaxChatClient(MiniMaxConnectionProperties commonProperties,
+ MiniMaxChatProperties chatProperties, RestClient.Builder restClientBuilder,
+ List toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext,
+ RetryTemplate retryTemplate, ResponseErrorHandler responseErrorHandler) {
+
+ var miniMaxApi = miniMaxApi(chatProperties.getBaseUrl(), commonProperties.getBaseUrl(),
+ chatProperties.getApiKey(), commonProperties.getApiKey(), restClientBuilder, responseErrorHandler);
+
+ if (!CollectionUtils.isEmpty(toolFunctionCallbacks)) {
+ chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks);
+ }
+
+ return new MiniMaxChatClient(miniMaxApi, chatProperties.getOptions(), functionCallbackContext, retryTemplate);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnProperty(prefix = MiniMaxEmbeddingProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
+ matchIfMissing = true)
+ public MiniMaxEmbeddingClient miniMaxEmbeddingClient(MiniMaxConnectionProperties commonProperties,
+ MiniMaxEmbeddingProperties embeddingProperties, RestClient.Builder restClientBuilder,
+ RetryTemplate retryTemplate, ResponseErrorHandler responseErrorHandler) {
+
+ var miniMaxApi = miniMaxApi(embeddingProperties.getBaseUrl(), commonProperties.getBaseUrl(),
+ embeddingProperties.getApiKey(), commonProperties.getApiKey(), restClientBuilder, responseErrorHandler);
+
+ return new MiniMaxEmbeddingClient(miniMaxApi, embeddingProperties.getMetadataMode(),
+ embeddingProperties.getOptions(), retryTemplate);
+ }
+
+ private MiniMaxApi miniMaxApi(String baseUrl, String commonBaseUrl, String apiKey, String commonApiKey,
+ RestClient.Builder restClientBuilder, ResponseErrorHandler responseErrorHandler) {
+
+ String resolvedBaseUrl = StringUtils.hasText(baseUrl) ? baseUrl : commonBaseUrl;
+ Assert.hasText(resolvedBaseUrl, "MiniMax base URL must be set");
+
+ String resolvedApiKey = StringUtils.hasText(apiKey) ? apiKey : commonApiKey;
+ Assert.hasText(resolvedApiKey, "MiniMax API key must be set");
+
+ return new MiniMaxApi(resolvedBaseUrl, resolvedApiKey, restClientBuilder, responseErrorHandler);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public FunctionCallbackContext springAiFunctionManager(ApplicationContext context) {
+ FunctionCallbackContext manager = new FunctionCallbackContext();
+ manager.setApplicationContext(context);
+ return manager;
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxChatProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxChatProperties.java
new file mode 100644
index 00000000000..c7f3716f386
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxChatProperties.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.springframework.ai.minimax.MiniMaxChatOptions;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+
+/**
+ * @author Geng Rong
+ */
+@ConfigurationProperties(MiniMaxChatProperties.CONFIG_PREFIX)
+public class MiniMaxChatProperties extends MiniMaxParentProperties {
+
+ public static final String CONFIG_PREFIX = "spring.ai.minimax.chat";
+
+ public static final String DEFAULT_CHAT_MODEL = MiniMaxApi.ChatModel.ABAB_5_5_Chat.value;
+
+ private static final Double DEFAULT_TEMPERATURE = 0.7;
+
+ /**
+ * Enable MiniMax chat client.
+ */
+ private boolean enabled = true;
+
+ @NestedConfigurationProperty
+ private MiniMaxChatOptions options = MiniMaxChatOptions.builder()
+ .withModel(DEFAULT_CHAT_MODEL)
+ .withTemperature(DEFAULT_TEMPERATURE.floatValue())
+ .build();
+
+ public MiniMaxChatOptions getOptions() {
+ return options;
+ }
+
+ public void setOptions(MiniMaxChatOptions options) {
+ this.options = options;
+ }
+
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxConnectionProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxConnectionProperties.java
new file mode 100644
index 00000000000..1019e849949
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxConnectionProperties.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(MiniMaxConnectionProperties.CONFIG_PREFIX)
+public class MiniMaxConnectionProperties extends MiniMaxParentProperties {
+
+ public static final String CONFIG_PREFIX = "spring.ai.minimax";
+
+ public static final String DEFAULT_BASE_URL = "https://api.minimax.chat";
+
+ public MiniMaxConnectionProperties() {
+ super.setBaseUrl(DEFAULT_BASE_URL);
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxEmbeddingProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxEmbeddingProperties.java
new file mode 100644
index 00000000000..21fbb752e90
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxEmbeddingProperties.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.springframework.ai.document.MetadataMode;
+import org.springframework.ai.minimax.MiniMaxEmbeddingOptions;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+
+/**
+ * @author Geng Rong
+ */
+@ConfigurationProperties(MiniMaxEmbeddingProperties.CONFIG_PREFIX)
+public class MiniMaxEmbeddingProperties extends MiniMaxParentProperties {
+
+ public static final String CONFIG_PREFIX = "spring.ai.minimax.embedding";
+
+ public static final String DEFAULT_EMBEDDING_MODEL = MiniMaxApi.EmbeddingModel.Embo_01.value;
+
+ /**
+ * Enable MiniMax embedding client.
+ */
+ private boolean enabled = true;
+
+ private MetadataMode metadataMode = MetadataMode.EMBED;
+
+ @NestedConfigurationProperty
+ private MiniMaxEmbeddingOptions options = MiniMaxEmbeddingOptions.builder()
+ .withModel(DEFAULT_EMBEDDING_MODEL)
+ .build();
+
+ public MiniMaxEmbeddingOptions getOptions() {
+ return this.options;
+ }
+
+ public void setOptions(MiniMaxEmbeddingOptions options) {
+ this.options = options;
+ }
+
+ public MetadataMode getMetadataMode() {
+ return this.metadataMode;
+ }
+
+ public void setMetadataMode(MetadataMode metadataMode) {
+ this.metadataMode = metadataMode;
+ }
+
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxParentProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxParentProperties.java
new file mode 100644
index 00000000000..1f8f9f6b722
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/minimax/MiniMaxParentProperties.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+/**
+ * @author Geng Rong
+ */
+class MiniMaxParentProperties {
+
+ private String apiKey;
+
+ private String baseUrl;
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
+ public String getBaseUrl() {
+ return baseUrl;
+ }
+
+ public void setBaseUrl(String baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackInPromptIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackInPromptIT.java
new file mode 100644
index 00000000000..7026812a6ed
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackInPromptIT.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.Generation;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxChatOptions;
+import org.springframework.ai.model.function.FunctionCallbackWrapper;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".*")
+public class FunctionCallbackInPromptIT {
+
+ private final Logger logger = LoggerFactory.getLogger(FunctionCallbackInPromptIT.class);
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.apiKey=" + System.getenv("MINIMAX_API_KEY"))
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class));
+
+ @Test
+ void functionCallTest() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ var promptOptions = MiniMaxChatOptions.builder()
+ .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName("CurrentWeatherService")
+ .withDescription("Get the weather in location")
+ .withResponseConverter((response) -> "" + response.temp() + response.unit())
+ .build()))
+ .build();
+
+ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), promptOptions));
+
+ logger.info("Response: {}", response);
+
+ assertThat(response.getResult().getOutput().getContent()).contains("30.0", "10.0", "15.0");
+ });
+ }
+
+ @Test
+ void streamingFunctionCallTest() {
+
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ var promptOptions = MiniMaxChatOptions.builder()
+ .withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName("CurrentWeatherService")
+ .withDescription("Get the weather in location")
+ .withResponseConverter((response) -> "" + response.temp() + response.unit())
+ .build()))
+ .build();
+
+ Flux response = chatClient.stream(new Prompt(List.of(userMessage), promptOptions));
+
+ String content = response.collectList()
+ .block()
+ .stream()
+ .map(ChatResponse::getResults)
+ .flatMap(List::stream)
+ .map(Generation::getOutput)
+ .map(AssistantMessage::getContent)
+ .collect(Collectors.joining());
+ logger.info("Response: {}", content);
+
+ assertThat(content).containsAnyOf("30.0", "30");
+ assertThat(content).containsAnyOf("10.0", "10");
+ assertThat(content).containsAnyOf("15.0", "15");
+ });
+ }
+
+}
\ No newline at end of file
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWithPlainFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWithPlainFunctionBeanIT.java
new file mode 100644
index 00000000000..1c1492e65f9
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWithPlainFunctionBeanIT.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.Generation;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxChatOptions;
+import org.springframework.ai.model.function.FunctionCallingOptions;
+import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".*")
+class FunctionCallbackWithPlainFunctionBeanIT {
+
+ private final Logger logger = LoggerFactory.getLogger(FunctionCallbackWithPlainFunctionBeanIT.class);
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.apiKey=" + System.getenv("MINIMAX_API_KEY"))
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .withUserConfiguration(Config.class);
+
+ @Test
+ void functionCallTest() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ // Test weatherFunction
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage),
+ MiniMaxChatOptions.builder().withFunction("weatherFunction").build()));
+
+ logger.info("Response: {}", response);
+
+ assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
+
+ // Test weatherFunctionTwo
+ response = chatClient.call(new Prompt(List.of(userMessage),
+ MiniMaxChatOptions.builder().withFunction("weatherFunctionTwo").build()));
+
+ logger.info("Response: {}", response);
+
+ assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
+
+ });
+ }
+
+ @Test
+ void functionCallWithPortableFunctionCallingOptions() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ // Test weatherFunction
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ PortableFunctionCallingOptions functionOptions = FunctionCallingOptions.builder()
+ .withFunction("weatherFunction")
+ .build();
+
+ ChatResponse response = chatClient.call(new Prompt(List.of(userMessage), functionOptions));
+
+ logger.info("Response: {}", response);
+ });
+ }
+
+ @Test
+ void streamFunctionCallTest() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ // Test weatherFunction
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ Flux response = chatClient.stream(new Prompt(List.of(userMessage),
+ MiniMaxChatOptions.builder().withFunction("weatherFunction").build()));
+
+ String content = response.collectList()
+ .block()
+ .stream()
+ .map(ChatResponse::getResults)
+ .flatMap(List::stream)
+ .map(Generation::getOutput)
+ .map(AssistantMessage::getContent)
+ .collect(Collectors.joining());
+ logger.info("Response: {}", content);
+
+ assertThat(content).containsAnyOf("30.0", "30");
+ assertThat(content).containsAnyOf("10.0", "10");
+ assertThat(content).containsAnyOf("15.0", "15");
+
+ // Test weatherFunctionTwo
+ response = chatClient.stream(new Prompt(List.of(userMessage),
+ MiniMaxChatOptions.builder().withFunction("weatherFunctionTwo").build()));
+
+ content = response.collectList()
+ .block()
+ .stream()
+ .map(ChatResponse::getResults)
+ .flatMap(List::stream)
+ .map(Generation::getOutput)
+ .map(AssistantMessage::getContent)
+ .collect(Collectors.joining());
+ logger.info("Response: {}", content);
+
+ assertThat(content).containsAnyOf("30.0", "30");
+ assertThat(content).containsAnyOf("10.0", "10");
+ assertThat(content).containsAnyOf("15.0", "15");
+ });
+ }
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ @Description("Get the weather in location")
+ public Function weatherFunction() {
+ return new MockWeatherService();
+ }
+
+ // Relies on the Request's JsonClassDescription annotation to provide the
+ // function description.
+ @Bean
+ public Function weatherFunctionTwo() {
+ MockWeatherService weatherService = new MockWeatherService();
+ return (weatherService::apply);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWrapperIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWrapperIT.java
new file mode 100644
index 00000000000..75530376fc2
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/FunctionCallbackWrapperIT.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.Generation;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxChatOptions;
+import org.springframework.ai.model.function.FunctionCallback;
+import org.springframework.ai.model.function.FunctionCallbackWrapper;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".*")
+public class FunctionCallbackWrapperIT {
+
+ private final Logger logger = LoggerFactory.getLogger(FunctionCallbackWrapperIT.class);
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.apiKey=" + System.getenv("MINIMAX_API_KEY"))
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .withUserConfiguration(Config.class);
+
+ @Test
+ void functionCallTest() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ ChatResponse response = chatClient.call(
+ new Prompt(List.of(userMessage), MiniMaxChatOptions.builder().withFunction("WeatherInfo").build()));
+
+ logger.info("Response: {}", response);
+
+ assertThat(response.getResult().getOutput().getContent()).contains("30.0", "10.0", "15.0");
+
+ });
+ }
+
+ @Test
+ void streamFunctionCallTest() {
+ contextRunner.withPropertyValues("spring.ai.minimax.chat.options.model=abab6-chat").run(context -> {
+
+ MiniMaxChatClient chatClient = context.getBean(MiniMaxChatClient.class);
+
+ UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
+
+ Flux response = chatClient.stream(
+ new Prompt(List.of(userMessage), MiniMaxChatOptions.builder().withFunction("WeatherInfo").build()));
+
+ String content = response.collectList()
+ .block()
+ .stream()
+ .map(ChatResponse::getResults)
+ .flatMap(List::stream)
+ .map(Generation::getOutput)
+ .map(AssistantMessage::getContent)
+ .collect(Collectors.joining());
+ logger.info("Response: {}", content);
+
+ assertThat(content).containsAnyOf("30.0", "30");
+ assertThat(content).containsAnyOf("10.0", "10");
+ assertThat(content).containsAnyOf("15.0", "15");
+
+ });
+ }
+
+ @Configuration
+ static class Config {
+
+ @Bean
+ public FunctionCallback weatherFunctionInfo() {
+
+ return FunctionCallbackWrapper.builder(new MockWeatherService())
+ .withName("WeatherInfo")
+ .withDescription("Get the weather in location")
+ .withResponseConverter((response) -> "" + response.temp() + response.unit())
+ .build();
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfigurationIT.java
new file mode 100644
index 00000000000..d400b2c4703
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxAutoConfigurationIT.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.chat.ChatResponse;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.ai.chat.prompt.Prompt;
+import org.springframework.ai.embedding.EmbeddingResponse;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxEmbeddingClient;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import reactor.core.publisher.Flux;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Geng Rong
+ */
+@EnabledIfEnvironmentVariable(named = "MINIMAX_API_KEY", matches = ".*")
+public class MiniMaxAutoConfigurationIT {
+
+ private static final Log logger = LogFactory.getLog(MiniMaxAutoConfigurationIT.class);
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.apiKey=" + System.getenv("MINIMAX_API_KEY"))
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class));
+
+ @Test
+ void generate() {
+ contextRunner.run(context -> {
+ MiniMaxChatClient client = context.getBean(MiniMaxChatClient.class);
+ String response = client.call("Hello");
+ assertThat(response).isNotEmpty();
+ logger.info("Response: " + response);
+ });
+ }
+
+ @Test
+ void generateStreaming() {
+ contextRunner.run(context -> {
+ MiniMaxChatClient client = context.getBean(MiniMaxChatClient.class);
+ Flux responseFlux = client.stream(new Prompt(new UserMessage("Hello")));
+ String response = responseFlux.collectList().block().stream().map(chatResponse -> {
+ return chatResponse.getResults().get(0).getOutput().getContent();
+ }).collect(Collectors.joining());
+
+ assertThat(response).isNotEmpty();
+ logger.info("Response: " + response);
+ });
+ }
+
+ @Test
+ void embedding() {
+ contextRunner.run(context -> {
+ MiniMaxEmbeddingClient embeddingClient = context.getBean(MiniMaxEmbeddingClient.class);
+
+ EmbeddingResponse embeddingResponse = embeddingClient
+ .embedForResponse(List.of("Hello World", "World is big and salvation is near"));
+ assertThat(embeddingResponse.getResults()).hasSize(2);
+ assertThat(embeddingResponse.getResults().get(0).getOutput()).isNotEmpty();
+ assertThat(embeddingResponse.getResults().get(0).getIndex()).isEqualTo(0);
+ assertThat(embeddingResponse.getResults().get(1).getOutput()).isNotEmpty();
+ assertThat(embeddingResponse.getResults().get(1).getIndex()).isEqualTo(1);
+
+ assertThat(embeddingClient.dimensions()).isEqualTo(1536);
+ });
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxPropertiesTests.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxPropertiesTests.java
new file mode 100644
index 00000000000..31e1035081b
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MiniMaxPropertiesTests.java
@@ -0,0 +1,329 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import org.junit.jupiter.api.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
+import org.springframework.ai.minimax.MiniMaxChatClient;
+import org.springframework.ai.minimax.MiniMaxEmbeddingClient;
+import org.springframework.ai.minimax.api.MiniMaxApi;
+import org.springframework.ai.model.ModelOptionsUtils;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit Tests for
+ * {@link org.springframework.ai.autoconfigure.minimax.MiniMaxConnectionProperties},
+ * {@link org.springframework.ai.autoconfigure.minimax.MiniMaxChatProperties} and
+ * {@link org.springframework.ai.autoconfigure.minimax.MiniMaxEmbeddingProperties}.
+ *
+ * @author Geng Rong
+ */
+public class MiniMaxPropertiesTests {
+
+ @Test
+ public void chatProperties() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.api-key=abc123",
+ "spring.ai.minimax.chat.options.model=MODEL_XYZ",
+ "spring.ai.minimax.chat.options.temperature=0.55")
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var chatProperties = context.getBean(MiniMaxChatProperties.class);
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+
+ assertThat(connectionProperties.getApiKey()).isEqualTo("abc123");
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+
+ assertThat(chatProperties.getApiKey()).isNull();
+ assertThat(chatProperties.getBaseUrl()).isNull();
+
+ assertThat(chatProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ assertThat(chatProperties.getOptions().getTemperature()).isEqualTo(0.55f);
+ });
+ }
+
+ @Test
+ public void chatOverrideConnectionProperties() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.api-key=abc123",
+ "spring.ai.minimax.chat.base-url=TEST_BASE_URL2",
+ "spring.ai.minimax.chat.api-key=456",
+ "spring.ai.minimax.chat.options.model=MODEL_XYZ",
+ "spring.ai.minimax.chat.options.temperature=0.55")
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var chatProperties = context.getBean(MiniMaxChatProperties.class);
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+
+ assertThat(connectionProperties.getApiKey()).isEqualTo("abc123");
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+
+ assertThat(chatProperties.getApiKey()).isEqualTo("456");
+ assertThat(chatProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL2");
+
+ assertThat(chatProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ assertThat(chatProperties.getOptions().getTemperature()).isEqualTo(0.55f);
+ });
+ }
+
+ @Test
+ public void embeddingProperties() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.api-key=abc123",
+ "spring.ai.minimax.embedding.options.model=MODEL_XYZ")
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var embeddingProperties = context.getBean(MiniMaxEmbeddingProperties.class);
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+
+ assertThat(connectionProperties.getApiKey()).isEqualTo("abc123");
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+
+ assertThat(embeddingProperties.getApiKey()).isNull();
+ assertThat(embeddingProperties.getBaseUrl()).isNull();
+
+ assertThat(embeddingProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ });
+ }
+
+ @Test
+ public void embeddingOverrideConnectionProperties() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.api-key=abc123",
+ "spring.ai.minimax.embedding.base-url=TEST_BASE_URL2",
+ "spring.ai.minimax.embedding.api-key=456",
+ "spring.ai.minimax.embedding.options.model=MODEL_XYZ")
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var embeddingProperties = context.getBean(MiniMaxEmbeddingProperties.class);
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+
+ assertThat(connectionProperties.getApiKey()).isEqualTo("abc123");
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+
+ assertThat(embeddingProperties.getApiKey()).isEqualTo("456");
+ assertThat(embeddingProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL2");
+
+ assertThat(embeddingProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ });
+ }
+
+ @Test
+ public void chatOptionsTest() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.api-key=API_KEY",
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+
+ "spring.ai.minimax.chat.options.model=MODEL_XYZ",
+ "spring.ai.minimax.chat.options.frequencyPenalty=-1.5",
+ "spring.ai.minimax.chat.options.logitBias.myTokenId=-5",
+ "spring.ai.minimax.chat.options.maxTokens=123",
+ "spring.ai.minimax.chat.options.n=10",
+ "spring.ai.minimax.chat.options.presencePenalty=0",
+ "spring.ai.minimax.chat.options.responseFormat.type=json",
+ "spring.ai.minimax.chat.options.seed=66",
+ "spring.ai.minimax.chat.options.stop=boza,koza",
+ "spring.ai.minimax.chat.options.temperature=0.55",
+ "spring.ai.minimax.chat.options.topP=0.56",
+
+ // "spring.ai.minimax.chat.options.toolChoice.functionName=toolChoiceFunctionName",
+ "spring.ai.minimax.chat.options.toolChoice=" + ModelOptionsUtils.toJsonString(MiniMaxApi.ChatCompletionRequest.ToolChoiceBuilder.FUNCTION("toolChoiceFunctionName")),
+
+ "spring.ai.minimax.chat.options.tools[0].function.name=myFunction1",
+ "spring.ai.minimax.chat.options.tools[0].function.description=function description",
+ "spring.ai.minimax.chat.options.tools[0].function.jsonSchema=" + """
+ {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "description": "The city and state e.g. San Francisco, CA"
+ },
+ "lat": {
+ "type": "number",
+ "description": "The city latitude"
+ },
+ "lon": {
+ "type": "number",
+ "description": "The city longitude"
+ },
+ "unit": {
+ "type": "string",
+ "enum": ["c", "f"]
+ }
+ },
+ "required": ["location", "lat", "lon", "unit"]
+ }
+ """
+ )
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var chatProperties = context.getBean(MiniMaxChatProperties.class);
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+ var embeddingProperties = context.getBean(MiniMaxEmbeddingProperties.class);
+
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+ assertThat(connectionProperties.getApiKey()).isEqualTo("API_KEY");
+
+ assertThat(embeddingProperties.getOptions().getModel()).isEqualTo("embo-01");
+
+ assertThat(chatProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ assertThat(chatProperties.getOptions().getFrequencyPenalty()).isEqualTo(-1.5f);
+ assertThat(chatProperties.getOptions().getMaxTokens()).isEqualTo(123);
+ assertThat(chatProperties.getOptions().getN()).isEqualTo(10);
+ assertThat(chatProperties.getOptions().getPresencePenalty()).isEqualTo(0);
+ assertThat(chatProperties.getOptions().getResponseFormat())
+ .isEqualTo(new MiniMaxApi.ChatCompletionRequest.ResponseFormat("json"));
+ assertThat(chatProperties.getOptions().getSeed()).isEqualTo(66);
+ assertThat(chatProperties.getOptions().getStop()).contains("boza", "koza");
+ assertThat(chatProperties.getOptions().getTemperature()).isEqualTo(0.55f);
+ assertThat(chatProperties.getOptions().getTopP()).isEqualTo(0.56f);
+
+ JSONAssert.assertEquals("{\"type\":\"function\",\"function\":{\"name\":\"toolChoiceFunctionName\"}}",
+ chatProperties.getOptions().getToolChoice(), JSONCompareMode.LENIENT);
+
+ assertThat(chatProperties.getOptions().getTools()).hasSize(1);
+ var tool = chatProperties.getOptions().getTools().get(0);
+ assertThat(tool.type()).isEqualTo(MiniMaxApi.FunctionTool.Type.FUNCTION);
+ var function = tool.function();
+ assertThat(function.name()).isEqualTo("myFunction1");
+ assertThat(function.description()).isEqualTo("function description");
+ assertThat(function.parameters()).isNotEmpty();
+ });
+ }
+
+ @Test
+ public void embeddingOptionsTest() {
+
+ new ApplicationContextRunner().withPropertyValues(
+ // @formatter:off
+ "spring.ai.minimax.api-key=API_KEY",
+ "spring.ai.minimax.base-url=TEST_BASE_URL",
+
+ "spring.ai.minimax.embedding.options.model=MODEL_XYZ",
+ "spring.ai.minimax.embedding.options.encodingFormat=MyEncodingFormat"
+ )
+ // @formatter:on
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ var connectionProperties = context.getBean(MiniMaxConnectionProperties.class);
+ var embeddingProperties = context.getBean(MiniMaxEmbeddingProperties.class);
+
+ assertThat(connectionProperties.getBaseUrl()).isEqualTo("TEST_BASE_URL");
+ assertThat(connectionProperties.getApiKey()).isEqualTo("API_KEY");
+
+ assertThat(embeddingProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
+ });
+ }
+
+ @Test
+ void embeddingActivation() {
+
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.embedding.enabled=false")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingClient.class)).isEmpty();
+ });
+
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingClient.class)).isNotEmpty();
+ });
+
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.embedding.enabled=true")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxEmbeddingClient.class)).isNotEmpty();
+ });
+ }
+
+ @Test
+ void chatActivation() {
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.chat.enabled=false")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxChatProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxChatClient.class)).isEmpty();
+ });
+
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxChatProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxChatClient.class)).isNotEmpty();
+ });
+
+ new ApplicationContextRunner()
+ .withPropertyValues("spring.ai.minimax.api-key=API_KEY", "spring.ai.minimax.base-url=TEST_BASE_URL",
+ "spring.ai.minimax.chat.enabled=true")
+ .withConfiguration(AutoConfigurations.of(SpringAiRetryAutoConfiguration.class,
+ RestClientAutoConfiguration.class, MiniMaxAutoConfiguration.class))
+ .run(context -> {
+ assertThat(context.getBeansOfType(MiniMaxChatProperties.class)).isNotEmpty();
+ assertThat(context.getBeansOfType(MiniMaxChatClient.class)).isNotEmpty();
+ });
+
+ }
+
+}
diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MockWeatherService.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MockWeatherService.java
new file mode 100644
index 00000000000..29967264ea7
--- /dev/null
+++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/minimax/MockWeatherService.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2023 - 2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.ai.autoconfigure.minimax;
+
+import com.fasterxml.jackson.annotation.JsonClassDescription;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyDescription;
+
+import java.util.function.Function;
+
+/**
+ * Mock 3rd party weather service.
+ *
+ * @author Geng Rong
+ */
+public class MockWeatherService implements Function {
+
+ /**
+ * Weather Function request.
+ */
+ @JsonInclude(Include.NON_NULL)
+ @JsonClassDescription("Weather API request")
+ public record Request(@JsonProperty(required = true,
+ value = "location") @JsonPropertyDescription("The city and state e.g. San Francisco, CA") String location,
+ @JsonProperty(required = true, value = "lat") @JsonPropertyDescription("The city latitude") double lat,
+ @JsonProperty(required = true, value = "lon") @JsonPropertyDescription("The city longitude") double lon,
+ @JsonProperty(required = true, value = "unit") @JsonPropertyDescription("Temperature unit") Unit unit) {
+ }
+
+ /**
+ * Temperature units.
+ */
+ public enum Unit {
+
+ /**
+ * Celsius.
+ */
+ C("metric"),
+ /**
+ * Fahrenheit.
+ */
+ F("imperial");
+
+ /**
+ * Human readable unit name.
+ */
+ public final String unitName;
+
+ private Unit(String text) {
+ this.unitName = text;
+ }
+
+ }
+
+ /**
+ * Weather Function response.
+ */
+ public record Response(double temp, double feels_like, double temp_min, double temp_max, int pressure, int humidity,
+ Unit unit) {
+ }
+
+ @Override
+ public Response apply(Request request) {
+
+ double temperature = 0;
+ if (request.location().contains("Paris")) {
+ temperature = 15;
+ }
+ else if (request.location().contains("Tokyo")) {
+ temperature = 10;
+ }
+ else if (request.location().contains("San Francisco")) {
+ temperature = 30;
+ }
+
+ return new Response(temperature, 15, 20, 2, 53, 45, Unit.C);
+ }
+
+}
\ No newline at end of file
diff --git a/spring-ai-spring-boot-starters/spring-ai-starter-minimax/pom.xml b/spring-ai-spring-boot-starters/spring-ai-starter-minimax/pom.xml
new file mode 100644
index 00000000000..3004b42a9db
--- /dev/null
+++ b/spring-ai-spring-boot-starters/spring-ai-starter-minimax/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+
+ org.springframework.ai
+ spring-ai
+ 1.0.0-SNAPSHOT
+ ../../pom.xml
+
+ spring-ai-minimax-spring-boot-starter
+ jar
+ Spring AI Starter - MiniMax
+ Spring AI MiniMax Auto Configuration
+ https://github.com/spring-projects/spring-ai
+
+
+ https://github.com/spring-projects/spring-ai
+ git://github.com/spring-projects/spring-ai.git
+ git@github.com:spring-projects/spring-ai.git
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ org.springframework.ai
+ spring-ai-spring-boot-autoconfigure
+ ${project.parent.version}
+
+
+
+ org.springframework.ai
+ spring-ai-minimax
+ ${project.parent.version}
+
+
+
+