Skip to content

feat: add MiniMax as first-class LLM provider#727

Open
octo-patch wants to merge 2 commits into
aws-samples:mainfrom
octo-patch:feature/add-minimax-provider
Open

feat: add MiniMax as first-class LLM provider#727
octo-patch wants to merge 2 commits into
aws-samples:mainfrom
octo-patch:feature/add-minimax-provider

Conversation

@octo-patch
Copy link
Copy Markdown

Summary

This PR adds MiniMax as a first-class third-party LLM provider, following the same adapter-registry pattern used by OpenAI and Azure OpenAI.

Supported models:

Model Context Description
MiniMax-M2.7 1M tokens Latest flagship model
MiniMax-M2.5 204K tokens Strong reasoning
MiniMax-M2.5-highspeed 204K tokens Faster variant

Key changes (11 files, 421 additions):

  • genai_core/types.py: Add MINIMAX to Provider enum
  • genai_core/clients.py: Add get_minimax_client() using OpenAI SDK with custom base URL
  • genai_core/model_providers/direct/provider.py: Add _list_minimax_models() for auto-discovery
  • adapters/minimax/minimax_chat.py: MinimaxChatAdapter extending ModelAdapter via ChatOpenAI with OpenAI-compatible API
  • adapters/__init__.py: Register minimax adapter module
  • docs/documentation/model-requirements.md: MiniMax setup documentation

How it works:

  • MiniMax uses an OpenAI-compatible API at https://api.minimax.io/v1
  • The adapter uses LangChain's ChatOpenAI with a custom openai_api_base
  • Temperature is clamped to [0, 1] per MiniMax API requirements
  • Models auto-appear in the UI when MINIMAX_API_KEY is added to Secrets Manager

Test plan

  • 11 unit tests for MinimaxChatAdapter (basic config, streaming, temperature clamping, max tokens, missing API key, all kwargs, model variants)
  • 3 integration tests for registry pattern matching and end-to-end adapter flow
  • 4 provider tests for _list_minimax_models() (with/without API key, model names, enum)
  • Existing tests pass without regressions (10/10 existing adapter + provider tests)

To enable: Add "MINIMAX_API_KEY": "your-key" to the Secrets Manager secret (same process as OpenAI/Cohere keys).

Add MiniMax AI as a third-party LLM provider alongside OpenAI and
Azure OpenAI. MiniMax provides an OpenAI-compatible API, enabling
integration via LangChain's ChatOpenAI with a custom base URL.

Supported models:
- MiniMax-M2.7 (flagship, 1M context)
- MiniMax-M2.5 (204K context)
- MiniMax-M2.5-highspeed (204K context, faster)

Changes:
- Add MINIMAX provider enum value
- Add get_minimax_client() to clients module
- Add _list_minimax_models() for auto-discovery when API key is set
- Add MinimaxChatAdapter with temperature clamping [0,1]
- Register adapter with registry pattern "^minimax*"
- Update model-requirements docs with MiniMax setup instructions
- Add 18 tests (11 unit + 3 integration + 4 provider tests)

To enable: add MINIMAX_API_KEY to the Secrets Manager secret.
Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern r"^minimax*" in minimax_chat.py (registry line) has a subtle but critical bug: the * is a quantifier on the preceding character x (meaning "zero or more x's"), not a glob wildcard. This means the pattern matches strings like "minima", "minimax", "minimaxxx" — but more importantly, since the registered model IDs are "MiniMax-M2.7", "MiniMax-M2.5", etc. (capital M), a case-sensitive match against ^minimax will fail entirely and none of these models will ever be routed to MinimaxChatAdapter. The pattern should be r"^MiniMax" or r"(?i)^minimax" with re.IGNORECASE.

Additionally, get_minimax_client() in clients.py is added but never referenced anywhere in the visible diff — the adapter in minimax_chat.py reads os.environ.get("MINIMAX_API_KEY") directly rather than going through genai_core.parameters.get_external_api_key(). This inconsistency means the two code paths behave differently depending on how the key is stored, and the new client function appears to be dead code.

Finally, the _MINIMAX_MODELS list in provider.py includes a "description" field for each model, but the dict comprehension in _list_minimax_models() never includes "description" in the returned model dict — the field is defined and documented but silently dropped.

Change `r"^minimax*"` to `r"^minimax.*"` — the bare `*` was a quantifier
on the preceding character `x` (zero or more x's), not a glob-style
wildcard.  With `.*` the pattern now correctly matches "minimax" followed
by any characters (e.g. "minimax.MiniMax-M2.7").
@octo-patch
Copy link
Copy Markdown
Author

Good catch @JiwaniZakir! Fixed the regex pattern from r"^minimax*" to r"^minimax.*" — the * was incorrectly quantifying the x character instead of acting as a wildcard. Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants