fix: route llm model syntax to litellm

* fix: route llm model syntax to litellm

* wip: add list of supported models
This commit is contained in:
Greyson LaLonde
2025-11-07 13:34:15 -05:00
committed by GitHub
parent d29867bbb6
commit 1ed307b58c
8 changed files with 802 additions and 23 deletions

View File

@@ -36,7 +36,7 @@ def test_anthropic_completion_is_used_when_claude_provider():
from crewai.llms.providers.anthropic.completion import AnthropicCompletion
assert isinstance(llm, AnthropicCompletion)
assert llm.provider == "claude"
assert llm.provider == "anthropic"
assert llm.model == "claude-3-5-sonnet-20241022"

View File

@@ -39,7 +39,7 @@ def test_azure_completion_is_used_when_azure_openai_provider():
from crewai.llms.providers.azure.completion import AzureCompletion
assert isinstance(llm, AzureCompletion)
assert llm.provider == "azure_openai"
assert llm.provider == "azure"
assert llm.model == "gpt-4"

View File

@@ -24,7 +24,7 @@ def test_gemini_completion_is_used_when_google_provider():
llm = LLM(model="google/gemini-2.0-flash-001")
assert llm.__class__.__name__ == "GeminiCompletion"
assert llm.provider == "google"
assert llm.provider == "gemini"
assert llm.model == "gemini-2.0-flash-001"

View File

@@ -154,7 +154,7 @@ class TestGeminiProviderInterceptor:
# Gemini provider should raise NotImplementedError
with pytest.raises(NotImplementedError) as exc_info:
LLM(
model="gemini/gemini-pro",
model="gemini/gemini-2.5-pro",
interceptor=interceptor,
api_key="test-gemini-key",
)
@@ -169,7 +169,7 @@ class TestGeminiProviderInterceptor:
with pytest.raises(NotImplementedError) as exc_info:
LLM(
model="gemini/gemini-pro",
model="gemini/gemini-2.5-pro",
interceptor=interceptor,
api_key="test-gemini-key",
)
@@ -181,7 +181,7 @@ class TestGeminiProviderInterceptor:
def test_gemini_without_interceptor_works(self) -> None:
"""Test that Gemini LLM works without interceptor."""
llm = LLM(
model="gemini/gemini-pro",
model="gemini/gemini-2.5-pro",
api_key="test-gemini-key",
)
@@ -231,7 +231,7 @@ class TestUnsupportedProviderMessages:
with pytest.raises(NotImplementedError) as exc_info:
LLM(
model="gemini/gemini-pro",
model="gemini/gemini-2.5-pro",
interceptor=interceptor,
api_key="test-gemini-key",
)
@@ -282,7 +282,7 @@ class TestProviderSupportMatrix:
# Gemini - NOT SUPPORTED
with pytest.raises(NotImplementedError):
LLM(
model="gemini/gemini-pro",
model="gemini/gemini-2.5-pro",
interceptor=interceptor,
api_key="test",
)
@@ -315,5 +315,5 @@ class TestProviderSupportMatrix:
assert not hasattr(bedrock_llm, 'interceptor') or bedrock_llm.interceptor is None
# Gemini - doesn't have interceptor attribute
gemini_llm = LLM(model="gemini/gemini-pro", api_key="test")
assert not hasattr(gemini_llm, 'interceptor') or gemini_llm.interceptor is None
gemini_llm = LLM(model="gemini/gemini-2.5-pro", api_key="test")
assert not hasattr(gemini_llm, 'interceptor') or gemini_llm.interceptor is None

View File

@@ -16,7 +16,7 @@ def test_openai_completion_is_used_when_openai_provider():
"""
Test that OpenAICompletion from completion.py is used when LLM uses provider 'openai'
"""
llm = LLM(model="openai/gpt-4o")
llm = LLM(model="gpt-4o")
assert llm.__class__.__name__ == "OpenAICompletion"
assert llm.provider == "openai"
@@ -70,7 +70,7 @@ def test_openai_completion_module_is_imported():
del sys.modules[module_name]
# Create LLM instance - this should trigger the import
LLM(model="openai/gpt-4o")
LLM(model="gpt-4o")
# Verify the module was imported
assert module_name in sys.modules
@@ -97,7 +97,7 @@ def test_native_openai_raises_error_when_initialization_fails():
# This should raise ImportError, not fall back to LiteLLM
with pytest.raises(ImportError) as excinfo:
LLM(model="openai/gpt-4o")
LLM(model="gpt-4o")
assert "Error importing native provider" in str(excinfo.value)
assert "Native SDK failed" in str(excinfo.value)
@@ -108,7 +108,7 @@ def test_openai_completion_initialization_parameters():
Test that OpenAICompletion is initialized with correct parameters
"""
llm = LLM(
model="openai/gpt-4o",
model="gpt-4o",
temperature=0.7,
max_tokens=1000,
api_key="test-key"
@@ -311,7 +311,7 @@ def test_openai_completion_call_returns_usage_metrics():
role="Research Assistant",
goal="Find information about the population of Tokyo",
backstory="You are a helpful research assistant.",
llm=LLM(model="openai/gpt-4o"),
llm=LLM(model="gpt-4o"),
verbose=True,
)
@@ -331,6 +331,7 @@ def test_openai_completion_call_returns_usage_metrics():
assert result.token_usage.cached_prompt_tokens == 0
@pytest.mark.skip(reason="Allow for litellm")
def test_openai_raises_error_when_model_not_supported():
"""Test that OpenAICompletion raises ValueError when model not supported"""
@@ -354,7 +355,7 @@ def test_openai_client_setup_with_extra_arguments():
Test that OpenAICompletion is initialized with correct parameters
"""
llm = LLM(
model="openai/gpt-4o",
model="gpt-4o",
temperature=0.7,
max_tokens=1000,
top_p=0.5,
@@ -391,7 +392,7 @@ def test_extra_arguments_are_passed_to_openai_completion():
"""
Test that extra arguments are passed to OpenAICompletion
"""
llm = LLM(model="openai/gpt-4o", temperature=0.7, max_tokens=1000, top_p=0.5, max_retries=3)
llm = LLM(model="gpt-4o", temperature=0.7, max_tokens=1000, top_p=0.5, max_retries=3)
with patch.object(llm.client.chat.completions, 'create') as mock_create:
mock_create.return_value = MagicMock(