Skip to content

Commit 0424e87

Browse files
committed
cleanup
1 parent 6b75133 commit 0424e87

File tree

2 files changed

+1
-76
lines changed

2 files changed

+1
-76
lines changed

mcp_bridge/agent_worker.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -179,40 +179,6 @@ async def extract_tool_result_image(self, result) -> Optional[Dict[str, Any]]:
179179

180180
return None
181181

182-
def save_image_locally(self, base64_data: str, mime_type: str = "image/png") -> None:
183-
"""Save base64 image data to a local file for inspection"""
184-
import base64
185-
import os
186-
from datetime import datetime
187-
188-
# Create a screenshots directory if it doesn't exist
189-
screenshots_dir = "screenshots"
190-
os.makedirs(screenshots_dir, exist_ok=True)
191-
192-
# Determine file extension from MIME type
193-
extension = "png" # Default
194-
if mime_type == "image/jpeg":
195-
extension = "jpg"
196-
elif mime_type == "image/gif":
197-
extension = "gif"
198-
elif mime_type == "image/webp":
199-
extension = "webp"
200-
201-
# Generate a filename with a timestamp
202-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
203-
filename = os.path.join(screenshots_dir, f"screenshot_{timestamp}.{extension}")
204-
205-
try:
206-
# Decode the base64 data
207-
image_data = base64.b64decode(base64_data)
208-
209-
# Write the image to a file
210-
with open(filename, "wb") as f:
211-
f.write(image_data)
212-
213-
logger.info(f"Saved screenshot: {filename}")
214-
except Exception as e:
215-
logger.error(f"Error saving image: {e}")
216182

217183
async def is_image_tool(self, tool_name: str) -> bool:
218184
"""Check if a tool is expected to return image data by examining its description or response type"""

mcp_bridge/anthropic_clients/chatCompletion.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ async def anthropic_chat_completions(
145145
mime_type = "image/png" # Default
146146
if hasattr(part, "mimeType"):
147147
mime_type = part.mimeType
148-
149-
# Save the image locally for inspection
150-
save_image_locally(image_data_raw, tool_name, mime_type)
148+
151149

152150
image_data = {
153151
"type": "image",
@@ -164,8 +162,6 @@ async def anthropic_chat_completions(
164162
elif hasattr(part, "image") and part.image:
165163
# Extract image data if available
166164
try:
167-
# Save the image locally for inspection
168-
save_image_locally(part.image, tool_name)
169165

170166
image_data = {
171167
"type": "image",
@@ -184,8 +180,6 @@ async def anthropic_chat_completions(
184180
for key in ["image", "data"]:
185181
if hasattr(part, 'keys') and key in part and isinstance(part[key], str) and len(part[key]) > 1000:
186182
try:
187-
# Save as a dictionary format
188-
save_image_locally(part[key], tool_name)
189183

190184
image_data = {
191185
"type": "image",
@@ -326,38 +320,3 @@ async def anthropic_chat_completions(
326320
"total_tokens": 0
327321
}
328322
}
329-
330-
def save_image_locally(base64_data: str, tool_name: str, mime_type: str = "image/png") -> None:
331-
"""Save base64 image data to a local file for inspection"""
332-
import base64
333-
import os
334-
from datetime import datetime
335-
336-
# Create a screenshots directory if it doesn't exist
337-
screenshots_dir = "screenshots"
338-
os.makedirs(screenshots_dir, exist_ok=True)
339-
340-
# Determine file extension from MIME type
341-
extension = "png" # Default
342-
if mime_type == "image/jpeg":
343-
extension = "jpg"
344-
elif mime_type == "image/gif":
345-
extension = "gif"
346-
elif mime_type == "image/webp":
347-
extension = "webp"
348-
349-
# Generate a filename with a timestamp
350-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
351-
filename = os.path.join(screenshots_dir, f"{tool_name}_screenshot_{timestamp}.{extension}")
352-
353-
try:
354-
# Decode the base64 data
355-
image_data = base64.b64decode(base64_data)
356-
357-
# Write the image to a file
358-
with open(filename, "wb") as f:
359-
f.write(image_data)
360-
361-
logger.info(f"Saved screenshot: {filename}")
362-
except Exception as e:
363-
logger.error(f"Error saving image: {e}")

0 commit comments

Comments
 (0)