Skip to content

Commit

Permalink
fixing tasks order
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Sep 27, 2024
1 parent bc31019 commit 44c8765
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 156 deletions.
256 changes: 128 additions & 128 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/crewai/agents/crew_agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def __init__(
self.log_error_after = 3
self.have_forced_answer = False
self.name_to_tool_map = {tool.name: tool for tool in self.tools}
self.llm.stop = self.stop
if self.llm.stop:
self.llm.stop = list(set(self.llm.stop + self.stop))
else:
self.llm.stop = self.stop

def invoke(self, inputs: Dict[str, str]) -> Dict[str, Any]:
if "system" in self.prompt:
Expand Down
3 changes: 2 additions & 1 deletion src/crewai/project/annotations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import wraps

from crewai.project.utils import memoize
from crewai import Crew


def task(func):
Expand Down Expand Up @@ -72,7 +73,7 @@ def pipeline(func):
return memoize(func)


def crew(func):
def crew(func) -> "Crew":
def wrapper(self, *args, **kwargs):
instantiated_tasks = []
instantiated_agents = []
Expand Down
16 changes: 0 additions & 16 deletions src/crewai/project/crew_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import yaml
from dotenv import load_dotenv

from crewai.crew import Crew

load_dotenv()


T = TypeVar("T", bound=Type[Any])


Expand Down Expand Up @@ -37,19 +34,6 @@ def __init__(self, *args, **kwargs):
self.map_all_agent_variables()
self.map_all_task_variables()

def crew(self) -> "Crew":
agents = [
getattr(self, name)()
for name, func in self._get_all_functions().items()
if hasattr(func, "is_agent")
]
tasks = [
getattr(self, name)()
for name, func in reversed(self._get_all_functions().items())
if hasattr(func, "is_task")
]
return Crew(agents=agents, tasks=tasks)

@staticmethod
def load_yaml(config_path: Path):
try:
Expand Down
10 changes: 5 additions & 5 deletions tests/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ def test_agent_training_handler(crew_training_handler):

result = agent._training_handler(task_prompt=task_prompt)

assert result == "What is 1 + 1?You MUST follow these feedbacks: \n good"
assert result == "What is 1 + 1?\n\nYou MUST follow these instructions: \n good"

crew_training_handler.assert_has_calls(
[mock.call(), mock.call("training_data.pkl"), mock.call().load()]
Expand Down Expand Up @@ -1121,8 +1121,8 @@ def test_agent_use_trained_data(crew_training_handler):
result = agent._use_trained_data(task_prompt=task_prompt)

assert (
result == "What is 1 + 1?You MUST follow these feedbacks: \n "
"The result of the math operation must be right.\n - Result must be better than 1."
result == "What is 1 + 1?\n\nYou MUST follow these instructions: \n"
" - The result of the math operation must be right.\n - Result must be better than 1."
)
crew_training_handler.assert_has_calls(
[mock.call(), mock.call("trained_agents_data.pkl"), mock.call().load()]
Expand Down Expand Up @@ -1205,7 +1205,7 @@ def test_agent_with_custom_stop_words():
)

assert isinstance(agent.llm, LLM)
assert agent.llm.stop == stop_words
assert agent.llm.stop == stop_words + ["\nObservation:"]


def test_agent_with_callbacks():
Expand Down Expand Up @@ -1368,7 +1368,7 @@ def test_agent_with_all_llm_attributes():
assert agent.llm.temperature == 0.7
assert agent.llm.top_p == 0.9
assert agent.llm.n == 1
assert agent.llm.stop == ["STOP", "END"]
assert agent.llm.stop == ["STOP", "END", "\nObservation:"]
assert agent.llm.max_tokens == 100
assert agent.llm.presence_penalty == 0.1
assert agent.llm.frequency_penalty == 0.1
Expand Down
11 changes: 6 additions & 5 deletions tests/utilities/evaluators/test_task_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ def test_evaluate_training_data(converter_mock):
text="Assess the quality of the training data based on the llm output, human feedback , and llm "
"output improved result.\n\nInitial Output:\nInitial output 1\n\nHuman Feedback:\nHuman feedback "
"1\n\nImproved Output:\nImproved output 1\n\nInitial Output:\nInitial output 2\n\nHuman "
"Feedback:\nHuman feedback 2\n\nImproved Output:\nImproved output 2\n\nPlease provide:\n- "
"Based on the Human Feedbacks and the comparison between Initial Outputs and Improved outputs "
"provide action items based on human_feedback for future tasks\n- A score from 0 to 10 evaluating "
"on completion, quality, and overall performance from the improved output to the initial output "
"based on the human feedback\n",
"Feedback:\nHuman feedback 2\n\nImproved Output:\nImproved output 2\n\nPlease provide:\n- Provide "
"a list of clear, actionable instructions derived from the Human Feedbacks to enhance the Agent's "
"performance. Analyze the differences between Initial Outputs and Improved Outputs to generate specific "
"action items for future tasks. Ensure all key and specificpoints from the human feedback are "
"incorporated into these instructions.\n- A score from 0 to 10 evaluating on completion, quality, and "
"overall performance from the improved output to the initial output based on the human feedback\n",
model=TrainingTaskEvaluation,
instructions="I'm gonna convert this raw text into valid JSON.\n\nThe json should have the "
"following structure, with the following keys:\n{\n suggestions: List[str],\n quality: float,\n final_summary: str\n}",
Expand Down

0 comments on commit 44c8765

Please sign in to comment.