-
-
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(SegmentReplayStrategy, drivers): add strategies.replay; refactor…
… adapters -> drivers + adapters (#714) * implemented * add get_active_window_data parameter include_window_data; fix ActionEvent.from_dict to handle multiple separators; add test_models.py * update get_default_prompt_adapter * add TODO * tests.openadapt.adapters -> drivers * utils.get_marked_image, .extract_code_block; .strip_backticks * working segment.py (misses final click in calculator task) * include_replay_instructions; dev_mode=False * fix test_openai.py: ValueError -> Exception * replay.py --record -> --capture * black/flake8 * remove import * INCLUDE_CURRENT_SCREENSHOT; handle mouse events without x/y * add models.Replay; print_config in replay.py
- Loading branch information
Showing
22 changed files
with
740 additions
and
100 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
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,47 @@ | ||
"""Adapter for prompting foundation models.""" | ||
|
||
from loguru import logger | ||
from typing import Type | ||
from PIL import Image | ||
|
||
|
||
from openadapt.drivers import anthropic, google, openai | ||
|
||
|
||
# Define a list of drivers in the order they should be tried | ||
DRIVER_ORDER: list[Type] = [openai, google, anthropic] | ||
|
||
|
||
def prompt( | ||
text: str, | ||
images: list[Image.Image] | None = None, | ||
system_prompt: str | None = None, | ||
) -> str: | ||
"""Attempt to fetch a prompt completion from various services in order of priority. | ||
Args: | ||
text: The main text prompt. | ||
images: list of images to include in the prompt. | ||
system_prompt: An optional system-level prompt. | ||
Returns: | ||
The result from the first successful driver. | ||
""" | ||
text = text.strip() | ||
for driver in DRIVER_ORDER: | ||
try: | ||
logger.info(f"Trying driver: {driver.__name__}") | ||
return driver.prompt(text, images=images, system_prompt=system_prompt) | ||
except Exception as e: | ||
logger.exception(e) | ||
logger.error(f"Driver {driver.__name__} failed with error: {e}") | ||
import ipdb | ||
|
||
ipdb.set_trace() | ||
continue | ||
raise Exception("All drivers failed to provide a response") | ||
|
||
|
||
if __name__ == "__main__": | ||
# This could be extended to use command-line arguments or other input methods | ||
print(prompt("Describe the solar system.")) |
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
File renamed without changes.
File renamed without changes.
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
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,16 @@ | ||
Consider the actions in the recording and states of the active window immediately | ||
before each action was taken: | ||
|
||
```json | ||
{{ action_windows }} | ||
``` | ||
|
||
Consider the attached screenshots taken immediately before each action. The order of | ||
the screenshots matches the order of the actions above. | ||
|
||
Provide a detailed natural language description of everything that happened | ||
in this recording. This description will be embedded in the context for a future prompt | ||
to replay the recording (subject to proposed modifications in natural language) on a | ||
live system, so make sure to include everything you will need to know. | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{% if include_raw_recording %} | ||
Consider the previously recorded actions: | ||
|
||
```json | ||
{{ recorded_actions }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
{% if include_raw_recording_description %} | ||
Consider the following description of the previously recorded actions: | ||
|
||
``json | ||
{{ recording_description }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
{% if include_replay_instructions %} | ||
Consider the user's proposed modifications in natural language instructions: | ||
|
||
```text | ||
{{ replay_instructions }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
{% if include_modified_recording %} | ||
Consider this updated list of actions that have been modified such that replaying them | ||
would have accomplished the user's instructions: | ||
|
||
```json | ||
{{ modified_actions }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
{% if include_modified_recording_description %} | ||
Consider the following description of the updated list of actions that have been | ||
modified such that replaying them would have accomplished the user's instructions: | ||
|
||
``json | ||
{{ modified_recording_description }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
Consider the actions you've produced (and we have played back) so far: | ||
|
||
```json | ||
{{ replayed_actions }} | ||
``` | ||
|
||
{% if include_active_window %} | ||
Consider the current active window: | ||
```json | ||
{{ current_window }} | ||
``` | ||
{% endif %} | ||
|
||
|
||
The attached image is a screenshot of the current state of the system. | ||
|
||
Provide the next action to be replayed in order to accomplish the user's replay | ||
instructions. | ||
|
||
Do NOT provide available_segment_descriptions in your response. | ||
|
||
Respond with JSON and nothing else. | ||
|
||
If you wish to terminate the recording, return an empty object. | ||
|
||
My career depends on this. Lives are at stake. |
Oops, something went wrong.