feat: improve LLM validation and error handling

- Add descriptive error messages with usage context
- Add LLM instance validation
- Add deprecation warning for openai_model_name
- Add string representation to CrewEvaluator
- Add edge case tests

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-09 22:48:56 +00:00
parent 3e67a2eca1
commit 90aea23dd6
3 changed files with 61 additions and 6 deletions

View File

@@ -38,10 +38,18 @@ class CrewEvaluator:
def __init__(self, crew, llm: Union[str, LLM]):
self.crew = crew
self.llm = llm if isinstance(llm, LLM) else LLM(model=llm)
try:
self.llm = llm if isinstance(llm, LLM) else LLM(model=llm)
if not hasattr(self.llm, 'model'):
raise ValueError("Provided LLM instance must have a 'model' attribute")
except Exception as e:
raise ValueError(f"Failed to initialize LLM: {str(e)}")
self._telemetry = Telemetry()
self._setup_for_evaluating()
def __str__(self) -> str:
return f"CrewEvaluator(model={str(self.llm)}, iteration={self.iteration})"
def _setup_for_evaluating(self) -> None:
"""Sets up the crew for evaluating."""
for task in self.crew.tasks: