Skip to content

Commit f4cd32f

Browse files
committedMay 9, 2024
bug fix
1 parent d29ace8 commit f4cd32f

18 files changed

+324
-279
lines changed
 

‎ufo/agent/agent.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def message_constructor(
114114
request_history: str,
115115
action_history: str,
116116
control_info: str,
117-
plan: str,
117+
plan: List[str],
118118
request: str,
119119
include_last_screenshot: bool,
120120
) -> list:
@@ -127,7 +127,7 @@ def message_constructor(
127127
:param request_history: The request history.
128128
:param action_history: The action history.
129129
:param control_info: The control information.
130-
:param plan: The plan.
130+
:param plan: The plan list.
131131
:param request: The request.
132132
:param include_last_screenshot: The flag indicating whether to include the last screenshot.
133133
:return: The prompt message.
@@ -188,7 +188,7 @@ def print_response(self, response_dict: Dict) -> None:
188188
)
189189
utils.print_with_color("Status📊: {status}".format(status=status), "blue")
190190
utils.print_with_color(
191-
"Next Plan📚: {plan}".format(plan=str(plan).replace("\\n", "\n")), "cyan"
191+
"Next Plan📚: {plan}".format(plan="\n".join(plan)), "cyan"
192192
)
193193
utils.print_with_color("Comment💬: {comment}".format(comment=comment), "green")
194194

@@ -447,7 +447,7 @@ def message_constructor(
447447
request_history: str,
448448
action_history: str,
449449
os_info: str,
450-
plan: str,
450+
plan: List[str],
451451
request: str,
452452
) -> list:
453453
"""
@@ -522,7 +522,7 @@ def print_response(self, response_dict: Dict) -> None:
522522
)
523523
utils.print_with_color("Status📊: {status}".format(status=status), "blue")
524524
utils.print_with_color(
525-
"Next Plan📚: {plan}".format(plan=str(plan).replace("\\n", "\n")), "cyan"
525+
"Next Plan📚: {plan}".format(plan="\n".join(plan)), "cyan"
526526
)
527527
utils.print_with_color("Comment💬: {comment}".format(comment=comment), "green")
528528

@@ -641,7 +641,7 @@ def message_constructor(
641641
request_history: str,
642642
action_history: str,
643643
control_info: str,
644-
plan: str,
644+
plan: List[str],
645645
request: str,
646646
include_last_screenshot: bool,
647647
) -> list:
@@ -688,7 +688,7 @@ def message_constructor(
688688
request_history: str,
689689
action_history: str,
690690
control_info: str,
691-
plan: str,
691+
plan: List[str],
692692
request: str,
693693
current_state: dict,
694694
state_diff: dict,

‎ufo/automator/ui_control/control_filter.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def inplace_append_filtered_annotation_dict(
5656
return filtered_control_dict
5757

5858
@staticmethod
59-
def get_plans(plan, topk_plan):
59+
def get_plans(plan: List[str], topk_plan: int) -> List[str]:
6060
"""
6161
Parses the given plan and returns a list of plans up to the specified topk_plan.
6262
@@ -67,8 +67,7 @@ def get_plans(plan, topk_plan):
6767
Returns:
6868
list: A list of plans up to the specified topk_plan.
6969
"""
70-
plans = str(plan).split("\n")[:topk_plan]
71-
return plans
70+
return plan[:topk_plan]
7271

7372

7473
class BasicControlFilter:
@@ -128,7 +127,7 @@ def control_filter(self, control_dicts, plans, **kwargs):
128127
pass
129128

130129
@staticmethod
131-
def plans_to_keywords(plans: list) -> list:
130+
def plans_to_keywords(plans: List[str]) -> List[str]:
132131
"""
133132
Gets keywords from the plan.
134133
We only consider the words in the plan that are alphabetic or Chinese characters.

‎ufo/config/config_dev.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DEMONSTRATION_PROMPT: "ufo/prompts/demonstration/demonstration_summary.yaml"
4747
DEMONSTRATION_SAVED_PATH: "vectordb/demonstration/"
4848

4949
API_PROMPT: "ufo/prompts/share/base/api.yaml" # The prompt for the API
50-
CLICK_API: "click" # The click API
50+
CLICK_API: "click_input" # The click API
5151
INPUT_TEXT_API: "type_keys" # The input text API
5252
INPUT_TEXT_ENTER: False # whether to press enter after typing the text
5353

‎ufo/module/basic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
ErrorState,
3232
MaxStepReachedState,
3333
NoneState,
34+
Status,
3435
StatusToStateMapper,
3536
)
3637

