mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
chore: fix ruff linting issues in project module
This commit is contained in:
@@ -2,7 +2,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any
|
||||||
|
|
||||||
from crewai.task import Task
|
from crewai.task import Task
|
||||||
from crewai.utilities import Printer
|
from crewai.utilities import Printer
|
||||||
@@ -18,7 +18,7 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
An updated SQLite storage class for kickoff task outputs storage.
|
An updated SQLite storage class for kickoff task outputs storage.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, db_path: Optional[str] = None) -> None:
|
def __init__(self, db_path: str | None = None) -> None:
|
||||||
if db_path is None:
|
if db_path is None:
|
||||||
# Get the parent directory of the default db path and create our db file there
|
# Get the parent directory of the default db path and create our db file there
|
||||||
db_path = str(Path(db_storage_path()) / "latest_kickoff_task_outputs.db")
|
db_path = str(Path(db_storage_path()) / "latest_kickoff_task_outputs.db")
|
||||||
@@ -57,15 +57,15 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
error_msg = DatabaseError.format_error(DatabaseError.INIT_ERROR, e)
|
error_msg = DatabaseError.format_error(DatabaseError.INIT_ERROR, e)
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise DatabaseOperationError(error_msg, e)
|
raise DatabaseOperationError(error_msg, e) from e
|
||||||
|
|
||||||
def add(
|
def add(
|
||||||
self,
|
self,
|
||||||
task: Task,
|
task: Task,
|
||||||
output: Dict[str, Any],
|
output: dict[str, Any],
|
||||||
task_index: int,
|
task_index: int,
|
||||||
was_replayed: bool = False,
|
was_replayed: bool = False,
|
||||||
inputs: Dict[str, Any] | None = None,
|
inputs: dict[str, Any] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add a new task output record to the database.
|
"""Add a new task output record to the database.
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
error_msg = DatabaseError.format_error(DatabaseError.SAVE_ERROR, e)
|
error_msg = DatabaseError.format_error(DatabaseError.SAVE_ERROR, e)
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise DatabaseOperationError(error_msg, e)
|
raise DatabaseOperationError(error_msg, e) from e
|
||||||
|
|
||||||
def update(
|
def update(
|
||||||
self,
|
self,
|
||||||
@@ -138,7 +138,7 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
else value
|
else value
|
||||||
)
|
)
|
||||||
|
|
||||||
query = f"UPDATE latest_kickoff_task_outputs SET {', '.join(fields)} WHERE task_index = ?" # nosec
|
query = f"UPDATE latest_kickoff_task_outputs SET {', '.join(fields)} WHERE task_index = ?" # nosec # noqa: S608
|
||||||
values.append(task_index)
|
values.append(task_index)
|
||||||
|
|
||||||
cursor.execute(query, tuple(values))
|
cursor.execute(query, tuple(values))
|
||||||
@@ -151,9 +151,9 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
error_msg = DatabaseError.format_error(DatabaseError.UPDATE_ERROR, e)
|
error_msg = DatabaseError.format_error(DatabaseError.UPDATE_ERROR, e)
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise DatabaseOperationError(error_msg, e)
|
raise DatabaseOperationError(error_msg, e) from e
|
||||||
|
|
||||||
def load(self) -> List[Dict[str, Any]]:
|
def load(self) -> list[dict[str, Any]]:
|
||||||
"""Load all task output records from the database.
|
"""Load all task output records from the database.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -192,7 +192,7 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
error_msg = DatabaseError.format_error(DatabaseError.LOAD_ERROR, e)
|
error_msg = DatabaseError.format_error(DatabaseError.LOAD_ERROR, e)
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise DatabaseOperationError(error_msg, e)
|
raise DatabaseOperationError(error_msg, e) from e
|
||||||
|
|
||||||
def delete_all(self) -> None:
|
def delete_all(self) -> None:
|
||||||
"""Delete all task output records from the database.
|
"""Delete all task output records from the database.
|
||||||
@@ -212,4 +212,4 @@ class KickoffTaskOutputsSQLiteStorage:
|
|||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
error_msg = DatabaseError.format_error(DatabaseError.DELETE_ERROR, e)
|
error_msg = DatabaseError.format_error(DatabaseError.DELETE_ERROR, e)
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise DatabaseOperationError(error_msg, e)
|
raise DatabaseOperationError(error_msg, e) from e
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any
|
||||||
|
|
||||||
from crewai.utilities import Printer
|
from crewai.utilities import Printer
|
||||||
from crewai.utilities.paths import db_storage_path
|
from crewai.utilities.paths import db_storage_path
|
||||||
@@ -12,9 +12,7 @@ class LTMSQLiteStorage:
|
|||||||
An updated SQLite storage class for LTM data storage.
|
An updated SQLite storage class for LTM data storage.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, db_path: str | None = None) -> None:
|
||||||
self, db_path: Optional[str] = None
|
|
||||||
) -> None:
|
|
||||||
if db_path is None:
|
if db_path is None:
|
||||||
# Get the parent directory of the default db path and create our db file there
|
# Get the parent directory of the default db path and create our db file there
|
||||||
db_path = str(Path(db_storage_path()) / "long_term_memory_storage.db")
|
db_path = str(Path(db_storage_path()) / "long_term_memory_storage.db")
|
||||||
@@ -53,9 +51,9 @@ class LTMSQLiteStorage:
|
|||||||
def save(
|
def save(
|
||||||
self,
|
self,
|
||||||
task_description: str,
|
task_description: str,
|
||||||
metadata: Dict[str, Any],
|
metadata: dict[str, Any],
|
||||||
datetime: str,
|
datetime: str,
|
||||||
score: Union[int, float],
|
score: int | float,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Saves data to the LTM table with error handling."""
|
"""Saves data to the LTM table with error handling."""
|
||||||
try:
|
try:
|
||||||
@@ -75,9 +73,7 @@ class LTMSQLiteStorage:
|
|||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
|
|
||||||
def load(
|
def load(self, task_description: str, latest_n: int) -> list[dict[str, Any]] | None:
|
||||||
self, task_description: str, latest_n: int
|
|
||||||
) -> Optional[List[Dict[str, Any]]]:
|
|
||||||
"""Queries the LTM table by task description with error handling."""
|
"""Queries the LTM table by task description with error handling."""
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.db_path) as conn:
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
@@ -89,7 +85,7 @@ class LTMSQLiteStorage:
|
|||||||
WHERE task_description = ?
|
WHERE task_description = ?
|
||||||
ORDER BY datetime DESC, score ASC
|
ORDER BY datetime DESC, score ASC
|
||||||
LIMIT {latest_n}
|
LIMIT {latest_n}
|
||||||
""", # nosec
|
""", # nosec # noqa: S608
|
||||||
(task_description,),
|
(task_description,),
|
||||||
)
|
)
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
@@ -125,4 +121,4 @@ class LTMSQLiteStorage:
|
|||||||
content=f"MEMORY ERROR: An error occurred while deleting all rows in LTM: {e}",
|
content=f"MEMORY ERROR: An error occurred while deleting all rows in LTM: {e}",
|
||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
return None
|
return
|
||||||
|
|||||||
@@ -14,16 +14,16 @@ from .annotations import (
|
|||||||
from .crew_base import CrewBase
|
from .crew_base import CrewBase
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
"CrewBase",
|
||||||
|
"after_kickoff",
|
||||||
"agent",
|
"agent",
|
||||||
|
"before_kickoff",
|
||||||
|
"cache_handler",
|
||||||
|
"callback",
|
||||||
"crew",
|
"crew",
|
||||||
"task",
|
"llm",
|
||||||
"output_json",
|
"output_json",
|
||||||
"output_pydantic",
|
"output_pydantic",
|
||||||
|
"task",
|
||||||
"tool",
|
"tool",
|
||||||
"callback",
|
|
||||||
"CrewBase",
|
|
||||||
"llm",
|
|
||||||
"cache_handler",
|
|
||||||
"before_kickoff",
|
|
||||||
"after_kickoff",
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from crewai import Crew
|
from crewai import Crew
|
||||||
from crewai.project.utils import memoize
|
from crewai.project.utils import memoize
|
||||||
@@ -36,15 +36,13 @@ def task(func):
|
|||||||
def agent(func):
|
def agent(func):
|
||||||
"""Marks a method as a crew agent."""
|
"""Marks a method as a crew agent."""
|
||||||
func.is_agent = True
|
func.is_agent = True
|
||||||
func = memoize(func)
|
return memoize(func)
|
||||||
return func
|
|
||||||
|
|
||||||
|
|
||||||
def llm(func):
|
def llm(func):
|
||||||
"""Marks a method as an LLM provider."""
|
"""Marks a method as an LLM provider."""
|
||||||
func.is_llm = True
|
func.is_llm = True
|
||||||
func = memoize(func)
|
return memoize(func)
|
||||||
return func
|
|
||||||
|
|
||||||
|
|
||||||
def output_json(cls):
|
def output_json(cls):
|
||||||
@@ -91,7 +89,7 @@ def crew(func) -> Callable[..., Crew]:
|
|||||||
agents = self._original_agents.items()
|
agents = self._original_agents.items()
|
||||||
|
|
||||||
# Instantiate tasks in order
|
# Instantiate tasks in order
|
||||||
for task_name, task_method in tasks:
|
for _task_name, task_method in tasks:
|
||||||
task_instance = task_method(self)
|
task_instance = task_method(self)
|
||||||
instantiated_tasks.append(task_instance)
|
instantiated_tasks.append(task_instance)
|
||||||
agent_instance = getattr(task_instance, "agent", None)
|
agent_instance = getattr(task_instance, "agent", None)
|
||||||
@@ -100,7 +98,7 @@ def crew(func) -> Callable[..., Crew]:
|
|||||||
agent_roles.add(agent_instance.role)
|
agent_roles.add(agent_instance.role)
|
||||||
|
|
||||||
# Instantiate agents not included by tasks
|
# Instantiate agents not included by tasks
|
||||||
for agent_name, agent_method in agents:
|
for _agent_name, agent_method in agents:
|
||||||
agent_instance = agent_method(self)
|
agent_instance = agent_method(self)
|
||||||
if agent_instance.role not in agent_roles:
|
if agent_instance.role not in agent_roles:
|
||||||
instantiated_agents.append(agent_instance)
|
instantiated_agents.append(agent_instance)
|
||||||
@@ -117,9 +115,9 @@ def crew(func) -> Callable[..., Crew]:
|
|||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
for _, callback in self._before_kickoff.items():
|
for callback in self._before_kickoff.values():
|
||||||
crew.before_kickoff_callbacks.append(callback_wrapper(callback, self))
|
crew.before_kickoff_callbacks.append(callback_wrapper(callback, self))
|
||||||
for _, callback in self._after_kickoff.items():
|
for callback in self._after_kickoff.values():
|
||||||
crew.after_kickoff_callbacks.append(callback_wrapper(callback, self))
|
crew.after_kickoff_callbacks.append(callback_wrapper(callback, self))
|
||||||
|
|
||||||
return crew
|
return crew
|
||||||
|
|||||||
Reference in New Issue
Block a user