Fix #2220: Add validation for numeric model IDs in LLM class

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-25 13:40:19 +00:00
parent 409892d65f
commit 6d4c591eda
2 changed files with 28 additions and 0 deletions

21
tests/unit/test_llm.py Normal file
View File

@@ -0,0 +1,21 @@
import pytest
from crewai.llm import LLM
def test_numeric_model_id_validation():
# Test with integer model ID
with pytest.raises(ValueError, match="Invalid model ID: 3420. Model ID cannot be a numeric value without a provider prefix."):
LLM(model=3420)
# Test with string numeric model ID
with pytest.raises(ValueError, match="Invalid model ID: 3420. Model ID cannot be a numeric value without a provider prefix."):
LLM(model="3420")
# Test with valid model ID
llm = LLM(model="openai/gpt-4")
assert llm.model == "openai/gpt-4"
# Test with valid model ID that contains numbers
llm = LLM(model="gpt-3.5-turbo")
assert llm.model == "gpt-3.5-turbo"