Add configurable MiniMax OpenAI-compatible provider - #13
Conversation
Replace the hardcoded OpenAI client and gpt-3.5-turbo model with region-aware MiniMax configuration via MINIMAX_API_KEY, MINIMAX_REGION, MINIMAX_BASE_URL, and MINIMAX_MODEL, defaulting to MiniMax-M3 on the global endpoint.
📝 WalkthroughWalkthroughThe client now uses MiniMax-compatible environment configuration for API credentials, endpoint selection, and model selection. JARVIS resolves the configured model dynamically, while documentation and tests cover defaults, regional endpoints, URL overrides, and model customization. ChangesMiniMax provider integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Environment
participant JARVIS
participant base
participant MiniMaxAPI
Environment->>base: Configure API key, endpoint, and model
JARVIS->>base: Call get_model()
JARVIS->>MiniMaxAPI: Submit chat completion with resolved model
base->>MiniMaxAPI: Provide configured OpenAI-compatible client
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
jarvis/assembly/core.py (1)
62-62: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a regression test for the request model.
The provider tests verify
get_model(), but none exerciseget_skill()and assert thatMINIMAX_MODELreachesclient.chat.completions.create. Mock the client and verify the configured model is passed instead of a hardcoded value.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@jarvis/assembly/core.py` at line 62, Add a regression test alongside the provider tests that exercises get_skill() and mocks the client’s chat.completions.create call. Assert that the configured MINIMAX_MODEL value is passed as the model argument, ensuring the request does not use a hardcoded model.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@jarvis/assembly/base.py`:
- Around line 42-54: Update build_client to require MINIMAX_API_KEY whenever
get_base_url() targets the MiniMax endpoint; remove the unconditional
OPENAI_API_KEY fallback or gate it behind an explicit provider selection,
ensuring MiniMax requests cannot use an OpenAI credential.
---
Nitpick comments:
In `@jarvis/assembly/core.py`:
- Line 62: Add a regression test alongside the provider tests that exercises
get_skill() and mocks the client’s chat.completions.create call. Assert that the
configured MINIMAX_MODEL value is passed as the model argument, ensuring the
request does not use a hardcoded model.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d5479fe7-ae68-44e6-8bc7-dbbe2fe93b6b
📒 Files selected for processing (4)
README.mdjarvis/assembly/base.pyjarvis/assembly/core.pytests/test_minimax_provider.py
| def build_client(): | ||
| """Create an OpenAI-compatible client pointed at the MiniMax API. | ||
|
|
||
| The API key is read from ``MINIMAX_API_KEY`` and falls back to | ||
| ``OPENAI_API_KEY`` for backward compatibility. | ||
| """ | ||
| return OpenAI( | ||
| api_key=os.environ.get("MINIMAX_API_KEY") or os.environ.get("OPENAI_API_KEY"), | ||
| base_url=get_base_url(), | ||
| ) | ||
|
|
||
|
|
||
| client = build_client() |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | rg '(^|/)base\.py$|jarvis/assembly|requirements|pyproject|poetry|setup|environment|env' || true
echo "== target file =="
if [ -f jarvis/assembly/base.py ]; then
nl -ba jarvis/assembly/base.py | sed -n '1,120p'
fi
echo "== search env/client usage =="
rg -n 'MINIMAX_API_KEY|OPENAI_API_KEY|build_client|base_url\s*=|OpenAI|openai' -S . --glob '!__pycache__/**' --glob '!*.pyc' || trueRepository: CraftJarvis/JARVIS-1
Length of output: 3358
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target file =="
cat -n jarvis/assembly/base.py | sed -n '1,140p'
echo "== relevant usage =="
rg -n 'MINIMAX_API_KEY|OPENAI_API_KEY|build_client\(|from jarvis\.assembly\.base import|import jarvis\.assembly\.base|OpenAI\(' -S . --glob '!__pycache__/**' --glob '!*.pyc' || true
echo "== pyproject deps =="
if [ -f pyproject.toml ]; then
rg -n 'openai|minimax|python' pyproject.toml -C 3 || true
fiRepository: CraftJarvis/JARVIS-1
Length of output: 5332
Require MINIMAX_API_KEY for MiniMax requests.
get_base_url() always resolves a MiniMax base_url, but build_client() falls back to OPENAI_API_KEY when MINIMAX_API_KEY is missing. If OPENAI_API_KEY is set, the client can send that OpenAI credential to the MiniMax endpoint; require MINIMAX_API_KEY or gate the fallback behind an explicit provider selection.
Proposed fix
def build_client():
+ api_key = os.environ.get("MINIMAX_API_KEY")
+ if not api_key:
+ raise RuntimeError("MINIMAX_API_KEY is required")
return OpenAI(
- api_key=os.environ.get("MINIMAX_API_KEY") or os.environ.get("OPENAI_API_KEY"),
+ api_key=api_key,
base_url=get_base_url(),
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def build_client(): | |
| """Create an OpenAI-compatible client pointed at the MiniMax API. | |
| The API key is read from ``MINIMAX_API_KEY`` and falls back to | |
| ``OPENAI_API_KEY`` for backward compatibility. | |
| """ | |
| return OpenAI( | |
| api_key=os.environ.get("MINIMAX_API_KEY") or os.environ.get("OPENAI_API_KEY"), | |
| base_url=get_base_url(), | |
| ) | |
| client = build_client() | |
| def build_client(): | |
| """Create an OpenAI-compatible client pointed at the MiniMax API. | |
| The API key is read from ``MINIMAX_API_KEY`` and falls back to | |
| ``OPENAI_API_KEY`` for backward compatibility. | |
| """ | |
| api_key = os.environ.get("MINIMAX_API_KEY") | |
| if not api_key: | |
| raise RuntimeError("MINIMAX_API_KEY is required") | |
| return OpenAI( | |
| api_key=api_key, | |
| base_url=get_base_url(), | |
| ) | |
| client = build_client() |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@jarvis/assembly/base.py` around lines 42 - 54, Update build_client to require
MINIMAX_API_KEY whenever get_base_url() targets the MiniMax endpoint; remove the
unconditional OPENAI_API_KEY fallback or gate it behind an explicit provider
selection, ensuring MiniMax requests cannot use an OpenAI credential.
Reason: The OpenAI client and chat model were hardcoded, so the MiniMax OpenAI-compatible API could not be configured.
What changed
jarvis/assembly/base.py: build the OpenAI-compatible client through a newbuild_client()helper instead of the hardcodedOpenAI().MINIMAX_API_KEY(falling back toOPENAI_API_KEY).get_base_url():global_en(
https://api.minimax.io/v1, default) andcn_zh(
https://api.minimaxi.com/v1).MINIMAX_BASE_URLoverrides the region.get_model()resolves the model id fromMINIMAX_MODEL, defaulting toMiniMax-M3;MiniMax-M2.7is also supported.jarvis/assembly/core.py: replace the hardcodedgpt-3.5-turboinchat.completions.create(...)and theJARVISdefault withget_model().README.md: document the new environment variables.tests/test_minimax_provider.py: unit tests for region/base-URL resolution,model selection, and the configured client.
Checks
python -m pytest tests/test_minimax_provider.py(6 passed)python -m py_compile jarvis/assembly/base.py jarvis/assembly/core.py tests/test_minimax_provider.pySummary by CodeRabbit
New Features
Documentation
Tests