Skip to content

Commit

Permalink
fix: fixed screenshot() not running if generator not consumed (such a…
Browse files Browse the repository at this point in the history
…s when not last statement in codeblock)
  • Loading branch information
ErikBjare committed Oct 27, 2024
1 parent 852e6f4 commit 65bdb8a
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions gptme/tools/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import os
import subprocess
from collections.abc import Generator
from datetime import datetime
from pathlib import Path

from ..message import Message
from .base import ToolSpec


Expand All @@ -28,21 +26,15 @@ def _screenshot(path: Path) -> Path:
return path


def screenshot(path: Path | None = None) -> Generator[Message, None, None]:
def screenshot(path: Path | None = None) -> Path:
"""
Take a screenshot and save it to a file.
"""
if path is None:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
path = Path(f"screenshot_{timestamp}.png")

try:
path = _screenshot(path)
yield Message("system", f"Screenshot saved to: {path}")
except NotImplementedError as e:
yield Message("system", str(e))
except subprocess.CalledProcessError:
yield Message("system", "Failed to capture screenshot.")
return _screenshot(path)


tool = ToolSpec(
Expand Down

0 comments on commit 65bdb8a

Please sign in to comment.