-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add MiniMax extraction backend #2208
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
3
commits into
Graphify-Labs:v8
Choose a base branch
from
octo-patch:octo/20260726-provider-add-recvp9DquT0oQo
base: v8
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.
+119
−16
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,22 @@ def _resolve_ollama_base_url(default: str) -> str: | |
| "temperature": None, # kimi-k2.6 enforces its own fixed temperature; sending any value raises 400 | ||
| "max_tokens": 16384, | ||
| }, | ||
| "minimax": { | ||
| # MINIMAX_BASE_URL selects the regional OpenAI-compatible endpoint. | ||
| "base_url": os.environ.get("MINIMAX_BASE_URL", "https://api.minimax.io/v1"), | ||
| "default_model": os.environ.get("MINIMAX_MODEL", "MiniMax-M3"), | ||
| "env_key": "MINIMAX_API_KEY", | ||
| "model_env_key": "GRAPHIFY_MINIMAX_MODEL", | ||
| "pricing": {"input": 0.60, "output": 2.40}, # USD per 1M tokens | ||
| "model_pricing": { | ||
| "MiniMax-M3": {"input": 0.60, "output": 2.40}, | ||
| "MiniMax-M2.7": {"input": 0.30, "output": 1.20}, | ||
| }, | ||
| "temperature": 0, | ||
| "max_tokens": 16384, | ||
| "vision": True, | ||
| "model_vision": {"MiniMax-M3": True, "MiniMax-M2.7": False}, | ||
| }, | ||
| "ollama": { | ||
| "base_url": _resolve_ollama_base_url("http://localhost:11434/v1"), | ||
| "default_model": os.environ.get("OLLAMA_MODEL", "qwen2.5-coder:7b"), | ||
|
|
@@ -840,7 +856,7 @@ def _strip_pixels(refs: list[_ImageRef]) -> list[_ImageRef]: | |
| return [replace(r, raw=None) for r in refs] | ||
|
|
||
|
|
||
| def _backend_supports_vision(backend: str) -> bool: | ||
| def _backend_supports_vision(backend: str, model: str | None = None) -> bool: | ||
| """Whether `backend`'s configured model can see images. | ||
|
|
||
| Ollama is special-cased: its default model is text-only, so vision is | ||
|
|
@@ -849,7 +865,13 @@ def _backend_supports_vision(backend: str) -> bool: | |
| """ | ||
| if backend == "ollama": | ||
| return os.environ.get("GRAPHIFY_OLLAMA_VISION", "").strip() == "1" | ||
| return bool(BACKENDS.get(backend, {}).get("vision", False)) | ||
| cfg = BACKENDS.get(backend, {}) | ||
| model_vision = cfg.get("model_vision", {}) | ||
| if model_vision: | ||
| model = model or _default_model_for_backend(backend) | ||
| if model in model_vision: | ||
| return bool(model_vision[model]) | ||
| return bool(cfg.get("vision", False)) | ||
|
|
||
|
|
||
| def _image_notes(refs: list[_ImageRef], *, with_paths: bool = False) -> str: | ||
|
|
@@ -1177,6 +1199,9 @@ def _call_openai_compat( | |
| # Kimi-k2.6 is a reasoning model — disable thinking so content isn't empty | ||
| elif "moonshot" in base_url: | ||
| kwargs["extra_body"] = {"thinking": {"type": "disabled"}} | ||
| # MiniMax-M2.7 always reasons, so the global opt-out must not disable it. | ||
| elif backend == "minimax" and model == "MiniMax-M2.7": | ||
| pass | ||
| # Opt-in only: disable thinking for reasoning models like deepseek-v4-flash | ||
| # (#1621). Not a default — see _thinking_disabled_via_env for the tradeoff. | ||
| elif _thinking_disabled_via_env(): | ||
|
|
@@ -1676,7 +1701,7 @@ def extract_files_direct( | |
| if backend is None: | ||
| raise ValueError( | ||
| "No LLM backend configured. Set one of: GEMINI_API_KEY, ANTHROPIC_API_KEY, " | ||
| "OPENAI_API_KEY, DEEPSEEK_API_KEY, MOONSHOT_API_KEY, " | ||
| "OPENAI_API_KEY, DEEPSEEK_API_KEY, MOONSHOT_API_KEY, MINIMAX_API_KEY, " | ||
| "AZURE_OPENAI_API_KEY+AZURE_OPENAI_ENDPOINT, OLLAMA_BASE_URL, " | ||
| "or AWS credentials. Pass backend= explicitly to select a provider." | ||
| ) | ||
|
|
@@ -1709,7 +1734,7 @@ def extract_files_direct( | |
| # (vision backends) or as a text reference node (everything else). | ||
| text_files, image_files = _partition_semantic_files(files) | ||
| user_msg = _read_files(text_files, root) | ||
| vision = _backend_supports_vision(backend) | ||
| vision = _backend_supports_vision(backend, mdl) | ||
| # Only base64 (inline) vision backends need the bytes loaded + size-capped; | ||
| # path-based backends (claude-cli) and non-vision backends do not. | ||
| read_bytes = vision and backend not in _PATH_IMAGE_BACKENDS | ||
|
|
@@ -2631,6 +2656,9 @@ def _rec(inp, out) -> None: | |
| kwargs["extra_body"] = cfg["extra_body"] | ||
| elif "moonshot" in cfg["base_url"]: | ||
| kwargs["extra_body"] = {"thinking": {"type": "disabled"}} | ||
| # MiniMax-M2.7 always reasons, so the global opt-out must not disable it. | ||
| elif backend == "minimax" and mdl == "MiniMax-M2.7": | ||
| pass | ||
| elif _thinking_disabled_via_env(): | ||
| kwargs["extra_body"] = {"thinking": {"type": "disabled"}} | ||
| resp = client.chat.completions.create(**kwargs) | ||
|
|
@@ -2642,11 +2670,19 @@ def _rec(inp, out) -> None: | |
| return resp.choices[0].message.content or "" | ||
|
|
||
|
|
||
| def estimate_cost(backend: str, input_tokens: int, output_tokens: int) -> float: | ||
| def estimate_cost( | ||
| backend: str, | ||
| input_tokens: int, | ||
| output_tokens: int, | ||
| model: str | None = None, | ||
| ) -> float: | ||
| """Estimate USD cost for a given token count using published pricing.""" | ||
| if backend not in BACKENDS: | ||
| return 0.0 | ||
| p = BACKENDS[backend]["pricing"] | ||
| cfg = BACKENDS[backend] | ||
| model_pricing = cfg.get("model_pricing", {}) | ||
| selected_model = model or _default_model_for_backend(backend) | ||
| p = model_pricing.get(selected_model, cfg["pricing"]) | ||
| return (input_tokens * p["input"] + output_tokens * p["output"]) / 1_000_000 | ||
|
|
||
|
|
||
|
|
@@ -2727,15 +2763,15 @@ def _validate_ollama_base_url(url: str, *, warn: bool = True) -> None: | |
| def detect_backend() -> str | None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
17 callers depend on it (afferent coupling). Grounded coupling-delta finding (deterministic), not an LLM guess. |
||
| """Return the name of whichever backend has an API key set, or None. | ||
|
|
||
| Priority: gemini → kimi → claude → openai → deepseek → azure → bedrock → ollama (last, opt-in). | ||
| Priority: gemini → kimi → minimax → claude → openai → deepseek → azure → bedrock → ollama (last, opt-in). | ||
|
|
||
| Ollama is intentionally checked LAST so a paid API key (Anthropic/OpenAI/etc.) | ||
| is never silently shadowed by an incidental OLLAMA_BASE_URL in the environment | ||
| — see security finding F-002/F-029. Setting OLLAMA_BASE_URL alongside a paid | ||
| key now keeps you on the paid backend; remove the paid key (or pass | ||
| --backend ollama explicitly) to route to the local model. | ||
| """ | ||
| for backend in ("gemini", "kimi", "claude", "openai", "deepseek"): | ||
| for backend in ("gemini", "kimi", "minimax", "claude", "openai", "deepseek"): | ||
| if _get_backend_api_key(backend): | ||
| return backend | ||
| if _get_backend_api_key("azure") and os.environ.get("AZURE_OPENAI_ENDPOINT"): | ||
|
|
@@ -2751,7 +2787,7 @@ def detect_backend() -> str | None: | |
| _validate_ollama_base_url(ollama_url) | ||
| return "ollama" | ||
| for name in BACKENDS: | ||
| if name not in ("gemini", "kimi", "claude", "openai", "deepseek", "azure", "bedrock", "ollama", "claude-cli"): | ||
| if name not in ("gemini", "kimi", "minimax", "claude", "openai", "deepseek", "azure", "bedrock", "ollama", "claude-cli"): | ||
| if _get_backend_api_key(name): | ||
| return name | ||
| return None | ||
|
|
||
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
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.
detect_backend()17 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.