Skip to content

Commit f91760e

Browse files
octo-patchPR Botmzr1996
authored
[Feature] add MiniMax as text LLM API provider (#1491)
* feat: add MiniMax as text LLM API provider Add MiniMax (https://platform.minimaxi.com) as a text-based LLM provider for evaluation, supporting MiniMax-M2.7, MiniMax-M2.5, and MiniMax-M2.5-highspeed models via OpenAI-compatible chat completions API. Changes: - New vlmeval/api/minimax_api.py: MiniMaxAPI class extending BaseAPI - Register MiniMaxAPI and 3 model configs in vlmeval/config.py - Add MINIMAX_API_KEY to EN/CN quickstart docs - Add 34 unit tests + 3 integration tests * Delete tests/test_minimax_api.py --------- Co-authored-by: PR Bot <pr-bot@minimaxi.com> Co-authored-by: Ma Zerun <mzr1996@163.com>
1 parent 7d6d81f commit f91760e

5 files changed

Lines changed: 151 additions & 1 deletion

File tree

docs/en/Quickstart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ To infer with API models (GPT-4v, Gemini-Pro-V, etc.) or use LLM APIs as the **j
4545
HUNYUAN_SECRET_ID=
4646
# LMDeploy API
4747
LMDEPLOY_API_BASE=
48+
# MiniMax API
49+
MINIMAX_API_KEY=
4850
# You can also set a proxy for calling api models during the evaluation stage
4951
EVAL_PROXY=
5052
```

docs/zh-CN/Quickstart.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pip install -e .
4444
HUNYUAN_SECRET_ID=
4545
# LMDeploy API
4646
LMDEPLOY_API_BASE=
47+
# MiniMax API
48+
MINIMAX_API_KEY=
4749
# 你可以设置一个评估时代理,评估阶段产生的 API 调用将通过这个代理进行
4850
EVAL_PROXY=
4951
```

vlmeval/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .together import TogetherAPI
3131
from .gcp_vertex import GCPVertexAPI
3232
from .bedrock import BedrockAPI
33+
from .minimax_api import MiniMaxAPI
3334

3435
__all__ = [
3536
'OpenAIWrapper', 'HFChatModel', 'GeminiWrapper', 'GPT4V', 'Gemini', 'QwenVLWrapper',
@@ -40,5 +41,5 @@
4041
'TaichuVLAPI', 'TaichuVLRAPI', 'DoubaoVL', "MUGUAPI", 'KimiVLAPIWrapper', 'KimiVLAPI',
4142
'RBdashMMChat3_API', 'RBdashChat3_5_API', 'RBdashMMChat3_78B_API', 'RBdashMMChat3_5_38B_API',
4243
'VideoChatOnlineV2API', 'TeleMM2_API', 'TeleMM2Thinking_API', 'TogetherAPI', 'GCPVertexAPI',
43-
'BedrockAPI', 'SenseChatVisionV2API'
44+
'BedrockAPI', 'SenseChatVisionV2API', 'MiniMaxAPI',
4445
]

vlmeval/api/minimax_api.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
MiniMax API support for text-based LLM evaluation.
3+
OpenAI-compatible chat completions endpoint.
4+
Set MINIMAX_API_KEY or pass key=...
5+
6+
Models: MiniMax-M2.7, MiniMax-M2.5, MiniMax-M2.5-highspeed
7+
API docs: https://platform.minimaxi.com/document/guides/chat-model/text-generation
8+
"""
9+
import json
10+
import os
11+
12+
import requests
13+
14+
from ..smp import get_logger
15+
from .base import BaseAPI
16+
17+
MINIMAX_API_BASE = "https://api.minimax.io/v1/chat/completions"
18+
19+
20+
class MiniMaxAPI(BaseAPI):
21+
"""Text LLM API using MiniMax (OpenAI-compatible)."""
22+
23+
is_api: bool = True
24+
25+
def __init__(
26+
self,
27+
model: str = "MiniMax-M2.7",
28+
key: str = None,
29+
api_base: str = None,
30+
retry: int = 10,
31+
wait: int = 1,
32+
system_prompt: str = None,
33+
verbose: bool = True,
34+
temperature: float = 0,
35+
max_tokens: int = 2048,
36+
timeout: int = 300,
37+
**kwargs,
38+
):
39+
self.model = model
40+
self.key = key or os.environ.get("MINIMAX_API_KEY")
41+
self.api_base = api_base or os.environ.get("MINIMAX_API_BASE", MINIMAX_API_BASE)
42+
self.temperature = temperature
43+
self.max_tokens = max_tokens
44+
self.timeout = timeout
45+
46+
if not self.key:
47+
raise ValueError(
48+
"MiniMax API key is required. Set MINIMAX_API_KEY or pass key=..."
49+
)
50+
51+
super().__init__(
52+
retry=retry,
53+
wait=wait,
54+
system_prompt=system_prompt,
55+
verbose=verbose,
56+
**kwargs,
57+
)
58+
59+
self.logger.info(f"MiniMaxAPI: model={self.model}, api_base={self.api_base}")
60+
61+
def _prepare_messages(self, inputs):
62+
"""Build OpenAI-style messages from VLMEvalKit input format."""
63+
messages = []
64+
if self.system_prompt:
65+
messages.append({"role": "system", "content": self.system_prompt})
66+
67+
# Handle multi-turn chat format
68+
if inputs and isinstance(inputs[0], dict) and "role" in inputs[0]:
69+
for item in inputs:
70+
content_parts = item.get("content", [])
71+
text = "\n".join(
72+
x["value"] for x in content_parts if x["type"] == "text"
73+
)
74+
messages.append({"role": item["role"], "content": text or ""})
75+
else:
76+
# Single-turn: extract text from inputs
77+
text = "\n".join(
78+
x["value"] for x in inputs if x["type"] == "text"
79+
)
80+
messages.append({"role": "user", "content": text or ""})
81+
82+
return messages
83+
84+
def generate_inner(self, inputs, **kwargs):
85+
temperature = kwargs.pop("temperature", self.temperature)
86+
max_tokens = kwargs.pop("max_tokens", self.max_tokens)
87+
88+
messages = self._prepare_messages(inputs)
89+
payload = {
90+
"model": self.model,
91+
"messages": messages,
92+
"temperature": temperature,
93+
"max_tokens": max_tokens,
94+
}
95+
96+
try:
97+
response = requests.post(
98+
self.api_base,
99+
headers={
100+
"Authorization": f"Bearer {self.key}",
101+
"Content-Type": "application/json",
102+
},
103+
data=json.dumps(payload),
104+
timeout=self.timeout * 1.1,
105+
)
106+
except Exception as err:
107+
if self.verbose:
108+
self.logger.error(f"{type(err).__name__}: {err}")
109+
return -1, self.fail_msg, str(err)
110+
111+
ret_code = response.status_code
112+
ret_code = 0 if (200 <= ret_code < 300) else ret_code
113+
answer = self.fail_msg
114+
115+
try:
116+
data = response.json()
117+
answer = data["choices"][0]["message"]["content"].strip()
118+
except Exception as err:
119+
if self.verbose:
120+
self.logger.error(f"{type(err).__name__}: {err}")
121+
self.logger.error(response.text)
122+
123+
return ret_code, answer, response

vlmeval/config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,28 @@
465465
max_tokens=2048,
466466
retry=10,
467467
),
468+
# MiniMax (set MINIMAX_API_KEY)
469+
"MiniMax-M2.7": partial(
470+
MiniMaxAPI,
471+
model="MiniMax-M2.7",
472+
temperature=0,
473+
max_tokens=2048,
474+
retry=10,
475+
),
476+
"MiniMax-M2.5": partial(
477+
MiniMaxAPI,
478+
model="MiniMax-M2.5",
479+
temperature=0,
480+
max_tokens=2048,
481+
retry=10,
482+
),
483+
"MiniMax-M2.5-highspeed": partial(
484+
MiniMaxAPI,
485+
model="MiniMax-M2.5-highspeed",
486+
temperature=0,
487+
max_tokens=2048,
488+
retry=10,
489+
),
468490
# Claude
469491
"Claude3V_Opus": partial(
470492
Claude3V, model="claude-3-opus-20240229", temperature=0, retry=10, verbose=False

0 commit comments

Comments
 (0)