Skip to content

Commit

Permalink
updating tools version
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Jan 19, 2025
1 parent 46d3e4d commit cc018bf
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 68 deletions.
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@ dependencies = [
"openai>=1.13.3",
"litellm==1.57.4",
"instructor>=1.3.3",

# Text Processing
"pdfplumber>=0.11.4",
"regex>=2024.9.11",

# Telemetry and Monitoring
"opentelemetry-api>=1.22.0",
"opentelemetry-sdk>=1.22.0",
"opentelemetry-exporter-otlp-proto-http>=1.22.0",

# Data Handling
"chromadb>=0.5.23",
"openpyxl>=3.1.5",
"pyvis>=0.3.2",

# Authentication and Security
"auth0-python>=4.7.1",
"python-dotenv>=1.0.0",

# Configuration and Utils
"click>=8.1.7",
"appdirs>=1.4.4",
Expand All @@ -40,7 +35,7 @@ dependencies = [
"uv>=0.4.25",
"tomli-w>=1.1.0",
"tomli>=2.0.2",
"blinker>=1.9.0"
"blinker>=1.9.0",
]

[project.urls]
Expand All @@ -49,7 +44,7 @@ Documentation = "https://docs.crewai.com"
Repository = "https://github.com/crewAIInc/crewAI"

[project.optional-dependencies]
tools = ["crewai-tools>=0.25.5"]
tools = ["crewai-tools>=0.32.1"]
embeddings = [
"tiktoken~=0.7.0"
]
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/cli/templates/flow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel

from crewai.flow.flow import Flow, listen, start
from crewai.flow import Flow, listen, start

from {{folder_name}}.crews.poem_crew.poem_crew import PoemCrew

Expand Down
6 changes: 4 additions & 2 deletions src/crewai/flow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from crewai.flow.flow import Flow
from crewai.flow.flow import Flow, start, listen, or_, and_, router
from crewai.flow.persistence import persist

__all__ = ["Flow", "start", "listen", "or_", "and_", "router", "persist"]

__all__ = ["Flow"]
7 changes: 3 additions & 4 deletions src/crewai/flow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def ensure_state_type(state: Any, expected_type: Type[StateT]) -> StateT:
ValueError: If state validation fails
"""
"""Ensure state matches expected type with proper validation.
Args:
state: State instance to validate
expected_type: Expected type for the state
Returns:
Validated state instance
Raises:
TypeError: If state doesn't match expected type
ValueError: If state validation fails
Expand Down Expand Up @@ -612,7 +612,6 @@ class StateWithId(state_type, FlowState): # type: ignore
# Create new instance of the same class
model_class = type(model)
return cast(T, model_class(**state_dict))

raise TypeError(
f"Initial state must be dict or BaseModel, got {type(self.initial_state)}"
)
Expand Down
35 changes: 16 additions & 19 deletions src/crewai/flow/persistence/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
```python
from crewai.flow.flow import Flow, start
from crewai.flow.persistence import persist, SQLiteFlowPersistence
class MyFlow(Flow):
@start()
@persist(SQLiteFlowPersistence())
def sync_method(self):
# Synchronous method implementation
pass
@start()
@persist(SQLiteFlowPersistence())
async def async_method(self):
Expand All @@ -23,18 +23,15 @@ async def async_method(self):

import asyncio
import functools
import inspect
import logging
from typing import (
Any,
Callable,
Dict,
Optional,
Type,
TypeVar,
Union,
cast,
get_type_hints,
)

from pydantic import BaseModel
Expand All @@ -48,23 +45,23 @@ async def async_method(self):

def persist(persistence: Optional[FlowPersistence] = None):
"""Decorator to persist flow state.
This decorator can be applied at either the class level or method level.
When applied at the class level, it automatically persists all flow method
states. When applied at the method level, it persists only that method's
state.
Args:
persistence: Optional FlowPersistence implementation to use.
If not provided, uses SQLiteFlowPersistence.
Returns:
A decorator that can be applied to either a class or method
Raises:
ValueError: If the flow state doesn't have an 'id' field
RuntimeError: If state persistence fails
Example:
@persist # Class-level persistence with default SQLite
class MyFlow(Flow[MyState]):
Expand All @@ -79,18 +76,18 @@ def _persist_state(flow_instance: Any, method_name: str, persistence_instance: F
state = getattr(flow_instance, 'state', None)
if state is None:
raise ValueError("Flow instance has no state")

flow_uuid: Optional[str] = None
if isinstance(state, dict):
flow_uuid = state.get('id')
elif isinstance(state, BaseModel):
flow_uuid = getattr(state, 'id', None)

if not flow_uuid:
raise ValueError(
"Flow state must have an 'id' field for persistence"
)

# Persist the state
persistence_instance.save_state(
flow_uuid=flow_uuid,
Expand All @@ -102,11 +99,11 @@ def _persist_state(flow_instance: Any, method_name: str, persistence_instance: F
f"Failed to persist state for method {method_name}: {str(e)}"
)
raise RuntimeError(f"State persistence failed: {str(e)}") from e

def decorator(target: Union[Type, Callable[..., T]]) -> Union[Type, Callable[..., T]]:
"""Decorator that handles both class and method decoration."""
actual_persistence = persistence or SQLiteFlowPersistence()

if isinstance(target, type):
# Class decoration
class_methods = {}
Expand All @@ -131,13 +128,13 @@ def class_sync_wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
_persist_state(self, method.__name__, actual_persistence)
return result
class_methods[name] = class_sync_wrapper

# Preserve flow-specific attributes
for attr in ["__is_start_method__", "__trigger_methods__", "__condition_type__", "__is_router__"]:
if hasattr(method, attr):
setattr(class_methods[name], attr, getattr(method, attr))
setattr(class_methods[name], "__is_flow_method__", True)

# Update class with wrapped methods
for name, method in class_methods.items():
setattr(target, name, method)
Expand All @@ -146,7 +143,7 @@ def class_sync_wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
# Method decoration
method = target
setattr(method, "__is_flow_method__", True)

if asyncio.iscoroutinefunction(method):
@functools.wraps(method)
async def method_async_wrapper(flow_instance: Any, *args: Any, **kwargs: Any) -> T:
Expand All @@ -173,5 +170,5 @@ def method_sync_wrapper(flow_instance: Any, *args: Any, **kwargs: Any) -> T:
setattr(method_sync_wrapper, attr, getattr(method, attr))
setattr(method_sync_wrapper, "__is_flow_method__", True)
return cast(Callable[..., T], method_sync_wrapper)

return decorator
Loading

0 comments on commit cc018bf

Please sign in to comment.