Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/semantic_kernel/connectors/ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All base clients inherit from the [`AIServiceClientBase`](../../services/ai_serv
| | [`GoogleAITextEmbedding`](./google/google_ai/services/google_ai_text_embedding.py) |
| HuggingFace | [`HuggingFaceTextCompletion`](./hugging_face/services/hf_text_completion.py) |
| | [`HuggingFaceTextEmbedding`](./hugging_face/services/hf_text_embedding.py) |
| [MiniMax](./minimax/README.md) | [`MiniMaxChatCompletion`](./minimax/services/minimax_chat_completion.py) |
| Mistral AI | [`MistralAIChatCompletion`](./mistral_ai/services/mistral_ai_chat_completion.py) |
| | [`MistralAITextEmbedding`](./mistral_ai/services/mistral_ai_text_embedding.py) |
| [Nvidia](./nvidia/README.md) | [`NvidiaTextEmbedding`](./nvidia/services/nvidia_text_embedding.py) |
Expand Down
67 changes: 67 additions & 0 deletions python/semantic_kernel/connectors/ai/minimax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# semantic_kernel.connectors.ai.minimax

This connector enables integration with the MiniMax API for chat completion. MiniMax provides an
OpenAI-compatible chat completion endpoint, so this connector reuses the OpenAI Python client.

## Regional endpoints

MiniMax exposes two regional OpenAI-compatible endpoints. Select the region through
`MiniMaxSettings` (or the `MINIMAX_REGION` environment variable); the base URL is resolved
automatically when `base_url` is not set explicitly.

| Region | OpenAI-compatible endpoint |
|-------------|-----------------------------------|
| `global_en` | `https://api.minimax.io/v1` |
| `cn_zh` | `https://api.minimaxi.com/v1` |

## Available models

- `MiniMax-M3` - Latest flagship model with a 1,000,000 token context window and text/image/video
input support (default).
Comment on lines +19 to +20
- `MiniMax-M2.7` - Previous generation flagship model with a 204,800 token context window.

## Quick start

### Initialize the kernel
```python
import semantic_kernel as sk
kernel = sk.Kernel()
```

### Add the MiniMax chat completion service
Provide your API key directly or through environment variables.
```python
from semantic_kernel.connectors.ai.minimax import MiniMaxChatCompletion

chat_service = MiniMaxChatCompletion(
ai_model_id="MiniMax-M3", # Defaults to MiniMax-M3
api_key="...", # Can also use MINIMAX_API_KEY env variable
service_id="minimax-chat",
)
kernel.add_service(chat_service)
```

### Target the China region
```python
from semantic_kernel.connectors.ai.minimax import MiniMaxChatCompletion

chat_service = MiniMaxChatCompletion(ai_model_id="MiniMax-M3", region="cn_zh")
```

### Basic chat completion
```python
response = await kernel.invoke_prompt("Hello, how are you?")
```

## Environment variables

| Variable | Description |
|------------------------|--------------------------------------------------------------------------|
| `MINIMAX_API_KEY` | Your MiniMax API key |
| `MINIMAX_REGION` | `global_en` (default) or `cn_zh` |
| `MINIMAX_BASE_URL` | API endpoint; resolved from the region when not provided |
| `MINIMAX_CHAT_MODEL_ID`| Default chat model ID |

## Notes

- The MiniMax API accepts `temperature` in the range `[0.0, 1.0]`.
15 changes: 15 additions & 0 deletions python/semantic_kernel/connectors/ai/minimax/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Microsoft. All rights reserved.

from semantic_kernel.connectors.ai.minimax.prompt_execution_settings.minimax_prompt_execution_settings import (
MiniMaxChatPromptExecutionSettings,
MiniMaxPromptExecutionSettings,
)
from semantic_kernel.connectors.ai.minimax.services.minimax_chat_completion import MiniMaxChatCompletion
from semantic_kernel.connectors.ai.minimax.settings.minimax_settings import MiniMaxSettings

__all__ = [
"MiniMaxChatCompletion",
"MiniMaxChatPromptExecutionSettings",
"MiniMaxPromptExecutionSettings",
"MiniMaxSettings",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) Microsoft. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) Microsoft. All rights reserved.

from typing import Annotated, Any, Literal

from pydantic import BaseModel, Field

from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings


class MiniMaxPromptExecutionSettings(PromptExecutionSettings):
"""Settings for MiniMax prompt execution."""

format: Literal["json"] | None = None
options: dict[str, Any] | None = None


class MiniMaxChatPromptExecutionSettings(MiniMaxPromptExecutionSettings):
"""Settings for MiniMax chat prompt execution.

MiniMax accepts temperature in the range [0.0, 1.0].
"""

messages: list[dict[str, str]] | None = None
ai_model_id: Annotated[str | None, Field(serialization_alias="model")] = None
temperature: Annotated[float | None, Field(ge=0.0, le=1.0)] = None
top_p: float | None = None
n: int | None = None
stream: bool = False
stop: str | list[str] | None = None
max_tokens: int | None = None
presence_penalty: float | None = None
frequency_penalty: float | None = None
logit_bias: dict[str, float] | None = None
user: str | None = None
tools: list[dict[str, Any]] | None = None
tool_choice: str | dict[str, Any] | None = None
response_format: (
dict[Literal["type"], Literal["text", "json_object"]] | dict[str, Any] | type[BaseModel] | type | None
) = None
seed: int | None = None
extra_headers: dict | None = None
extra_body: dict | None = None
timeout: float | None = None

def prepare_settings_dict(self, **kwargs) -> dict[str, Any]:
"""Prepare the settings as a dictionary for the API request."""
return self.model_dump(
exclude={"service_id", "extension_data", "structured_json_response", "response_format"},
exclude_none=True,
by_alias=True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) Microsoft. All rights reserved.
Loading
Loading