mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
Fix #2642: Add local file path handling to AddImageTool for Claude 3.7 Sonnet
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -283,6 +283,9 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
||||
] or tool_calling.tool_name.casefold().replace("_", " ") in [
|
||||
name.casefold().strip() for name in self.tool_name_to_tool_map
|
||||
]:
|
||||
if tool_calling.tool_name.casefold().strip() == self._i18n.tools("add_image")["name"].casefold().strip():
|
||||
tool_calling.kwargs['llm'] = self.llm
|
||||
|
||||
tool_result = tool_usage.use(tool_calling, agent_action.text)
|
||||
tool = self.tool_name_to_tool_map.get(tool_calling.tool_name)
|
||||
if tool:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from typing import Dict, Optional, Union
|
||||
import os
|
||||
import base64
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -29,6 +31,20 @@ class AddImageTool(BaseTool):
|
||||
**kwargs,
|
||||
) -> dict:
|
||||
action = action or i18n.tools("add_image")["default_action"] # type: ignore
|
||||
|
||||
if os.path.exists(image_url):
|
||||
try:
|
||||
with open(image_url, "rb") as image_file:
|
||||
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
image_url = f"data:image/jpeg;base64,{encoded_string}"
|
||||
except Exception as e:
|
||||
raise ValueError(f"Error encoding image: {e}")
|
||||
|
||||
using_claude_3_7 = False
|
||||
if "llm" in kwargs and hasattr(kwargs["llm"], "model"):
|
||||
model_name = kwargs["llm"].model
|
||||
using_claude_3_7 = "claude-3-7" in model_name.lower()
|
||||
|
||||
content = [
|
||||
{"type": "text", "text": action},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user