Test optional dependencies are not required in runtime (#260)

* Test optional dependencies are not required in runtime

* Add dynamic imports to S3 tools

* Setup CI
This commit is contained in:
Vini Brasil
2025-04-08 13:20:11 -04:00
committed by GitHub
parent 6f95572e18
commit 257f4bf385
8 changed files with 80 additions and 278 deletions

View File

@@ -8,10 +8,7 @@ from dotenv import load_dotenv
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
import boto3
from botocore.exceptions import ClientError
# Import custom exceptions
from ..exceptions import BedrockAgentError, BedrockValidationError
# Load environment variables from .env file
@@ -92,6 +89,12 @@ class BedrockInvokeAgentTool(BaseTool):
raise BedrockValidationError(f"Parameter validation failed: {str(e)}")
def _run(self, query: str) -> str:
try:
import boto3
from botocore.exceptions import ClientError
except ImportError:
raise ImportError("`boto3` package not found, please run `uv add boto3`")
try:
# Initialize the Bedrock Agent Runtime client
bedrock_agent = boto3.client(

View File

@@ -5,10 +5,7 @@ from dotenv import load_dotenv
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
import boto3
from botocore.exceptions import ClientError
# Import custom exceptions
from ..exceptions import BedrockKnowledgeBaseError, BedrockValidationError
# Load environment variables from .env file
@@ -179,6 +176,12 @@ class BedrockKBRetrieverTool(BaseTool):
return result_object
def _run(self, query: str) -> str:
try:
import boto3
from botocore.exceptions import ClientError
except ImportError:
raise ImportError("`boto3` package not found, please run `uv add boto3`")
try:
# Initialize the Bedrock Agent Runtime client
bedrock_agent_runtime = boto3.client(

View File

@@ -1,10 +1,8 @@
from typing import Type
from typing import Any, Type
import os
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
import boto3
from botocore.exceptions import ClientError
class S3ReaderToolInput(BaseModel):
@@ -19,6 +17,12 @@ class S3ReaderTool(BaseTool):
args_schema: Type[BaseModel] = S3ReaderToolInput
def _run(self, file_path: str) -> str:
try:
import boto3
from botocore.exceptions import ClientError
except ImportError:
raise ImportError("`boto3` package not found, please run `uv add boto3`")
try:
bucket_name, object_key = self._parse_s3_path(file_path)

View File

@@ -1,22 +1,27 @@
from typing import Type
from typing import Any, Type
import os
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
import boto3
from botocore.exceptions import ClientError
class S3WriterToolInput(BaseModel):
"""Input schema for S3WriterTool."""
file_path: str = Field(..., description="S3 file path (e.g., 's3://bucket-name/file-name')")
content: str = Field(..., description="Content to write to the file")
class S3WriterTool(BaseTool):
name: str = "S3 Writer Tool"
description: str = "Writes content to a file in Amazon S3 given an S3 file path"
args_schema: Type[BaseModel] = S3WriterToolInput
def _run(self, file_path: str, content: str) -> str:
try:
import boto3
from botocore.exceptions import ClientError
except ImportError:
raise ImportError("`boto3` package not found, please run `uv add boto3`")
try:
bucket_name, object_key = self._parse_s3_path(file_path)