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
5 changes: 2 additions & 3 deletions examples/basic_modules/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@
# Scenario 7: Using LLMFactory with MiniMax (OpenAI-compatible API)
# Prerequisites:
# 1. Get your API key from the MiniMax platform.
# 2. Available models: MiniMax-M2.7 (flagship), MiniMax-M2.7-highspeed (low-latency),
# MiniMax-M2.5, MiniMax-M2.5-highspeed.
# 2. Available models: MiniMax-M3.1-Flash (default), MiniMax-M3.

cfg_mm = LLMConfigFactory.model_validate(
{
"backend": "minimax",
"config": {
"model_name_or_path": "MiniMax-M2.7",
"model_name_or_path": "MiniMax-M3.1-Flash",
"api_key": "your-minimax-api-key",
"api_base": "https://api.minimax.io/v1",
"temperature": 0.7,
Expand Down
2 changes: 1 addition & 1 deletion src/memos/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def qwen_config() -> dict[str, Any]:
def minimax_config() -> dict[str, Any]:
"""Get MiniMax configuration."""
return {
"model_name_or_path": os.getenv("MOS_CHAT_MODEL", "MiniMax-M2.7"),
"model_name_or_path": os.getenv("MOS_CHAT_MODEL", "MiniMax-M3.1-Flash"),
"temperature": float(os.getenv("MOS_CHAT_TEMPERATURE", "0.8")),
"max_tokens": int(os.getenv("MOS_MAX_TOKENS", "8000")),
"top_p": float(os.getenv("MOS_TOP_P", "0.9")),
Expand Down
157 changes: 157 additions & 0 deletions tests/llms/test_minimax_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""Exercise MiniMax configuration through the SDK's serialized HTTP requests."""

import json

import httpx
import pytest

from memos.api.config import APIConfig
from memos.configs.llm import MinimaxLLMConfig
from memos.llms.minimax import MinimaxLLM


@pytest.mark.parametrize("model", [None, "MiniMax-M3", "MiniMax-M2.7", "custom-model"])
@pytest.mark.parametrize(
"api_base",
["https://api.minimax.io/v1", "https://api.minimaxi.com/v1", "https://gateway.test/v1"],
)
@pytest.mark.parametrize("stream", [False, True])
def test_minimax_default_and_saved_requests(monkeypatch, model, api_base, stream):
monkeypatch.delenv("MOS_CHAT_MODEL", raising=False)
if model is not None:
monkeypatch.setenv("MOS_CHAT_MODEL", model)
monkeypatch.setenv("MINIMAX_API_KEY", "test-key")
monkeypatch.setenv("MINIMAX_API_BASE", api_base)
config = MinimaxLLMConfig.model_validate(APIConfig.minimax_config())
expected_model = model or "MiniMax-M3.1-Flash"
messages = [{"role": "user", "content": "Hello"}]
requests = []

def respond(request):
requests.append(request)
if stream:
chunk = {
"id": "test-completion",
"object": "chat.completion.chunk",
"created": 0,
"model": expected_model,
"choices": [{"index": 0, "delta": {"content": "Hello"}}],
}
return httpx.Response(
200,
headers={"content-type": "text/event-stream"},
text=f"data: {json.dumps(chunk)}\n\ndata: [DONE]\n\n",
)
return httpx.Response(
200,
json={
"id": "test-completion",
"object": "chat.completion",
"created": 0,
"model": expected_model,
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello"},
"finish_reason": "stop",
}
],
},
)

llm = MinimaxLLM(config)
llm.client.close()
with httpx.Client(transport=httpx.MockTransport(respond)) as transport:
llm.client = llm.client.with_options(http_client=transport)
output = "".join(llm.generate_stream(messages)) if stream else llm.generate(messages)
assert output == "Hello"
assert len(requests) == 1
request = requests[0]
assert str(request.url) == f"{api_base}/chat/completions"
body = json.loads(request.content)
assert body["model"] == expected_model
assert body["messages"] == messages
if stream:
assert body["stream"] is True
else:
assert "stream" not in body
assert "thinking" not in body
assert "enable_thinking" not in body
assert "reasoning_effort" not in body
assert "reasoning_split" not in body
assert "service_tier" not in body


@pytest.mark.parametrize(
("model", "extra_body"),
[
("MiniMax-M3.1-Flash", {"thinking": {"type": "adaptive"}, "reasoning_effort": "high"}),
("MiniMax-M3", {"thinking": {"type": "disabled"}}),
("MiniMax-M2.7", {"custom_option": True}),
],
)
def test_minimax_explicit_request_preserves_options_and_history(model, extra_body):
config = MinimaxLLMConfig.model_validate(
{"model_name_or_path": "saved-model", "api_key": "test-key", "extra_body": extra_body}
)
messages = [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://example.test/image.png"}}
],
},
{
"role": "assistant",
"content": None,
"reasoning_content": "Remember the image.",
"tool_calls": [
{
"id": "call-1",
"type": "function",
"function": {"name": "lookup", "arguments": "{}"},
}
],
},
{"role": "tool", "tool_call_id": "call-1", "content": "Found"},
]
tools = [
{
"type": "function",
"function": {"name": "lookup", "parameters": {"type": "object", "properties": {}}},
}
]
bodies = []

def respond(request):
bodies.append(json.loads(request.content))
return httpx.Response(
200,
json={
"id": "test-completion",
"object": "chat.completion",
"created": 0,
"model": model,
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Done"},
"finish_reason": "stop",
}
],
},
)

llm = MinimaxLLM(config)
llm.client.close()
with httpx.Client(transport=httpx.MockTransport(respond)) as transport:
llm.client = llm.client.with_options(http_client=transport)
assert llm.generate(messages, model_name_or_path=model, tools=tools) == "Done"
assert len(bodies) == 1
body = bodies[0]
assert body["model"] == model
assert body["messages"] == messages
assert body["tools"] == tools
for key, value in extra_body.items():
assert body[key] == value
assert config.model_name_or_path == "saved-model"
Loading