From 48096044e005ad2329d3ddb987d506b4175a3d85 Mon Sep 17 00:00:00 2001 From: octo-patch <266937838+octo-patch@users.noreply.github.com> Date: Tue, 20 Oct 2026 20:26:36 +0800 Subject: [PATCH 1/2] fix: default MiniMax configurations to M3.1 Flash --- examples/basic_modules/llm.py | 5 +- src/memos/api/config.py | 2 +- tests/llms/test_minimax_requests.py | 153 ++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 tests/llms/test_minimax_requests.py diff --git a/examples/basic_modules/llm.py b/examples/basic_modules/llm.py index 7d05fb2de..ff3909461 100644 --- a/examples/basic_modules/llm.py +++ b/examples/basic_modules/llm.py @@ -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, diff --git a/src/memos/api/config.py b/src/memos/api/config.py index 0247dfa42..9e2cbd31c 100644 --- a/src/memos/api/config.py +++ b/src/memos/api/config.py @@ -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")), diff --git a/tests/llms/test_minimax_requests.py b/tests/llms/test_minimax_requests.py new file mode 100644 index 000000000..fb2a8d6f1 --- /dev/null +++ b/tests/llms/test_minimax_requests.py @@ -0,0 +1,153 @@ +"""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 + assert body.get("stream", False) is stream + 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" + 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" From 6d9d523e11d3772838470ada7b13814bd86c0e95 Mon Sep 17 00:00:00 2001 From: octo-patch <266937838+octo-patch@users.noreply.github.com> Date: Tue, 20 Oct 2026 20:31:19 +0800 Subject: [PATCH 2/2] test: clarify MiniMax request transport assertions --- tests/llms/test_minimax_requests.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/llms/test_minimax_requests.py b/tests/llms/test_minimax_requests.py index fb2a8d6f1..8b5700308 100644 --- a/tests/llms/test_minimax_requests.py +++ b/tests/llms/test_minimax_requests.py @@ -71,7 +71,10 @@ def respond(request): body = json.loads(request.content) assert body["model"] == expected_model assert body["messages"] == messages - assert body.get("stream", False) is stream + 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 @@ -144,6 +147,7 @@ def respond(request): 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