Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/test_litellm_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import importlib.util
from pathlib import Path

import litellm
import pytest


MODULE_PATH = (
Path(__file__).parents[1] / "wdoc" / "utils" / "customs" / "litellm_models.py"
)
SPEC = importlib.util.spec_from_file_location("wdoc_litellm_models", MODULE_PATH)
assert SPEC is not None and SPEC.loader is not None
litellm_models = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(litellm_models)


def test_registers_minimax_models_with_current_metadata():
litellm_models.register_wdoc_models(litellm)

expected = {
"minimax/MiniMax-M3": {
"max_tokens": 1_000_000,
"input_cost_per_token": 0.6 / 1_000_000,
"output_cost_per_token": 2.4 / 1_000_000,
"cache_read_input_token_cost": 0.12 / 1_000_000,
"cache_creation_input_token_cost": None,
"input_modalities": ["text", "image", "video"],
"thinking": ["adaptive", "disabled"],
},
"minimax/MiniMax-M2.7": {
"max_tokens": 204_800,
"input_cost_per_token": 0.3 / 1_000_000,
"output_cost_per_token": 1.2 / 1_000_000,
"cache_read_input_token_cost": 0.06 / 1_000_000,
"cache_creation_input_token_cost": 0.375 / 1_000_000,
"input_modalities": ["text"],
"thinking": ["always_on"],
},
}

for model_id, metadata in expected.items():
assert model_id in litellm.models_by_provider["minimax"]
registered = litellm.model_cost[model_id]
assert registered["litellm_provider"] == "minimax"
assert registered["mode"] == "chat"
for key, value in metadata.items():
assert registered[key] == value


@pytest.mark.parametrize(
("region", "protocol", "expected"),
[
("global_en", "openai", "https://api.minimax.io/v1"),
("global_en", "anthropic", "https://api.minimax.io/anthropic"),
("cn_zh", "openai", "https://api.minimaxi.com/v1"),
("cn_zh", "anthropic", "https://api.minimaxi.com/anthropic"),
],
)
def test_minimax_endpoint_recipes(region, protocol, expected):
assert litellm_models.get_minimax_api_base(region, protocol) == expected


def test_minimax_endpoint_recipe_rejects_unknown_selection():
with pytest.raises(ValueError, match="Unsupported MiniMax endpoint selection"):
litellm_models.get_minimax_api_base("unknown", "openai")
68 changes: 68 additions & 0 deletions wdoc/utils/customs/litellm_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""wdoc-specific model metadata registered with LiteLLM."""

@thiswillbeyourgithub thiswillbeyourgithub Aug 1, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't see how this model is "wdoc-specific"


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'd prefer if the file was called add_extra_litellm_models_metadata.py to make it more explicit

from typing import Any, Literal


MINIMAX_PROVIDER = "minimax"

MINIMAX_ENDPOINTS = {
"global_en": {
"openai_base_url": "https://api.minimax.io/v1",
"anthropic_base_url": "https://api.minimax.io/anthropic",
},
"cn_zh": {
"openai_base_url": "https://api.minimaxi.com/v1",
"anthropic_base_url": "https://api.minimaxi.com/anthropic",
},
}

MINIMAX_MODELS = {
"minimax/MiniMax-M3": {
"litellm_provider": MINIMAX_PROVIDER,
"mode": "chat",
"max_tokens": 1_000_000,
"max_input_tokens": 1_000_000,
"input_cost_per_token": 0.6 / 1_000_000,
"output_cost_per_token": 2.4 / 1_000_000,
"cache_read_input_token_cost": 0.12 / 1_000_000,
"cache_creation_input_token_cost": None,
"input_modalities": ["text", "image", "video"],
"thinking": ["adaptive", "disabled"],
"supports_vision": True,
"supports_reasoning": True,
"supports_adaptive_thinking": True,
},
"minimax/MiniMax-M2.7": {
"litellm_provider": MINIMAX_PROVIDER,
"mode": "chat",
"max_tokens": 204_800,
"max_input_tokens": 204_800,
"input_cost_per_token": 0.3 / 1_000_000,
"output_cost_per_token": 1.2 / 1_000_000,
"cache_read_input_token_cost": 0.06 / 1_000_000,
"cache_creation_input_token_cost": 0.375 / 1_000_000,
"input_modalities": ["text"],
"thinking": ["always_on"],
"supports_reasoning": True,
},
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

To make it easier to maintain and detect stale values, please add as comments in the code the URLs you used to get those values.


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Have you considered making a PR to litellm directly too?


def get_minimax_api_base(
region: Literal["global_en", "cn_zh"],
protocol: Literal["openai", "anthropic"] = "openai",
) -> str:
"""Return the configured MiniMax base URL for a region and protocol."""
try:
return MINIMAX_ENDPOINTS[region][f"{protocol}_base_url"]
except KeyError as err:
raise ValueError(
f"Unsupported MiniMax endpoint selection: {region}/{protocol}"
) from err


def register_wdoc_models(litellm: Any) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'd prefer a more generic name for that func like add_extra_models_metadata

"""Register wdoc's model recipes in LiteLLM's cost and provider catalogs."""
litellm.register_model(MINIMAX_MODELS)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Before registering the model, maybe we should check in litellm's models metadata if there isn't already those values? Otherwise in the long run if/when litellm has those values we might have stale values.

provider_models = litellm.models_by_provider.setdefault(MINIMAX_PROVIDER, set())
provider_models.update(MINIMAX_MODELS)
3 changes: 3 additions & 0 deletions wdoc/wdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)

from wdoc.utils.batch_file_loader import batch_load_doc
from wdoc.utils.customs.litellm_models import register_wdoc_models
from wdoc.utils.env import env, is_out_piped
from wdoc.utils.errors import (
NoDocumentsAfterLLMEvalFiltering,
Expand Down Expand Up @@ -120,6 +121,8 @@ def __init__(
"""
import litellm

register_wdoc_models(litellm)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

By principle I think i'd prefer using a try block somewhere. Maybe make that func just a wrapper that applies a try block to a real _func. If the block fails log a warning with the error message or something


if version:
print(self.VERSION)
return
Expand Down