-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(action verification): implement replay action verification (#857)
* add is_action_event_complete * retry_with_exceptions in apply_replay_instructions * fix parse_code_snippet * add error_reporting.py * refactor video.py * black/flake8 * add module docstring * CHECK_ACTION_COMPLETE
- Loading branch information
Showing
11 changed files
with
225 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,13 @@ | |
import os | ||
import pathlib | ||
import shutil | ||
import webbrowser | ||
|
||
from loguru import logger | ||
from pydantic import field_validator | ||
from pydantic.fields import FieldInfo | ||
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource | ||
from PySide6.QtWidgets import QMessageBox, QPushButton | ||
import git | ||
import sentry_sdk | ||
|
||
from openadapt.build_utils import get_root_dir_path, is_running_from_executable | ||
from openadapt.build_utils import get_root_dir_path | ||
|
||
CONFIG_DEFAULTS_FILE_PATH = ( | ||
pathlib.Path(__file__).parent / "config.defaults.json" | ||
|
@@ -411,47 +407,3 @@ def print_config() -> None: | |
if not key.startswith("_") and key.isupper(): | ||
val = maybe_obfuscate(key, val) | ||
logger.info(f"{key}={val}") | ||
|
||
if config.ERROR_REPORTING_ENABLED: | ||
if is_running_from_executable(): | ||
is_reporting_branch = True | ||
else: | ||
active_branch_name = git.Repo(PARENT_DIR_PATH).active_branch.name | ||
logger.info(f"{active_branch_name=}") | ||
is_reporting_branch = ( | ||
active_branch_name == config.ERROR_REPORTING_BRANCH | ||
) | ||
logger.info(f"{is_reporting_branch=}") | ||
if is_reporting_branch: | ||
|
||
def show_alert() -> None: | ||
"""Show an alert to the user.""" | ||
msg = QMessageBox() | ||
msg.setIcon(QMessageBox.Warning) | ||
msg.setText(""" | ||
An error has occurred. The development team has been notified. | ||
Please join the discord server to get help or send an email to | ||
[email protected] | ||
""") | ||
discord_button = QPushButton("Join the discord server") | ||
discord_button.clicked.connect( | ||
lambda: webbrowser.open("https://discord.gg/yF527cQbDG") | ||
) | ||
msg.addButton(discord_button, QMessageBox.ActionRole) | ||
msg.addButton(QMessageBox.Ok) | ||
msg.exec() | ||
|
||
def before_send_event(event: Any, hint: Any) -> Any: | ||
"""Handle the event before sending it to Sentry.""" | ||
try: | ||
show_alert() | ||
except Exception: | ||
pass | ||
return event | ||
|
||
sentry_sdk.init( | ||
dsn=config.ERROR_REPORTING_DSN, | ||
traces_sample_rate=1.0, | ||
before_send=before_send_event, | ||
ignore_errors=[KeyboardInterrupt], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Module for error reporting logic.""" | ||
|
||
from typing import Any | ||
|
||
from loguru import logger | ||
from PySide6.QtGui import QIcon | ||
from PySide6.QtWidgets import QMessageBox, QPushButton | ||
import git | ||
import sentry_sdk | ||
import webbrowser | ||
|
||
from openadapt.build_utils import is_running_from_executable | ||
from openadapt.config import PARENT_DIR_PATH, config | ||
|
||
|
||
def configure_error_reporting() -> None: | ||
"""Configure error reporting.""" | ||
logger.info(f"{config.ERROR_REPORTING_ENABLED=}") | ||
if not config.ERROR_REPORTING_ENABLED: | ||
return | ||
|
||
if is_running_from_executable(): | ||
is_reporting_branch = True | ||
else: | ||
active_branch_name = git.Repo(PARENT_DIR_PATH).active_branch.name | ||
logger.info(f"{active_branch_name=}") | ||
is_reporting_branch = active_branch_name == config.ERROR_REPORTING_BRANCH | ||
logger.info(f"{is_reporting_branch=}") | ||
|
||
if is_reporting_branch: | ||
sentry_sdk.init( | ||
dsn=config.ERROR_REPORTING_DSN, | ||
traces_sample_rate=1.0, | ||
before_send=before_send_event, | ||
ignore_errors=[KeyboardInterrupt], | ||
) | ||
|
||
|
||
def show_alert() -> None: | ||
"""Show an alert to the user.""" | ||
# TODO: move to config | ||
from openadapt.app.tray import ICON_PATH | ||
|
||
msg = QMessageBox() | ||
msg.setIcon(QMessageBox.Warning) | ||
msg.setWindowIcon(QIcon(ICON_PATH)) | ||
msg.setText(""" | ||
An error has occurred. The development team has been notified. | ||
Please join the discord server to get help or send an email to | ||
[email protected] | ||
""") | ||
discord_button = QPushButton("Join the discord server") | ||
discord_button.clicked.connect( | ||
lambda: webbrowser.open("https://discord.gg/yF527cQbDG") | ||
) | ||
msg.addButton(discord_button, QMessageBox.ActionRole) | ||
msg.addButton(QMessageBox.Ok) | ||
msg.exec() | ||
|
||
|
||
def before_send_event(event: Any, hint: Any) -> Any: | ||
"""Handle the event before sending it to Sentry.""" | ||
try: | ||
show_alert() | ||
except Exception: | ||
pass | ||
return event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Consider the actions that you previously generated: | ||
|
||
```json | ||
{{ actions }} | ||
``` | ||
|
||
The attached image is a screenshot of the current state of the system, immediately | ||
after the last action in the sequence was played. | ||
|
||
Your task is to: | ||
1. Describe what you would expect to see in the screenshot after the last action in the | ||
sequence is complete, and | ||
2. Determine whether the the last action has completed by looking at the attached | ||
screenshot. For example, if you expect that the sequence of actions would result in | ||
opening a particular application, you should determine whether that application has | ||
finished opening. | ||
|
||
Respond with JSON and nothing else. The JSON should have the following keys: | ||
- "expected_state": Natural language description of what you would expect to see. | ||
- "is_complete": Boolean indicating whether the last action is complete or not. | ||
|
||
My career depends on this. Lives are at stake. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.