-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
136 lines (100 loc) · 3.24 KB
/
run.py
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
import openai
import os
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY')
import pyautogui
import time
os_type = 'win' # 'mac'
def openApp(app):
if os_type == 'win':
pyautogui.press('win')
else:
pyautogui.hotkey('command', 'space')
time.sleep(1)
pyautogui.typewrite(app)
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
def calculate(equation):
pyautogui.typewrite(equation)
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
pyautogui.hotkey('ctrl', 'c')
def searchGoogle(searchKeyword):
pyautogui.typewrite(searchKeyword)
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
pyautogui.hotkey('ctrl', 'a')
time.sleep(1)
pyautogui.hotkey('ctrl', 'c')
time.sleep(1)
def writeMemo():
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
def complete():
exit()
def main():
calculate('9+1')
writeMemo()
searchGoogle('llava2')
writeMemo()
initial_prompt = '''
You are the Agent that determines the next action to achieve the final object.
There are three movements that you can perform. Determine the next action considering the current screen condition.
def openApp(app)
- OpenApp function lets you open the app by inserting the app name.
- You can enter only three types of app name: 'calculator', 'chrome', and 'memo'.
def calculate(equation)
- Calculate function performs calculations when you insert an equation and copies the calculation results to the clipboard.
def searchGoogle(searchKeyword)
- The searchGoogle function enters the searchKeyword into the Google search box and copies the entire search result to the clipboard.
def writeMemo()
- writeMemo function opens and pastes what is copied to the clipboard.
def complete()
- The complete function is invoked when all operations are complete and causes the process to terminate.
Sample Output 1:
Input:
Current screen status: Desktop is displayed
Final object: add 2 to 8 and find out what the value minus 3 is and paste it into Notepad
Output:
openApp('calculator')
calculate('8+2-3')
openApp('memo')
writeMemo()
complete()
Sample Output 2:
Input:
Current screen status: Calculator is on the screen
Final object: add 2 to 8 and find out what the value minus 3 is and paste it into Notepad
Output:
calculate('8+2-3')
openApp('memo')
writeMemo()
complete()
---------
'''
if __name__=='__main__':
status = input('current status: ')
objective = input('final objective: ')
current_prompt = f' \
Input: \
Current screen status: {status} \
Final objective: {objective} \
Output: \
'
prompt = initial_prompt + current_prompt
completion = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
)
output = str(completion.choices[0].message.content)
commands = output.split('\n')
for command in commands:
print(command)
eval(command)