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
2 changes: 1 addition & 1 deletion docs/src/core_concepts/models_and_api_clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In language model programming, the relationship between models and API clients i
Model Registration and Default Clients
--------------------------------------

ell automatically registers numerous models from providers like OpenAI, Anthropic, Cohere, and Groq upon initialization. This allows you to use models without explicitly specifying a client.
ell automatically registers numerous models from providers like OpenAI, Anthropic, Cohere, Groq, and MiniMax upon initialization. This allows you to use models without explicitly specifying a client.

If no client is found for a model, ell falls back to a default OpenAI client. This enables the utilization of newly released models without updating ell for new model registrations. If the fallback fails because the model is not available in the OpenAI API, you can register your own client for the model using the `ell.config.register_model` method or specify a client when calling the language model program below

Expand Down
30 changes: 30 additions & 0 deletions examples/providers/minimax_ex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
MiniMax example: set MINIMAX_API_KEY in your environment to run this example.

MiniMax provides OpenAI-compatible API endpoints, so no extra package is needed
beyond the standard openai SDK that ell already depends on.
"""
import ell
import openai

ell.init(verbose=True)

# Option 1: Use auto-registered models (requires MINIMAX_API_KEY env var)
@ell.simple(model="MiniMax-M2.7")
def chat_minimax(prompt: str) -> str:
"""You are a helpful assistant."""
return prompt

print(chat_minimax("Tell me a fun fact about octopuses!"))


# Option 2: Use a custom client
minimax_client = openai.Client(
base_url="https://api.minimax.io/v1",
api_key="your_api_key_here",
)

@ell.simple(model="MiniMax-M2.5", client=minimax_client)
def chat_minimax_custom(prompt: str) -> str:
"""You are a helpful assistant."""
return prompt
4 changes: 2 additions & 2 deletions src/ell/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from ell.models import openai, anthropic, ollama, groq, bedrock, xai, google
from ell.models import openai, anthropic, ollama, groq, bedrock, xai, google, minimax

__all__ = ["openai", "anthropic", "ollama", "groq", "bedrock", "xai", "google"]
__all__ = ["openai", "anthropic", "ollama", "groq", "bedrock", "xai", "google", "minimax"]

75 changes: 75 additions & 0 deletions src/ell/models/minimax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
This module handles the registration of MiniMax models within the ell framework.

MiniMax provides OpenAI-compatible API endpoints, so models are registered
using the OpenAI client with the MiniMax base URL.

Key features:
1. Registration of MiniMax models (MiniMax-M2.7, MiniMax-M2.7-highspeed, MiniMax-M2.5, MiniMax-M2.5-highspeed).
2. Automatic client setup using the MINIMAX_API_KEY environment variable.

MiniMax API docs: https://www.minimaxi.com/document/introduction

Note: MiniMax models support OpenAI-compatible chat completions, streaming,
and tool/function calling.
"""

import os
from ell.configurator import config
import openai

import logging

logger = logging.getLogger(__name__)

MINIMAX_MODELS = [
"MiniMax-M2.7",
"MiniMax-M2.7-highspeed",
"MiniMax-M2.5",
"MiniMax-M2.5-highspeed",
]


def register(client: openai.Client = None, api_key: str = None):
"""
Register MiniMax models with the provided client.

Args:
client (openai.Client, optional): An OpenAI-compatible client configured
for MiniMax. If not provided, one will be created using the
MINIMAX_API_KEY environment variable.
api_key (str, optional): MiniMax API key. If not provided, the
MINIMAX_API_KEY environment variable is used.
"""
if client is None:
key = api_key or os.environ.get("MINIMAX_API_KEY")
if not key:
raise openai.OpenAIError(
"MINIMAX_API_KEY not found. Set the MINIMAX_API_KEY environment "
"variable or pass api_key to register()."
)
client = openai.Client(
base_url="https://api.minimax.io/v1",
api_key=key,
)
for model_id in MINIMAX_MODELS:
config.register_model(model_id, client)


default_client = None
try:
minimax_api_key = os.environ.get("MINIMAX_API_KEY")
if not minimax_api_key:
raise openai.OpenAIError(
"MINIMAX_API_KEY not found in environment variables"
)
default_client = openai.Client(
base_url="https://api.minimax.io/v1",
api_key=minimax_api_key,
)
except openai.OpenAIError:
pass

if default_client is not None:
for model_id in MINIMAX_MODELS:
config.register_model(model_id, default_client)
Loading