mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
test: improve test reliability by mocking LLM responses
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -7,7 +7,14 @@ from crewai.llm import LLM
|
|||||||
from crewai.task import Task
|
from crewai.task import Task
|
||||||
from crewai.utilities.evaluators.crew_evaluator_handler import CrewEvaluator
|
from crewai.utilities.evaluators.crew_evaluator_handler import CrewEvaluator
|
||||||
|
|
||||||
def test_crew_test_with_custom_llm():
|
@pytest.mark.parametrize("model_input", [
|
||||||
|
"gpt-4", # Test string model name
|
||||||
|
LLM(model="gpt-4"), # Test LLM instance
|
||||||
|
])
|
||||||
|
def test_crew_test_with_custom_llm(model_input, mocker):
|
||||||
|
# Mock LLM call to return valid JSON
|
||||||
|
mocker.patch('crewai.llm.LLM.call', return_value='{"quality": 9.0}')
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
role="test",
|
role="test",
|
||||||
@@ -22,12 +29,8 @@ def test_crew_test_with_custom_llm():
|
|||||||
)
|
)
|
||||||
crew = Crew(agents=[agent], tasks=[task])
|
crew = Crew(agents=[agent], tasks=[task])
|
||||||
|
|
||||||
# Test with string model name
|
# Test with provided model input
|
||||||
crew.test(n_iterations=1, llm="gpt-4")
|
crew.test(n_iterations=1, llm=model_input)
|
||||||
|
|
||||||
# Test with LLM instance
|
|
||||||
custom_llm = LLM(model="gpt-4")
|
|
||||||
crew.test(n_iterations=1, llm=custom_llm)
|
|
||||||
|
|
||||||
# Test backward compatibility
|
# Test backward compatibility
|
||||||
crew.test(n_iterations=1, openai_model_name="gpt-4")
|
crew.test(n_iterations=1, openai_model_name="gpt-4")
|
||||||
|
|||||||
Reference in New Issue
Block a user