Skip to content

Commit

Permalink
fix: Resize file in screen toolkit (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: Bradley Axen <[email protected]>
  • Loading branch information
zakiali and baxen authored Sep 24, 2024
1 parent cb6a3d7 commit b9bb48e
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/goose/toolkit/screen.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
import subprocess
import uuid

from rich.markdown import Markdown
from rich.panel import Panel

from goose.toolkit.base import Toolkit, tool


class Screen(Toolkit):
"""Provides an instructions on when and how to work with screenshots"""

@tool
def take_screenshot(self) -> str:
def take_screenshot(self, display: int = 1) -> str:
"""
Take a screenshot to assist the user in debugging or designing an app. They may need help with moving a screen element, or interacting in some way where you could do with seeing the screen.
Take a screenshot to assist the user in debugging or designing an app. They may need
help with moving a screen element, or interacting in some way where you could do with
seeing the screen.
Return:
(str) a path to the screenshot file, in the format of image: followed by the path to the file.
Args:
display (int): Display to take the screen shot in. Default is the main display (1). Must be a value greater than 1.
""" # noqa: E501
# Generate a random tmp filename for screenshot
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png"
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.jpg"
screen_capture_command = ["screencapture", "-x", "-D", str(display), filename, "-f", "jpg"]

subprocess.run(screen_capture_command, check=True, capture_output=True)

resize_command = ["sips", "--resampleWidth", "768", filename, "-s", "format", "jpeg"]
subprocess.run(resize_command, check=True, capture_output=True)

subprocess.run(["screencapture", "-x", filename])
self.notifier.log(
Panel.fit(
Markdown(f"```bash\n{' '.join(screen_capture_command)}"),
title="screen",
)
)

return f"image:{filename}"

Expand Down

0 comments on commit b9bb48e

Please sign in to comment.