mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
Add converter_cls option to Task (#800)
* Add converter_cls option to Task Fixes #799 * Update task_test.py * Update task.py * Update task.py * Update task_test.py * Update task.py * Update task.py * Update task.py * Update task.py --------- Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
committed by
GitHub
parent
58558a1950
commit
7edacf6e24
@@ -9,6 +9,7 @@ from pydantic_core import ValidationError
|
||||
|
||||
from crewai import Agent, Crew, Process, Task
|
||||
from crewai.tasks.task_output import TaskOutput
|
||||
from crewai.utilities.converter import Converter
|
||||
|
||||
|
||||
def test_task_tool_reflect_agent_tools():
|
||||
@@ -393,6 +394,37 @@ def test_save_task_pydantic_output():
|
||||
save_file.assert_called_once_with('{"score":4}')
|
||||
|
||||
|
||||
def test_custom_converter_cls():
|
||||
class ScoreOutput(BaseModel):
|
||||
score: int
|
||||
|
||||
class ScoreConverter(Converter):
|
||||
pass
|
||||
|
||||
scorer = Agent(
|
||||
role="Scorer",
|
||||
goal="Score the title",
|
||||
backstory="You're an expert scorer, specialized in scoring titles.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Give me an integer score between 1-5 for the following title: 'The impact of AI in the future of work'",
|
||||
expected_output="The score of the title.",
|
||||
output_file="score.json",
|
||||
output_pydantic=ScoreOutput,
|
||||
converter_cls=ScoreConverter,
|
||||
agent=scorer,
|
||||
)
|
||||
|
||||
crew = Crew(agents=[scorer], tasks=[task])
|
||||
|
||||
with patch.object(ScoreConverter, "__new__", ScoreConverter.__new__) as converter_constructor:
|
||||
crew.kickoff()
|
||||
converter_constructor.assert_called_once
|
||||
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_increment_delegations_for_hierarchical_process():
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
Reference in New Issue
Block a user