@@ -72,7 +73,7 @@ def __init__(
7273
self.app_agent = None
7374

7475
# Status-related properties
75-
self._status = "APP_SELECTION"
76+
self._status = Status.APP_SELECTION
7677

7778
# Application-related properties
7879
self.application = ""
@@ -267,7 +268,7 @@ def __init__(self, task: str) -> None:
267268
self.app_agent = None
268269

269270
# Status and state-related properties
270-
self._status = "APP_SELECTION"
271+
self._status = Status.APP_SELECTION
271272
self._state = StatusToStateMapper().get_appropriate_state(self._status)
272273

273274
# Application-related properties

‎ufo/module/processors/processor.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_prompt_message(self) -> None:
131131
if agent_memory.length > 0:
132132
plan = agent_memory.get_latest_item().to_dict()["Plan"]
133133
else:
134-
plan = ""
134+
plan = []
135135

136136
# Construct the prompt message for the host agent.
137137
self._prompt_message = self.host_agent.message_constructor(
@@ -438,7 +438,7 @@ def __init__(
438438
self._operation = None
439439
self._args = None
440440
self._image_url = []
441-
self.prev_plan = ""
441+
self.prev_plan = []
442442
self._control_reannotate = control_reannotate
443443
self.control_filter_factory = ControlFilterFactory()
444444
self.filtered_annotation_dict = None
@@ -790,7 +790,7 @@ def _safe_guard_judgement(self, action: str, control_text: str) -> bool:
790790
return False
791791

792792
# Handle the PENDING_AND_FINISH case
793-
elif Status.FINISH in self._plan:
793+
elif len(self._plan) > 0 and Status.FINISH in self._plan[0]:
794794
self._status = Status.FINISH
795795
return True
796796

@@ -810,9 +810,9 @@ def get_prev_plan(self) -> str:
810810
agent_memory = self.app_agent.memory
811811

812812
if agent_memory.length > 0:
813-
prev_plan = agent_memory.get_latest_item().to_dict()["Plan"].strip()
813+
prev_plan = agent_memory.get_latest_item().to_dict()["Plan"]
814814
else:
815-
prev_plan = ""
815+
prev_plan = []
816816

817817
return prev_plan
818818

@@ -861,7 +861,7 @@ def get_filtered_annotation_dict(
861861
control_filter_type = configs["CONTROL_FILTER_TYPE"]
862862
topk_plan = configs["CONTROL_FILTER_TOP_K_PLAN"]
863863

864-
if len(control_filter_type) == 0 or self.prev_plan == "":
864+
if len(control_filter_type) == 0 or self.prev_plan == []:
865865
return annotation_dict
866866

867867
control_filter_type_lower = [

‎ufo/prompter/agent_prompter.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def user_prompt_construction(
6262
request_history: List[str],
6363
action_history: List[str],
6464
control_item: List[str],
65-
prev_plan: str,
65+
prev_plan: List[str],
6666
user_request: str,
6767
retrieved_docs: str = "",
6868
) -> str:
@@ -78,7 +78,7 @@ def user_prompt_construction(
7878
action_history=json.dumps(action_history),
7979
request_history=json.dumps(request_history),
8080
control_item=json.dumps(control_item),
81-
prev_plan=prev_plan,
81+
prev_plan=json.dumps(prev_plan),
8282
user_request=user_request,
8383
retrieved_docs=retrieved_docs,
8484
)
@@ -250,7 +250,7 @@ def user_prompt_construction(
250250
request_history: List[str],
251251
action_history: List[str],
252252
control_item: List[str],
253-
prev_plan: str,
253+
prev_plan: List[str],
254254
user_request: str,
255255
retrieved_docs: str = "",
256256
) -> str:
@@ -267,7 +267,7 @@ def user_prompt_construction(
267267
action_history=json.dumps(action_history),
268268
request_history=json.dumps(request_history),
269269
control_item=json.dumps(control_item),
270-
prev_plan=prev_plan,
270+
prev_plan=json.dumps(prev_plan),
271271
user_request=user_request,
272272
retrieved_docs=retrieved_docs,
273273
)
@@ -280,7 +280,7 @@ def user_content_construction(
280280
request_history: List[str],
281281
action_history: List[str],
282282
control_item: List[str],
283-
prev_plan: str,
283+
prev_plan: List[str],
284284
user_request: str,
285285
retrieved_docs: str = "",
286286
include_last_screenshot: bool = True,
@@ -484,7 +484,7 @@ def user_prompt_construction(
484484
request_history: List[str],
485485
action_history: List[str],
486486
control_item: List[str],
487-
prev_plan: str,
487+
prev_plan: List[str],
488488
user_request: str,
489489
retrieved_docs: str = "",
490490
current_state: dict = {},
@@ -505,7 +505,7 @@ def user_prompt_construction(
505505
action_history=json.dumps(action_history),
506506
request_history=json.dumps(request_history),
507507
control_item=json.dumps(control_item),
508-
prev_plan=prev_plan,
508+
prev_plan=json.dumps(prev_plan),
509509
user_request=user_request,
510510
retrieved_docs=retrieved_docs,
511511
current_state=json.dumps(current_state),
@@ -520,7 +520,7 @@ def user_content_construction(
520520
request_history: List[str],
521521
action_history: List[str],
522522
control_item: List[str],
523-
prev_plan: str,
523+
prev_plan: List[str],
524524
user_request: str,
525525
retrieved_docs: str = "",
526526
current_state: dict = {},

‎ufo/prompts/examples/lite/nonvisual/app_agent_example.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ example1:
1818
{"button": "left", "double": false}
1919
Status: |-
2020
CONTINUE
21-
Plan: |-
22-
(1) Input the email address of the receiver.
23-
(2) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
24-
(3) Input the content of the email. I need to input 'Dear Jack,\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\nBest regards,\nZac'.
25-
(4) Click the Send button to send the email.
21+
Plan:
22+
- (1) Input the email address of the receiver.
23+
- (2) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
24+
- (3) Input the content of the email. I need to input 'Dear Jack,\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\nBest regards,\nZac'.
25+
- (4) Click the Send button to send the email.
2626
Comment: |-
2727
After I click the New Email button, the New Email window will be opened and available for composing the email.
2828
Tips: |-

‎ufo/prompts/examples/lite/nonvisual/host_agent_example.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ example1:
1515
Mail - Outlook - Zac
1616
Status: |-
1717
CONTINUE
18-
Plan: |-
19-
(1) Open the windows of outlook application.
20-
(2) Input the email address of the receiver.
21-
(3) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
22-
(4) Input the content of the email. I need to input 'Dear Jack,\\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\\nBest regards,\\nZac'.
23-
(5) Click the Send button to send the email. This action is sensitive and need to be confirmed by the user.
18+
Plan:
19+
- (1) Open the windows of outlook application.
20+
- (2) Input the email address of the receiver.
21+
- (3) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
22+
- (4) Input the content of the email. I need to input 'Dear Jack,\\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\\nBest regards,\\nZac'.
23+
- (5) Click the Send button to send the email. This action is sensitive and need to be confirmed by the user.
2424
Comment: |-
2525
It is time to open the outlook application!
2626

‎ufo/prompts/examples/lite/visual/app_agent_example.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ example1:
1818
{"button": "left", "double": false}
1919
Status: |-
2020
CONTINUE
21-
Plan: |-
22-
(1) Input the email address of the receiver.
23-
(2) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
24-
(3) Input the content of the email. I need to input 'Dear Jack,\\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\\nBest regards,\\nZac'.
25-
(4) Click the Send button to send the email.
21+
Plan:
22+
- (1) Input the email address of the receiver.
23+
- (2) Input the title of the email. I need to input 'Thanks for your contribution on the open source.'.
24+
- (3) Input the content of the email. I need to input 'Dear Jack,\\nI hope this message finds you well. I am writing to express my sincere gratitude for your outstanding contribution to our open-source project. Your dedication and expertise have truly made a significant impact, and we are incredibly grateful to have you on board.\\nYour commitment to the open-source community has not gone unnoticed, and your recent contributions have been instrumental in enhancing the functionality and quality of our project. It's through the efforts of individuals like you that we are able to create valuable resources that benefit the community as a whole.\\nYour code reviews, bug fixes, and innovative ideas have not only improved the project but have also inspired others to contribute their best. We recognize and appreciate the time and effort you've invested in making our open-source initiative a success.\\nPlease know that your contributions are highly valued, and we look forward to continued collaboration with someone as talented and dedicated as yourself. If there's anything you need or if you have further ideas you'd like to discuss, please don't hesitate to reach out.\\nOnce again, thank you for your exceptional contributions. We are fortunate to have you as part of our open-source community.\\nBest regards,\\nZac'.
25+
- (4) Click the Send button to send the email.
2626
Comment: |-
2727
After I click the New Email button, the New Email window will be opened and available for composing the email.
2828
Tips: |-

0 commit comments

Comments
 (0)
Please sign in to comment.