Merge pull request #174 from crewAIInc/extra_deps

add optional dependencies for all deps that we have
This commit is contained in:
Lorenze Jay
2025-01-03 14:19:00 -08:00
committed by GitHub

View File

@@ -1,29 +1,50 @@
from typing import Any, Optional, Type from typing import Optional, Type
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from pypdf import PdfReader, PdfWriter, PageObject, ContentStream, NameObject, Font from pypdf import PdfReader, PdfWriter, PageObject, ContentStream, NameObject, Font
from pathlib import Path from pathlib import Path
from crewai_tools.tools.rag.rag_tool import RagTool
class PDFTextWritingToolSchema(BaseModel): class PDFTextWritingToolSchema(BaseModel):
"""Input schema for PDFTextWritingTool.""" """Input schema for PDFTextWritingTool."""
pdf_path: str = Field(..., description="Path to the PDF file to modify") pdf_path: str = Field(..., description="Path to the PDF file to modify")
text: str = Field(..., description="Text to add to the PDF") text: str = Field(..., description="Text to add to the PDF")
position: tuple = Field(..., description="Tuple of (x, y) coordinates for text placement") position: tuple = Field(
..., description="Tuple of (x, y) coordinates for text placement"
)
font_size: int = Field(default=12, description="Font size of the text") font_size: int = Field(default=12, description="Font size of the text")
font_color: str = Field(default="0 0 0 rg", description="RGB color code for the text") font_color: str = Field(
font_name: Optional[str] = Field(default="F1", description="Font name for standard fonts") default="0 0 0 rg", description="RGB color code for the text"
font_file: Optional[str] = Field(None, description="Path to a .ttf font file for custom font usage") )
font_name: Optional[str] = Field(
default="F1", description="Font name for standard fonts"
)
font_file: Optional[str] = Field(
None, description="Path to a .ttf font file for custom font usage"
)
page_number: int = Field(default=0, description="Page number to add text to") page_number: int = Field(default=0, description="Page number to add text to")
class PDFTextWritingTool(RagTool): class PDFTextWritingTool(RagTool):
"""A tool to add text to specific positions in a PDF, with custom font support.""" """A tool to add text to specific positions in a PDF, with custom font support."""
name: str = "PDF Text Writing Tool" name: str = "PDF Text Writing Tool"
description: str = "A tool that can write text to a specific position in a PDF document, with optional custom font embedding." description: str = "A tool that can write text to a specific position in a PDF document, with optional custom font embedding."
args_schema: Type[BaseModel] = PDFTextWritingToolSchema args_schema: Type[BaseModel] = PDFTextWritingToolSchema
def run(self, pdf_path: str, text: str, position: tuple, font_size: int, font_color: str, def run(
font_name: str = "F1", font_file: Optional[str] = None, page_number: int = 0, **kwargs) -> str: self,
pdf_path: str,
text: str,
position: tuple,
font_size: int,
font_color: str,
font_name: str = "F1",
font_file: Optional[str] = None,
page_number: int = 0,
**kwargs,
) -> str:
reader = PdfReader(pdf_path) reader = PdfReader(pdf_path)
writer = PdfWriter() writer = PdfWriter()