Skip to content

Add configurable MiniMax OpenAI-compatible provider - #13

Open
octo-patch wants to merge 1 commit into
CraftJarvis:mainfrom
octo-patch:octo/20260730-provider-add-recvqcvPSjEp1x
Open

Add configurable MiniMax OpenAI-compatible provider#13
octo-patch wants to merge 1 commit into
CraftJarvis:mainfrom
octo-patch:octo/20260730-provider-add-recvqcvPSjEp1x

Conversation

@octo-patch

@octo-patch octo-patch commented Jul 30, 2026

Copy link
Copy Markdown

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 new
    build_client() helper instead of the hardcoded OpenAI().
    • API key is read from MINIMAX_API_KEY (falling back to OPENAI_API_KEY).
    • The base URL is resolved by region via get_base_url(): global_en
      (https://api.minimax.io/v1, default) and cn_zh
      (https://api.minimaxi.com/v1). MINIMAX_BASE_URL overrides the region.
    • get_model() resolves the model id from MINIMAX_MODEL, defaulting to
      MiniMax-M3; MiniMax-M2.7 is also supported.
  • jarvis/assembly/core.py: replace the hardcoded gpt-3.5-turbo in
    chat.completions.create(...) and the JARVIS default with get_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.py

Summary by CodeRabbit

  • New Features

    • Added MiniMax API support with configurable regions, models, and endpoints.
    • Added environment variable options for API keys, model selection, region, and custom base URLs.
    • Custom endpoints take precedence over region-based configuration.
  • Documentation

    • Updated setup and usage instructions for MiniMax configuration.
  • Tests

    • Added coverage for default, regional, custom endpoint, and model configurations.

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.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

MiniMax provider integration

Layer / File(s) Summary
Provider configuration and resolution
jarvis/assembly/base.py, tests/test_minimax_provider.py, README.md
MiniMax endpoints, regions, models, credentials, and URL precedence are resolved from environment variables; the client is constructed with the resolved settings, and tests and usage instructions cover the configuration.
Dynamic model integration
jarvis/assembly/core.py
Chat completions and the JARVIS constructor use get_model() instead of a fixed GPT model identifier.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding configurable support for the MiniMax OpenAI-compatible provider.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
jarvis/assembly/core.py (1)

62-62: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for the request model.

The provider tests verify get_model(), but none exercise get_skill() and assert that MINIMAX_MODEL reaches client.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

📥 Commits

Reviewing files that changed from the base of the PR and between aa9bd97 and 805dfb7.

📒 Files selected for processing (4)
  • README.md
  • jarvis/assembly/base.py
  • jarvis/assembly/core.py
  • tests/test_minimax_provider.py

Comment thread jarvis/assembly/base.py
Comment on lines +42 to +54
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 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' || true

Repository: 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
fi

Repository: 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.

Suggested change
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.

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.

1 participant