mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Fix #2220: Address PR feedback and fix failing tests
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -1,21 +1,42 @@
|
||||
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"
|
||||
@pytest.mark.parametrize(
|
||||
"invalid_model,error_message",
|
||||
[
|
||||
(3420, "Invalid model ID: 3420. Model ID cannot be a numeric value without a provider prefix."),
|
||||
("3420", "Invalid model ID: 3420. Model ID cannot be a numeric value without a provider prefix."),
|
||||
(3.14, "Invalid model ID: 3.14. Model ID cannot be a numeric value without a provider prefix."),
|
||||
],
|
||||
)
|
||||
def test_invalid_numeric_model_ids(invalid_model, error_message):
|
||||
"""Test that numeric model IDs are rejected."""
|
||||
with pytest.raises(ValueError, match=error_message):
|
||||
LLM(model=invalid_model)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"valid_model",
|
||||
[
|
||||
"openai/gpt-4",
|
||||
"gpt-3.5-turbo",
|
||||
"anthropic/claude-2",
|
||||
],
|
||||
)
|
||||
def test_valid_model_ids(valid_model):
|
||||
"""Test that valid model IDs are accepted."""
|
||||
llm = LLM(model=valid_model)
|
||||
assert llm.model == valid_model
|
||||
|
||||
|
||||
def test_empty_model_id():
|
||||
"""Test that empty model IDs are rejected."""
|
||||
with pytest.raises(ValueError, match="Invalid model ID: ''. Model ID cannot be empty or whitespace."):
|
||||
LLM(model="")
|
||||
|
||||
|
||||
def test_whitespace_model_id():
|
||||
"""Test that whitespace model IDs are rejected."""
|
||||
with pytest.raises(ValueError, match="Invalid model ID: ' '. Model ID cannot be empty or whitespace."):
|
||||
LLM(model=" ")
|
||||
|
||||
Reference in New Issue
Block a user