Compare commits

..

2 Commits

Author SHA1 Message Date
Devin AI
709b8077dd Fix: Format imports to pass lint checks
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 07:02:18 +00:00
Devin AI
2b058a9a54 Fix: Import Self from typing_extensions for Python 3.10 compatibility (#2563)
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 06:59:32 +00:00
10 changed files with 35 additions and 39 deletions

View File

@@ -12,9 +12,6 @@ jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -24,8 +21,9 @@ jobs:
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Set up Python
run: uv python install 3.12.8
- name: Install the project
run: uv sync --dev --all-extras

View File

@@ -13,6 +13,7 @@ dependencies = [
"openai>=1.13.3",
"litellm==1.60.2",
"instructor>=1.3.3",
"typing_extensions>=4.0.0",
# Text Processing
"pdfplumber>=0.11.4",
"regex>=2024.9.11",

View File

@@ -60,7 +60,7 @@ def test():
"current_year": str(datetime.now().year)
}
try:
{{crew_name}}().crew().test(n_iterations=int(sys.argv[1]), eval_llm=sys.argv[2], inputs=inputs)
{{crew_name}}().crew().test(n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs)
except Exception as e:
raise Exception(f"An error occurred while testing the crew: {e}")

View File

@@ -1043,7 +1043,6 @@ class Flow(Generic[T], metaclass=FlowMeta):
import traceback
traceback.print_exc()
raise
def _log_flow_event(
self, message: str, color: str = "yellow", level: str = "info"

View File

@@ -1,9 +1,16 @@
from typing import TYPE_CHECKING, Any, Dict, Optional
import sys
from crewai.memory.external.external_memory_item import ExternalMemoryItem
from crewai.memory.memory import Memory
from crewai.memory.storage.interface import Storage
if sys.version_info < (3, 11):
from typing import TYPE_CHECKING, Any, Dict, Optional
from typing_extensions import Self
else:
from typing import TYPE_CHECKING, Any, Dict, Optional, Self
if TYPE_CHECKING:
from crewai.memory.storage.mem0_storage import Mem0Storage
@@ -52,7 +59,7 @@ class ExternalMemory(Memory):
def reset(self) -> None:
self.storage.reset()
def set_crew(self, crew: Any) -> "ExternalMemory":
def set_crew(self, crew: Any) -> Self:
super().set_crew(crew)
if not self.storage:

View File

@@ -1,7 +1,14 @@
from typing import Any, Dict, List, Optional
import sys
from pydantic import BaseModel
if sys.version_info < (3, 11):
from typing import Any, Dict, List, Optional
from typing_extensions import Self
else:
from typing import Any, Dict, List, Optional, Self
class Memory(BaseModel):
"""
@@ -38,6 +45,6 @@ class Memory(BaseModel):
query=query, limit=limit, score_threshold=score_threshold
)
def set_crew(self, crew: Any) -> "Memory":
def set_crew(self, crew: Any) -> Self:
self.crew = crew
return self

View File

@@ -244,13 +244,9 @@ def to_langchain(
return [t.to_structured_tool() if isinstance(t, BaseTool) else t for t in tools]
def tool(*args, result_as_answer=False):
def tool(*args):
"""
Decorator to create a tool from a function.
Args:
*args: Positional arguments, either the function to decorate or the tool name.
result_as_answer: Flag to indicate if the tool result should be used as the final agent answer.
"""
def _make_with_name(tool_name: str) -> Callable:
@@ -276,7 +272,6 @@ def tool(*args, result_as_answer=False):
description=f.__doc__,
func=f,
args_schema=args_schema,
result_as_answer=result_as_answer,
)
return _make_tool

View File

@@ -13,3 +13,14 @@ def test_crew_output_import():
from crewai import CrewOutput
assert CrewOutput is not None
def test_memory_imports():
"""Test that memory imports work correctly across Python versions."""
import importlib
importlib.import_module("crewai.memory.memory")
importlib.import_module("crewai.memory.external.external_memory")
from crewai.memory.memory import Memory
assert hasattr(Memory, "set_crew")

View File

@@ -100,25 +100,3 @@ def test_default_cache_function_is_true():
my_tool = MyCustomTool()
# Assert all the right attributes were defined
assert my_tool.cache_function()
def test_result_as_answer_in_tool_decorator():
@tool("Tool with result as answer", result_as_answer=True)
def my_tool_with_result_as_answer(question: str) -> str:
"""This tool will return its result as the final answer."""
return question
assert my_tool_with_result_as_answer.result_as_answer is True
converted_tool = my_tool_with_result_as_answer.to_structured_tool()
assert converted_tool.result_as_answer is True
@tool("Tool with default result_as_answer")
def my_tool_with_default(question: str) -> str:
"""This tool uses the default result_as_answer value."""
return question
assert my_tool_with_default.result_as_answer is False
converted_tool = my_tool_with_default.to_structured_tool()
assert converted_tool.result_as_answer is False