-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(provider): add MiniMax regional support #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
octo-patch
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
octo-patch:octo/20260812-provider-add-recvs0kphjyPs8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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 | ||
| # | ||
| # http://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. | ||
|
|
||
| """MiniMax provider package.""" | ||
|
|
||
| from .provider import ( | ||
| MINIMAX_CN_BASE_URL, | ||
| MINIMAX_GLOBAL_BASE_URL, | ||
| REGISTRY_PATH, | ||
| MiniMaxProvider, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "MINIMAX_CN_BASE_URL", | ||
| "MINIMAX_GLOBAL_BASE_URL", | ||
| "REGISTRY_PATH", | ||
| "MiniMaxProvider", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Token-budget metadata for the MiniMax provider. | ||
| # | ||
| # Format: | ||
| # models: | ||
| # "<model-label>": | ||
| # context_length: <int> | ||
| # max_output_tokens: <int> # optional when no output cap is published | ||
|
|
||
| models: | ||
| "MiniMax-M3": | ||
| context_length: 1000000 | ||
| "MiniMax-M2.7": | ||
| context_length: 204800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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 | ||
| # | ||
| # http://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. | ||
|
|
||
| """MiniMax provider with global and China regional endpoint selection. | ||
|
|
||
| ``MINIMAX_REGION`` accepts ``global_en`` (the default) or ``cn_zh``. | ||
| ``MINIMAX_BASE_URL`` can override the selected regional endpoint. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from langchain_core.language_models.chat_models import BaseChatModel | ||
|
|
||
| from skillspector.providers import registry | ||
| from skillspector.providers.chat_models import create_openai_compatible_chat_model | ||
|
|
||
| MINIMAX_GLOBAL_BASE_URL = "https://api.minimax.io/v1" | ||
| MINIMAX_CN_BASE_URL = "https://api.minimaxi.com/v1" | ||
| MINIMAX_BASE_URLS = { | ||
| "global_en": MINIMAX_GLOBAL_BASE_URL, | ||
| "cn_zh": MINIMAX_CN_BASE_URL, | ||
| } | ||
|
|
||
| REGISTRY_PATH = str(Path(__file__).with_name("model_registry.yaml")) | ||
|
|
||
|
|
||
| def _resolve_base_url() -> str: | ||
| override = os.environ.get("MINIMAX_BASE_URL", "").strip() | ||
| if override: | ||
| return override | ||
|
|
||
| region = os.environ.get("MINIMAX_REGION", "").strip().lower() or "global_en" | ||
| try: | ||
| return MINIMAX_BASE_URLS[region] | ||
| except KeyError as exc: | ||
| raise ValueError("MINIMAX_REGION must be 'global_en' or 'cn_zh'") from exc | ||
|
|
||
|
|
||
| class MiniMaxProvider: | ||
| """MiniMax credentials, regional routing, and bundled model metadata.""" | ||
|
|
||
| DEFAULT_MODEL = "MiniMax-M3" | ||
| SLOT_DEFAULTS: dict[str, str] = {} | ||
|
|
||
| def resolve_credentials(self) -> tuple[str, str | None] | None: | ||
| """Return the MiniMax API key and selected regional base URL.""" | ||
| api_key = os.environ.get("MINIMAX_API_KEY", "").strip() | ||
| if not api_key: | ||
| return None | ||
| return api_key, _resolve_base_url() | ||
|
|
||
| def create_chat_model( | ||
| self, | ||
| model: str, | ||
| *, | ||
| max_tokens: int, | ||
| timeout: float | None = 120, | ||
| ) -> BaseChatModel | None: | ||
| """Create a chat model for the selected MiniMax endpoint.""" | ||
| return create_openai_compatible_chat_model( | ||
| model=model, | ||
| credentials=self.resolve_credentials(), | ||
| max_tokens=max_tokens, | ||
| timeout=timeout, | ||
| ) | ||
|
|
||
| def get_context_length(self, model: str) -> int | None: | ||
| return registry.lookup_context_length(REGISTRY_PATH, model) | ||
|
|
||
| def get_max_output_tokens(self, model: str) -> int | None: | ||
| return registry.lookup_max_output_tokens(REGISTRY_PATH, model) | ||
|
|
||
| def resolve_model(self, slot: str = "default") -> str: | ||
| """Resolve model from an environment override or the bundled default.""" | ||
| user_input = os.environ.get("SKILLSPECTOR_MODEL", "").strip() | ||
| return user_input or self.SLOT_DEFAULTS.get(slot, "") or self.DEFAULT_MODEL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # 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 | ||
| # | ||
| # http://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. | ||
|
|
||
| """Tests for the MiniMax provider.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from langchain_openai import ChatOpenAI | ||
|
|
||
| import skillspector.providers as providers_module | ||
| from skillspector.providers import get_metadata_provider, registry, resolve_provider_credentials | ||
| from skillspector.providers._agent_cli import _scrub_env | ||
| from skillspector.providers.minimax import ( | ||
| MINIMAX_CN_BASE_URL, | ||
| MINIMAX_GLOBAL_BASE_URL, | ||
| MiniMaxProvider, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _clean_provider_env(monkeypatch: pytest.MonkeyPatch): | ||
| for key in ( | ||
| "MINIMAX_API_KEY", | ||
| "MINIMAX_BASE_URL", | ||
| "MINIMAX_REGION", | ||
| "SKILLSPECTOR_MODEL", | ||
| "SKILLSPECTOR_MODEL_REGISTRY", | ||
| "SKILLSPECTOR_PROVIDER", | ||
| ): | ||
| monkeypatch.delenv(key, raising=False) | ||
| providers_module._INJECTED_PROVIDER.set(None) | ||
| registry._load.cache_clear() | ||
| yield | ||
| providers_module._INJECTED_PROVIDER.set(None) | ||
| registry._load.cache_clear() | ||
|
|
||
|
|
||
| class TestMiniMaxProvider: | ||
| def test_returns_none_without_api_key(self) -> None: | ||
| assert MiniMaxProvider().resolve_credentials() is None | ||
|
|
||
| def test_uses_global_endpoint_by_default(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| assert MiniMaxProvider().resolve_credentials() == ( | ||
| "test-key", | ||
| MINIMAX_GLOBAL_BASE_URL, | ||
| ) | ||
|
|
||
| def test_selects_china_endpoint(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| monkeypatch.setenv("MINIMAX_REGION", "cn_zh") | ||
| assert MiniMaxProvider().resolve_credentials() == ( | ||
| "test-key", | ||
| MINIMAX_CN_BASE_URL, | ||
| ) | ||
|
|
||
| def test_honors_base_url_override(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| monkeypatch.setenv("MINIMAX_BASE_URL", "https://minimax.example.com/v1") | ||
| assert MiniMaxProvider().resolve_credentials() == ( | ||
| "test-key", | ||
| "https://minimax.example.com/v1", | ||
| ) | ||
|
|
||
| def test_rejects_unknown_region(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| monkeypatch.setenv("MINIMAX_REGION", "unknown") | ||
| with pytest.raises(ValueError, match="global_en.*cn_zh"): | ||
| MiniMaxProvider().resolve_credentials() | ||
|
|
||
| def test_creates_chat_model(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| llm = MiniMaxProvider().create_chat_model("MiniMax-M3", max_tokens=123) | ||
| assert isinstance(llm, ChatOpenAI) | ||
| assert llm.model_name == "MiniMax-M3" | ||
| assert llm.max_tokens == 123 | ||
| assert str(llm.openai_api_base).rstrip("/") == MINIMAX_GLOBAL_BASE_URL | ||
|
|
||
| def test_bundled_models_and_context_windows(self) -> None: | ||
| provider = MiniMaxProvider() | ||
| assert provider.resolve_model() == "MiniMax-M3" | ||
| assert provider.get_context_length("MiniMax-M3") == 1_000_000 | ||
| assert provider.get_context_length("MiniMax-M2.7") == 204_800 | ||
| assert provider.get_max_output_tokens("MiniMax-M3") is None | ||
|
|
||
| def test_selector_uses_minimax_provider(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("SKILLSPECTOR_PROVIDER", "minimax") | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| assert resolve_provider_credentials() == ("test-key", MINIMAX_GLOBAL_BASE_URL) | ||
| assert isinstance(get_metadata_provider(), MiniMaxProvider) | ||
|
|
||
| def test_api_key_is_removed_from_cli_environment(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("MINIMAX_API_KEY", "test-key") | ||
| assert "MINIMAX_API_KEY" not in _scrub_env() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Official MiniMax API docs currently list
MiniMax-M2.7/MiniMax-M2.7-highspeedas the supported OpenAI-compatible model IDs, and the/v1/modelsexample does not includeMiniMax-M3; this default would make every out-of-box request fail. Use a served model with documented limits (or provide authoritative endpoint evidence plus a live contract test). Source: https://platform.minimax.io/docs/api-reference/api-overview