fleet-memory/hindsight-api-slim/tests/test_minimax_provider.py
Nicolò Boschi 15ea23d5d6
feat: introduce hindsight-api-slim and hindsight-all-slim packages (#560)
* feat: introduce hindsight-api-slim and hindsight-all-slim packages

Closes #552

- Move all source code from hindsight-api/ to new hindsight-api-slim/
- hindsight-api-slim has heavy ML deps (torch, sentence-transformers,
  transformers, einops, flashrank, mlx, mlx-lm, safetensors) and
  pg0-embedded as optional extras: [local-ml], [embedded-db], [all]
- hindsight-api becomes a zero-code meta-package depending on
  hindsight-api-slim[all] for full backward compatibility
- Add hindsight-all-slim meta-package: hindsight-api-slim + client + embed
- hindsight-all updated to depend on hindsight-api-slim[all]
- pg0.py: lazy-import pg0 with clear ImportError pointing to [embedded-db]
- Dockerfile: replace sed hack with proper uv sync --extra flags
- Update release.yml, test.yml, lint.sh, release.sh, CLAUDE.md and
  all path references throughout the repo

* refactor: rename hindsight/ directory to hindsight-all/

* docs: document hindsight-api-slim and hindsight-all-slim package variants

Add package variants table and extras explanation to installation.md

* docs: remove emojis from installation.md, use professional tone

* docs: link Docker slim variant to pip package variants section

* docs: consolidate Docker image variants into single table

* ci: fix working-directory paths after package restructure

- Replace all hindsight-api → hindsight-api-slim in test.yml
- Replace hindsight → hindsight-all in test.yml
- Add --extra embedded-db to test-embed API install step

* ci: add local-ml and embedded-db extras to API sync steps

These extras were previously implicit in the old hindsight-api package
(which bundled everything). Now that hindsight-api-slim uses optional
extras, we must explicitly request local-ml and embedded-db in CI.

* ci: add API install step with embedded-db to test-embed smoke test

The smoke test starts hindsight-api as a daemon, which requires pg0-embedded.
Add a dedicated install step for hindsight-api-slim with embedded-db extra
so the daemon can start successfully.

* ci: remove --no-install-project when using optional extras

When --no-install-project is combined with --extra, the optional deps
are not installed because extras require the project to be active.
Remove --no-install-project from steps that need local-ml or embedded-db.

* ci: fix ordering of uv sync steps to preserve optional extras

When uv sync runs for a different workspace member, it removes optional
extras installed for other members. Fix by always running extra-requiring
API sync last, after other workspace member syncs.

Also remove --no-install-project from embedded-db sync in test-embed,
as --no-install-project prevents optional extras from being active.

* ci: add local-ml extra to test-embed API install for smoke test

The smoke test starts the full API server which needs sentence-transformers
for local embeddings (default provider). Add local-ml extra to the install.

* ci: simplify extras with --all-extras and add slim pip smoke test

- Replace explicit --extra local-ml --extra embedded-db with --all-extras
  for cleaner, more maintainable sync steps
- Add test-pip-slim job: tests hindsight-api-slim[embedded-db] without
  local ML models, using Cohere for embeddings/reranking (mirrors Docker
  slim smoke test approach)

* ci: simplify slim smoke test to health check only (mirrors Docker test)
2026-03-13 13:50:03 +01:00

200 lines
6 KiB
Python

"""Tests for MiniMax provider integration.
Validates that MiniMax is correctly registered as an OpenAI-compatible provider
with proper base URL, temperature clamping, and default model configuration.
"""
import os
import pytest
from hindsight_api.engine.llm_wrapper import LLMProvider, create_llm
def test_minimax_provider_creation():
"""Test that MiniMax provider can be instantiated correctly."""
llm = LLMProvider(
provider="minimax",
api_key="test-key",
base_url="",
model="MiniMax-M2.5",
)
assert llm.provider == "minimax"
assert llm.model == "MiniMax-M2.5"
assert llm.base_url == "https://api.minimax.io/v1"
def test_minimax_default_base_url():
"""Test that MiniMax uses the correct default base URL when none is provided."""
llm = LLMProvider(
provider="minimax",
api_key="test-key",
base_url="",
model="MiniMax-M2.5",
)
assert llm.base_url == "https://api.minimax.io/v1"
def test_minimax_custom_base_url():
"""Test that a custom base URL overrides the default."""
llm = LLMProvider(
provider="minimax",
api_key="test-key",
base_url="https://custom.api.example.com/v1",
model="MiniMax-M2.5",
)
assert llm.base_url == "https://custom.api.example.com/v1"
def test_minimax_factory_function():
"""Test that the create_llm factory function creates MiniMax provider correctly."""
llm = create_llm(
provider="minimax",
api_key="test-key",
base_url="",
model="MiniMax-M2.5",
)
assert llm is not None
def test_minimax_requires_api_key():
"""Test that MiniMax provider requires an API key."""
with pytest.raises(ValueError, match="API key"):
LLMProvider(
provider="minimax",
api_key="",
base_url="",
model="MiniMax-M2.5",
)
def test_minimax_default_model_config():
"""Test that MiniMax has a default model in PROVIDER_DEFAULT_MODELS."""
from hindsight_api.config import PROVIDER_DEFAULT_MODELS
assert "minimax" in PROVIDER_DEFAULT_MODELS
assert PROVIDER_DEFAULT_MODELS["minimax"] == "MiniMax-M2.5"
def test_minimax_config_default_model():
"""Test that MiniMax default model is used when model is not explicitly set."""
from hindsight_api.config import HindsightConfig, clear_config_cache
original_provider = os.environ.get("HINDSIGHT_API_LLM_PROVIDER")
original_model = os.environ.get("HINDSIGHT_API_LLM_MODEL")
try:
clear_config_cache()
os.environ["HINDSIGHT_API_LLM_PROVIDER"] = "minimax"
if "HINDSIGHT_API_LLM_MODEL" in os.environ:
del os.environ["HINDSIGHT_API_LLM_MODEL"]
config = HindsightConfig.from_env()
assert config.llm_provider == "minimax"
assert config.llm_model == "MiniMax-M2.5"
finally:
clear_config_cache()
if original_provider:
os.environ["HINDSIGHT_API_LLM_PROVIDER"] = original_provider
elif "HINDSIGHT_API_LLM_PROVIDER" in os.environ:
del os.environ["HINDSIGHT_API_LLM_PROVIDER"]
if original_model:
os.environ["HINDSIGHT_API_LLM_MODEL"] = original_model
elif "HINDSIGHT_API_LLM_MODEL" in os.environ:
del os.environ["HINDSIGHT_API_LLM_MODEL"]
def test_minimax_temperature_clamping():
"""Test that MiniMax temperature is clamped to (0.0, 1.0] range."""
from hindsight_api.engine.providers.openai_compatible_llm import OpenAICompatibleLLM
llm = OpenAICompatibleLLM(
provider="minimax",
api_key="test-key",
base_url="https://api.minimax.io/v1",
model="MiniMax-M2.5",
)
# Verify the provider is correctly set up for temperature clamping
assert llm.provider == "minimax"
@pytest.mark.asyncio
async def test_minimax_integration():
"""Integration test: verify MiniMax provider works with actual API.
Requires MINIMAX_API_KEY environment variable to be set.
"""
api_key = os.environ.get("MINIMAX_API_KEY")
if not api_key:
pytest.skip("MINIMAX_API_KEY not set")
llm = LLMProvider(
provider="minimax",
api_key=api_key,
base_url="",
model="MiniMax-M2.5",
)
# Test verify_connection
await llm.verify_connection()
# Test basic call
response = await llm.call(
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is 2+2? Answer in one word."},
],
max_completion_tokens=50,
)
assert response is not None
assert len(response) > 0
@pytest.mark.asyncio
async def test_minimax_tool_calling():
"""Integration test: verify MiniMax provider supports tool calling.
Requires MINIMAX_API_KEY environment variable to be set.
"""
api_key = os.environ.get("MINIMAX_API_KEY")
if not api_key:
pytest.skip("MINIMAX_API_KEY not set")
llm = LLMProvider(
provider="minimax",
api_key=api_key,
base_url="",
model="MiniMax-M2.5",
)
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
},
"required": ["location"],
},
},
}
]
result = await llm.call_with_tools(
messages=[
{"role": "system", "content": "You are a helpful assistant with access to tools."},
{"role": "user", "content": "What's the weather like in Paris?"},
],
tools=tools,
max_completion_tokens=500,
)
assert result is not None
assert hasattr(result, "tool_calls")
assert len(result.tool_calls) > 0
assert result.tool_calls[0].name == "get_weather"