Fix #2645: Remove 'models/' prefix from LLM model names

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-19 20:20:46 +00:00
parent 409892d65f
commit 819bd0b3b2
2 changed files with 53 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
import pytest
from unittest.mock import MagicMock, patch
from crewai import Agent
from crewai.llm import LLM
def test_normalize_model_name_method():
"""Test that the _normalize_model_name method correctly handles model names with 'models/' prefix"""
agent = Agent(
role="Test Agent",
goal="Test goal",
backstory="Test backstory",
llm="gpt-4"
)
model_with_prefix = "models/gemini/gemini-1.5-flash"
normalized_name = agent._normalize_model_name(model_with_prefix)
assert normalized_name == "gemini/gemini-1.5-flash"
regular_model = "gpt-4"
assert agent._normalize_model_name(regular_model) == "gpt-4"
assert agent._normalize_model_name(None) is None
assert agent._normalize_model_name(123) == 123
def test_agent_with_regular_model_name():
"""Test that the Agent class doesn't modify normal model names"""
with patch('crewai.agent.LLM') as mock_llm:
agent = Agent(
role="Test Agent",
goal="Test goal",
backstory="Test backstory",
llm="gpt-4"
)
args, kwargs = mock_llm.call_args
assert kwargs["model"] == "gpt-4"