Refactor prepare tool and adding initial add images logic

This commit is contained in:
João Moura
2024-12-26 13:30:59 -03:00
parent e6be4ed66d
commit 93bee87324
5 changed files with 133 additions and 34 deletions

View File

@@ -0,0 +1,34 @@
from pydantic import BaseModel, Field
from crewai.tools.base_tool import BaseTool
class AddImageToolSchema(BaseModel):
image_url: str = Field(..., description="The URL or path of the image to add")
action: str = Field(..., description="The context or purpose of why this image is being added and how it should be used")
class AddImageTool(BaseTool):
"""Tool for adding images to the content"""
name: str = "Add image to content"
description: str = "See image to understand it's content"
args_schema: type[BaseModel] = AddImageToolSchema
def _run(
self,
image_url: str,
action: str,
**kwargs,
) -> dict:
return {
"role": "user",
"content": [
{"type": "text", "text": action},
{
"type": "image_url",
"image_url": {
"url": image_url,
},
},
],
}

View File

@@ -1,7 +1,5 @@
from typing import Optional
from pydantic import BaseModel, Field
from crewai.tools.agent_tools.base_agent_tools import BaseAgentTool