From 34faf609f42b3d133dcb31923e42f1ba8d07bfc1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:08:00 +0000 Subject: [PATCH] Fix: Remove models/ prefix causing LiteLLM provider recognition failure - Adds validation to prevent models/ prefix in model names - Adds tests for model name validation - Ensures correct model name format for LiteLLM provider recognition Co-Authored-By: Joe Moura --- src/crewai/llm.py | 7 +++++++ tests/llm_test.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/crewai/llm.py b/src/crewai/llm.py index ada5c9bf3..d62694f14 100644 --- a/src/crewai/llm.py +++ b/src/crewai/llm.py @@ -142,6 +142,13 @@ class LLM: reasoning_effort: Optional[Literal["none", "low", "medium", "high"]] = None, **kwargs, ): + # Validate model name + if isinstance(model, str) and model.startswith('models/'): + raise ValueError( + 'Model name should not start with "models/". ' + 'Use the provider prefix instead (e.g., "gemini/model-name").' + ) + self.model = model self.timeout = timeout self.temperature = temperature diff --git a/tests/llm_test.py b/tests/llm_test.py index 2e5faf774..876e98e0e 100644 --- a/tests/llm_test.py +++ b/tests/llm_test.py @@ -252,6 +252,17 @@ def test_validate_call_params_no_response_format(): llm._validate_call_params() +def test_model_name_validation(): + """Test that model names with 'models/' prefix are rejected.""" + with pytest.raises(ValueError, match="should not start with \"models/\""): + LLM(model="models/gemini/gemini-1.5-pro") + + # Valid model names should work + LLM(model="gemini/gemini-1.5-pro") + LLM(model="anthropic/claude-3-opus-20240229-v1:0") + LLM(model="openai/gpt-4") + + @pytest.mark.vcr(filter_headers=["authorization"]) def test_o3_mini_reasoning_effort_high(): llm = LLM(