mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
"""Unit tests for Morph provider integration."""
|
|
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
|
|
import litellm
|
|
from litellm import MorphChatConfig, get_llm_provider
|
|
|
|
# Force model loading
|
|
litellm.add_known_models()
|
|
|
|
|
|
def test_morph_config_get_provider_info():
|
|
"""Test that MorphChatConfig returns correct provider info."""
|
|
config = MorphChatConfig()
|
|
|
|
# Test with environment variable
|
|
with patch.dict(os.environ, {"MORPH_API_KEY": "test-key-from-env"}):
|
|
api_base, api_key = config._get_openai_compatible_provider_info(None, None)
|
|
assert api_base == "https://api.morphllm.com/v1"
|
|
assert api_key == "test-key-from-env"
|
|
|
|
# Test with passed api_key
|
|
api_base, api_key = config._get_openai_compatible_provider_info(None, "direct-key")
|
|
assert api_base == "https://api.morphllm.com/v1"
|
|
assert api_key == "direct-key"
|
|
|
|
# Test with custom api_base
|
|
api_base, api_key = config._get_openai_compatible_provider_info(
|
|
"https://custom.morph.com", "key"
|
|
)
|
|
assert api_base == "https://custom.morph.com"
|
|
assert api_key == "key"
|
|
|
|
|
|
def test_morph_get_llm_provider():
|
|
"""Test that get_llm_provider correctly identifies morph models."""
|
|
# Test with morph/model format
|
|
_, custom_llm_provider, _, _ = get_llm_provider("morph/morph-v3-large")
|
|
assert custom_llm_provider == "morph"
|
|
|
|
_, custom_llm_provider, _, _ = get_llm_provider("morph/morph-v3-fast")
|
|
assert custom_llm_provider == "morph"
|
|
|
|
|
|
def test_morph_in_provider_lists():
|
|
"""Test that morph is included in all necessary provider lists."""
|
|
import litellm
|
|
from litellm.constants import (
|
|
openai_compatible_providers,
|
|
openai_compatible_endpoints,
|
|
)
|
|
|
|
# Check morph is in openai_compatible_providers
|
|
assert "morph" in openai_compatible_providers
|
|
|
|
# Check morph endpoint is in openai_compatible_endpoints
|
|
assert "https://api.morphllm.com/v1" in openai_compatible_endpoints
|
|
|
|
# Check morph is in provider_list
|
|
assert "morph" in litellm.provider_list
|
|
|
|
# Check models are in model_list after initialization
|
|
assert all(
|
|
model in litellm.model_list
|
|
for model in ["morph/morph-v3-large", "morph/morph-v3-fast"]
|
|
)
|
|
|
|
|
|
def test_morph_model_info():
|
|
"""Test that morph models have correct configuration."""
|
|
import litellm
|
|
|
|
model_info = litellm.get_model_info("morph/morph-v3-large")
|
|
|
|
assert model_info["litellm_provider"] == "morph"
|
|
assert model_info["mode"] == "chat"
|
|
assert model_info["max_tokens"] == 16000
|
|
assert model_info["max_input_tokens"] == 16000
|
|
assert model_info["max_output_tokens"] == 16000
|
|
assert model_info["input_cost_per_token"] == 9e-07 # $0.9/1M tokens
|
|
assert model_info["output_cost_per_token"] == 1.9e-06 # $1.9/1M tokens
|
|
assert model_info["supports_function_calling"] is False
|
|
assert model_info["supports_vision"] is False
|
|
assert model_info["supports_system_messages"] is True
|
|
|
|
|
|
def test_morph_supported_params():
|
|
"""Test that MorphChatConfig returns correct supported parameters."""
|
|
config = MorphChatConfig()
|
|
supported_params = config.get_supported_openai_params("morph/morph-v3-large")
|
|
|
|
expected_params = [
|
|
"messages",
|
|
"model",
|
|
"stream",
|
|
]
|
|
|
|
assert all(param in supported_params for param in expected_params)
|
|
|
|
|
|
def test_morph_custom_llm_provider():
|
|
"""Test that morph models are correctly identified."""
|
|
config = MorphChatConfig()
|
|
assert config.custom_llm_provider == "morph"
|