Move to src dir usage (#99)

This commit is contained in:
Greyson LaLonde
2024-01-10 09:39:36 -05:00
committed by GitHub
parent c601fbdc12
commit d122d90df0
22 changed files with 17 additions and 6 deletions

2
src/crewai/agents/cache/__init__.py vendored Normal file
View File

@@ -0,0 +1,2 @@
from .cache_handler import CacheHandler
from .cache_hit import CacheHit

View File

@@ -0,0 +1,20 @@
from typing import Optional
from pydantic import PrivateAttr
class CacheHandler:
"""Callback handler for tool usage."""
_cache: PrivateAttr = {}
def __init__(self):
self._cache = {}
def add(self, tool, input, output):
input = input.strip()
self._cache[f"{tool}-{input}"] = output
def read(self, tool, input) -> Optional[str]:
input = input.strip()
return self._cache.get(f"{tool}-{input}")

18
src/crewai/agents/cache/cache_hit.py vendored Normal file
View File

@@ -0,0 +1,18 @@
from typing import Any
from pydantic import BaseModel, Field
from .cache_handler import CacheHandler
class CacheHit(BaseModel):
"""Cache Hit Object."""
class Config:
arbitrary_types_allowed = True
# Making it Any instead of AgentAction to avoind
# pydantic v1 vs v2 incompatibility, langchain should
# soon be updated to pydantic v2
action: Any = Field(description="Action taken")
cache: CacheHandler = Field(description="Cache Handler for the tool")