mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
Trying to fix linting and other warnings (#1417)
* Trying to fix linting * fixing more type issues * clean up ci * more ci fixes --------- Co-authored-by: Eduardo Chiarotti <dudumelgaco@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
b149bd4149
commit
6534a909d6
@@ -1,12 +1,12 @@
|
||||
from functools import wraps
|
||||
from typing import Callable
|
||||
|
||||
from crewai.project.utils import memoize
|
||||
from crewai import Crew
|
||||
from crewai.project.utils import memoize
|
||||
|
||||
|
||||
def task(func):
|
||||
if not hasattr(task, "registration_order"):
|
||||
task.registration_order = []
|
||||
func.is_task = True
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
@@ -15,9 +15,6 @@ def task(func):
|
||||
result.name = func.__name__
|
||||
return result
|
||||
|
||||
setattr(wrapper, "is_task", True)
|
||||
task.registration_order.append(func.__name__)
|
||||
|
||||
return memoize(wrapper)
|
||||
|
||||
|
||||
@@ -73,50 +70,45 @@ def pipeline(func):
|
||||
return memoize(func)
|
||||
|
||||
|
||||
def crew(func) -> "Crew":
|
||||
def wrapper(self, *args, **kwargs):
|
||||
def crew(func) -> Callable[..., Crew]:
|
||||
def wrapper(self, *args, **kwargs) -> Crew:
|
||||
instantiated_tasks = []
|
||||
instantiated_agents = []
|
||||
|
||||
agent_roles = set()
|
||||
all_functions = {
|
||||
name: getattr(self, name)
|
||||
for name in dir(self)
|
||||
if callable(getattr(self, name))
|
||||
}
|
||||
tasks = {
|
||||
name: func
|
||||
for name, func in all_functions.items()
|
||||
if hasattr(func, "is_task")
|
||||
}
|
||||
agents = {
|
||||
name: func
|
||||
for name, func in all_functions.items()
|
||||
if hasattr(func, "is_agent")
|
||||
}
|
||||
|
||||
# Sort tasks by their registration order
|
||||
sorted_task_names = sorted(
|
||||
tasks, key=lambda name: task.registration_order.index(name)
|
||||
)
|
||||
# Collect methods from crew in order
|
||||
all_functions = [
|
||||
(name, getattr(self, name))
|
||||
for name, attr in self.__class__.__dict__.items()
|
||||
if callable(attr)
|
||||
]
|
||||
tasks = [
|
||||
(name, method)
|
||||
for name, method in all_functions
|
||||
if hasattr(method, "is_task")
|
||||
]
|
||||
|
||||
# Instantiate tasks in the order they were defined
|
||||
for task_name in sorted_task_names:
|
||||
task_instance = tasks[task_name]()
|
||||
agents = [
|
||||
(name, method)
|
||||
for name, method in all_functions
|
||||
if hasattr(method, "is_agent")
|
||||
]
|
||||
|
||||
# Instantiate tasks in order
|
||||
for task_name, task_method in tasks:
|
||||
task_instance = task_method()
|
||||
instantiated_tasks.append(task_instance)
|
||||
agent_instance = getattr(task_instance, "agent", None)
|
||||
if agent_instance is not None:
|
||||
agent_instance = task_instance.agent
|
||||
if agent_instance.role not in agent_roles:
|
||||
instantiated_agents.append(agent_instance)
|
||||
agent_roles.add(agent_instance.role)
|
||||
if agent_instance and agent_instance.role not in agent_roles:
|
||||
instantiated_agents.append(agent_instance)
|
||||
agent_roles.add(agent_instance.role)
|
||||
|
||||
# Instantiate any additional agents not already included by tasks
|
||||
for agent_name in agents:
|
||||
temp_agent_instance = agents[agent_name]()
|
||||
if temp_agent_instance.role not in agent_roles:
|
||||
instantiated_agents.append(temp_agent_instance)
|
||||
agent_roles.add(temp_agent_instance.role)
|
||||
# Instantiate agents not included by tasks
|
||||
for agent_name, agent_method in agents:
|
||||
agent_instance = agent_method()
|
||||
if agent_instance.role not in agent_roles:
|
||||
instantiated_agents.append(agent_instance)
|
||||
agent_roles.add(agent_instance.role)
|
||||
|
||||
self.agents = instantiated_agents
|
||||
self.tasks = instantiated_tasks
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Dict, Type, TypeVar
|
||||
from typing import Any, Callable, Dict, TypeVar, cast
|
||||
|
||||
import yaml
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
T = TypeVar("T", bound=Type[Any])
|
||||
T = TypeVar("T", bound=type)
|
||||
|
||||
|
||||
def CrewBase(cls: T) -> T:
|
||||
class WrappedClass(cls):
|
||||
class WrappedClass(cls): # type: ignore
|
||||
is_crew_class: bool = True # type: ignore
|
||||
|
||||
# Get the directory of the class being decorated
|
||||
@@ -180,4 +180,4 @@ def CrewBase(cls: T) -> T:
|
||||
callback_functions[callback]() for callback in callbacks
|
||||
]
|
||||
|
||||
return WrappedClass
|
||||
return cast(T, WrappedClass)
|
||||
|
||||
Reference in New Issue
Block a user