Skip to content

Commit

Permalink
fix bug for the last screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
vyokky committed Oct 29, 2024
1 parent 7ccf3b4 commit 6e4ee27
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
81 changes: 79 additions & 2 deletions ufo/automator/ui_control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def set_edit_text(self, params: Dict[str, str]) -> str:
args = {"text": text}
else:
method_name = "type_keys"
text = text.replace("\n", "{ENTER}")
text = text.replace("\t", "{TAB}")

# Transform the text according to the tags.
text = TextTransformer.transform_text(text, "all")

args = {"keys": text, "pause": inter_key_pause, "with_spaces": True}
try:
Expand Down Expand Up @@ -622,3 +623,79 @@ def name(cls) -> str:
:return: The name of the atomic command.
"""
return ""


class TextTransformer:
"""
The text transformer class.
"""

@staticmethod
def transform_text(text: str, transform_tag: str) -> str:
"""
Transform the text.
:param text: The text to transform.
:param transform_tag: The tag to transform.
:return: The transformed text.
"""

if transform_tag == "all":
transform_tag = "+\n\t^%"

if "\n" in transform_tag:
text = TextTransformer.transform_enter(text)
if "\t" in transform_tag:
text = TextTransformer.transform_tab(text)
if "+" in transform_tag:
text = TextTransformer.transform_plus(text)
if "^" in transform_tag:
text = TextTransformer.transform_caret(text)
if "%" in transform_tag:
text = TextTransformer.transform_percent(text)

return text

@staticmethod
def transform_enter(text: str) -> str:
"""
Transform the enter key.
:param text: The text to transform.
:return: The transformed text.
"""
return text.replace("\n", "{ENTER}")

@staticmethod
def transform_tab(text: str) -> str:
"""
Transform the tab key.
:param text: The text to transform.
:return: The transformed text.
"""
return text.replace("\t", "{TAB}")

@staticmethod
def transform_plus(text: str) -> str:
"""
Transform the plus key.
:param text: The text to transform.
:return: The transformed text.
"""
return text.replace("+", "{+}")

@staticmethod
def transform_caret(text: str) -> str:
"""
Transform the caret key.
:param text: The text to transform.
:return: The transformed text.
"""
return text.replace("^", "{^}")

@staticmethod
def transform_percent(text: str) -> str:
"""
Transform the percent key.
:param text: The text to transform.
:return: The transformed text.
"""
return text.replace("%", "{%}")
4 changes: 2 additions & 2 deletions ufo/prompter/agent_prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def user_content_construction(
if include_last_screenshot:
screenshot_text += ["Screenshot for the last step:"]

screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"]
screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"]

for i, image in enumerate(image_list):
user_content.append({"type": "text", "text": screenshot_text[i]})
Expand Down Expand Up @@ -580,7 +580,7 @@ def user_content_construction(
if include_last_screenshot:
screenshot_text += ["Screenshot for the last step:"]

screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"]
screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"]

for i, image in enumerate(image_list):
user_content.append({"type": "text", "text": screenshot_text[i]})
Expand Down

0 comments on commit 6e4ee27

Please # to comment.