mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-14 18:48:29 +00:00
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:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user