-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompting.py
More file actions
146 lines (118 loc) · 4.18 KB
/
Copy pathprompting.py
File metadata and controls
146 lines (118 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from action.base import Action, ActionResult, History
from action.qwen_action import AtlasActionmodel, QwenVLActionModel
from planner.base import Plan
from planner.qwen_planner import QwenVLPlanner
from prompts.action_prompts import SYS_PROMPT_MID as MIDDLEMAN
from prompts.planner_prompts import SYS_PROMPT_COT as PLANNER_COT
# TODO: take image as bytes
def take_action(
subtask: str,
history: History,
image_path: str,
task: str,
plan: Plan,
context: str,
task_description: str,
) -> None:
"""
Performs an action on the current screen given an instruction
@param subtask: Subtask at hand from the original plan
@param history: Actions and results until this point
@image_path: Path to the image upon which the interaction will happen
@task: Objective
@param plan: Plan layed out by the planner beforehand
@context: Bussiness context
@task_description: Detailed description of the task at hand, from a process POV
"""
middle_model = QwenVLActionModel("Qwen/Qwen2-VL-7B-Instruct-GPTQ-Int4")
prompt = f"""
**task**: {task}
**plan**: {plan.steps}.
**Plan reasoning**: {plan.reasoning}
**history**:
{history}
**result of the last executed action**: {history.last_result}
**task description**:
{task_description}
**context description**:
{context}
**current subtask**: {subtask}
"""
action: Action = middle_model.action(
MIDDLEMAN,
prompt,
image=image_path,
)
action_model = AtlasActionmodel("OS-Copilot/OS-Atlas-Base-7B")
grounding: Action = action_model.action(
None,
f'In this UI screenshot, what is the position of the element corresponding to the command "{action.action_target}" (with bbox)?',
image=image_path,
)
grounding.action = action.action
grounding.action_target = action.action_target
history.append(grounding, ActionResult.PENDING)
def plan_task(
task: str,
image_path: str,
context: str,
task_description: str,
) -> Plan:
"""
Plans ahead the steps to carry out to complete the given task
@param task: Task to complete on the user's computer
@image_path: Path to the image upon which the interaction will happen
@context: Bussiness context
@task_description: Detailed description of the task at hand, from a process POV
@returns plan: Plan object
"""
# prompt = """
# **Task Description**: Register a client with email \"example@email.com\" and password \"password123\".
# **Contextual Information**:
# - Users must have first sent an email to the company attaching their NIF, which must be included in the registration
# - Once registered, we respond back to the email sent by the user confirming that the registration was done correctly
# """
# This prompt now resembles a process description
planner = QwenVLPlanner("Qwen/Qwen2-VL-7B-Instruct-GPTQ-Int4")
prompt = f"""
**Task Description**: {task}.
**Contextual Information**:
{task_description}
"""
plan: Plan = planner.plan(
PLANNER_COT.format(context=context),
prompt,
image=image_path,
)
return plan
if __name__ == "__main__":
task: str = 'Register a client with email "example@email.com" and password "password123"'
context: str = """
- The organization operates in a legal advisory setting.
- Users are registered in the Odoo system.
- Chrome is used as the main browser
- Gmail is used as the email client
"""
task_description: str = """
- First, check email from user to see if a NIF was sent
- If it was, register user, else respond to email and stop process
- Register the user in Odoo
- Send email back to user confirming registration
"""
history = History()
plan = plan_task(
task,
image_path=".resources/A_720p.png",
context=context,
task_description=task_description,
)
take_action(
plan.steps[0],
history,
image_path=".resources/A_720p.png",
task=task,
plan=plan,
context=context,
task_description=task_description,
)
print("\n-----------------------\n", history)