Spaces:
Sleeping
Sleeping
lordspline
commited on
Commit
•
2ab9625
1
Parent(s):
5c4f5c9
Upload folder using huggingface_hub
Browse files- agent.py +27 -27
- app.py +10 -1
- index.html +584 -0
agent.py
CHANGED
@@ -102,7 +102,7 @@ class DevOn:
|
|
102 |
# time.sleep(1)
|
103 |
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
104 |
# self.editor_image = self.programmer["screenshot"]
|
105 |
-
if self.programmer.status
|
106 |
break
|
107 |
|
108 |
self.editor_image = self.multion.sessions.screenshot(
|
@@ -184,35 +184,35 @@ class DevOn:
|
|
184 |
include_screenshot=True,
|
185 |
)
|
186 |
print(self.programmer)
|
187 |
-
if self.programmer.status == "NOT SURE":
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
else:
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
# time.sleep(1)
|
213 |
# self.editor_image = self.programmer["screenshot"]
|
214 |
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
215 |
-
if self.programmer.status
|
216 |
break
|
217 |
self.editor_image = self.multion.sessions.screenshot(
|
218 |
session_id=self.programmer.session_id
|
|
|
102 |
# time.sleep(1)
|
103 |
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
104 |
# self.editor_image = self.programmer["screenshot"]
|
105 |
+
if self.programmer.status in ["DONE", "NOT SURE"]:
|
106 |
break
|
107 |
|
108 |
self.editor_image = self.multion.sessions.screenshot(
|
|
|
184 |
include_screenshot=True,
|
185 |
)
|
186 |
print(self.programmer)
|
187 |
+
# if self.programmer.status == "NOT SURE":
|
188 |
+
# self.messages.append(
|
189 |
+
# {
|
190 |
+
# "role": "user",
|
191 |
+
# "content": "The Programmer says: {message}\n\nYour next reply will go to the programmer.".format(
|
192 |
+
# message=self.programmer.message
|
193 |
+
# ),
|
194 |
+
# }
|
195 |
+
# )
|
196 |
+
# chat_completion = self.client.chat.completions.create(
|
197 |
+
# messages=self.prepare_messages(),
|
198 |
+
# model="gpt-4-vision-preview",
|
199 |
+
# # max_tokens=200,
|
200 |
+
# )
|
201 |
+
# action_arg = chat_completion.choices[0].message.content
|
202 |
+
# self.messages.append({"role": "assistant", "content": action_arg})
|
203 |
+
# else:
|
204 |
+
self.messages.append(
|
205 |
+
{
|
206 |
+
"role": "user",
|
207 |
+
"content": "The Programmer says: {message}".format(
|
208 |
+
message=self.programmer.message
|
209 |
+
),
|
210 |
+
}
|
211 |
+
)
|
212 |
# time.sleep(1)
|
213 |
# self.editor_image = self.programmer["screenshot"]
|
214 |
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
215 |
+
if self.programmer.status in ["DONE", "NOT SURE"]:
|
216 |
break
|
217 |
self.editor_image = self.multion.sessions.screenshot(
|
218 |
session_id=self.programmer.session_id
|
app.py
CHANGED
@@ -3,6 +3,8 @@ import os
|
|
3 |
import time
|
4 |
from agent import DevOn
|
5 |
|
|
|
|
|
6 |
image_temp = "https://miro.medium.com/v2/resize:fit:1200/0*n-2bW82Z6m6U2bij.jpeg"
|
7 |
# devon = DevOn(
|
8 |
# editor_image=image_temp, browser_image=image_temp, scratchpad_image=image_temp
|
@@ -54,6 +56,10 @@ def bot(history):
|
|
54 |
)
|
55 |
|
56 |
for r in devon.run(history[-1][0]):
|
|
|
|
|
|
|
|
|
57 |
text, editor_image, browser_image, scratchpad_image = r
|
58 |
if type(text) == str:
|
59 |
history.append((None, text))
|
@@ -87,6 +93,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
87 |
placeholder="Enter message or upload file...",
|
88 |
show_label=False,
|
89 |
)
|
|
|
90 |
with gr.Column():
|
91 |
if devon:
|
92 |
editor_view = gr.Image(
|
@@ -129,8 +136,10 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
129 |
replit_email_in.change(replit_email_update, replit_email_in)
|
130 |
replit_password_in.change(replit_password_update, replit_password_in)
|
131 |
|
|
|
|
|
132 |
# chatbot.like(print_like_dislike, None, None)
|
133 |
|
134 |
if __name__ == "__main__":
|
135 |
demo.queue()
|
136 |
-
demo.launch()
|
|
|
3 |
import time
|
4 |
from agent import DevOn
|
5 |
|
6 |
+
start_time = time.time()
|
7 |
+
|
8 |
image_temp = "https://miro.medium.com/v2/resize:fit:1200/0*n-2bW82Z6m6U2bij.jpeg"
|
9 |
# devon = DevOn(
|
10 |
# editor_image=image_temp, browser_image=image_temp, scratchpad_image=image_temp
|
|
|
56 |
)
|
57 |
|
58 |
for r in devon.run(history[-1][0]):
|
59 |
+
curr_time = time.time()
|
60 |
+
print(curr_time - start_time)
|
61 |
+
if curr_time - start_time >= 300:
|
62 |
+
break
|
63 |
text, editor_image, browser_image, scratchpad_image = r
|
64 |
if type(text) == str:
|
65 |
history.append((None, text))
|
|
|
93 |
placeholder="Enter message or upload file...",
|
94 |
show_label=False,
|
95 |
)
|
96 |
+
terminate = gr.Button("Terminate")
|
97 |
with gr.Column():
|
98 |
if devon:
|
99 |
editor_view = gr.Image(
|
|
|
136 |
replit_email_in.change(replit_email_update, replit_email_in)
|
137 |
replit_password_in.change(replit_password_update, replit_password_in)
|
138 |
|
139 |
+
terminate.click(fn=None, inputs=None, outputs=None, cancels=[bot_msg])
|
140 |
+
|
141 |
# chatbot.like(print_like_dislike, None, None)
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
demo.queue()
|
145 |
+
demo.launch(debug=True)
|
index.html
ADDED
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
<html>
|
4 |
+
<head>
|
5 |
+
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
6 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<gradio-lite>
|
10 |
+
|
11 |
+
<gradio-requirements>
|
12 |
+
multion
|
13 |
+
openai
|
14 |
+
python-dotenv
|
15 |
+
pyodide-http
|
16 |
+
</gradio-requirements>
|
17 |
+
|
18 |
+
<gradio-file name="app.py" entrypoint>
|
19 |
+
import pyodide_http
|
20 |
+
pyodide_http.patch_all()
|
21 |
+
import gradio as gr
|
22 |
+
import os
|
23 |
+
import time
|
24 |
+
from agent import DevOn
|
25 |
+
|
26 |
+
image_temp = "https://miro.medium.com/v2/resize:fit:1200/0*n-2bW82Z6m6U2bij.jpeg"
|
27 |
+
# devon = DevOn(
|
28 |
+
# editor_image=image_temp, browser_image=image_temp, scratchpad_image=image_temp
|
29 |
+
# )
|
30 |
+
devon = None
|
31 |
+
multion_api_key = ""
|
32 |
+
openai_api_key = ""
|
33 |
+
replit_email = ""
|
34 |
+
replit_password = ""
|
35 |
+
|
36 |
+
|
37 |
+
def add_message(history, message):
|
38 |
+
for x in message["files"]:
|
39 |
+
history.append(((x,), None))
|
40 |
+
if message["text"] is not None:
|
41 |
+
history.append((message["text"], None))
|
42 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
43 |
+
|
44 |
+
|
45 |
+
def multion_api_key_update(x):
|
46 |
+
global multion_api_key
|
47 |
+
multion_api_key = x
|
48 |
+
|
49 |
+
|
50 |
+
def openai_api_key_update(x):
|
51 |
+
global openai_api_key
|
52 |
+
openai_api_key = x
|
53 |
+
|
54 |
+
|
55 |
+
def replit_email_update(x):
|
56 |
+
global replit_email
|
57 |
+
replit_email = x
|
58 |
+
|
59 |
+
|
60 |
+
def replit_password_update(x):
|
61 |
+
global replit_password
|
62 |
+
replit_password = x
|
63 |
+
|
64 |
+
|
65 |
+
def bot(history):
|
66 |
+
devon = DevOn(
|
67 |
+
editor_image=image_temp,
|
68 |
+
browser_image=image_temp,
|
69 |
+
scratchpad_image=image_temp,
|
70 |
+
multion_api_key=multion_api_key,
|
71 |
+
openai_api_key=openai_api_key,
|
72 |
+
replit_email=replit_email,
|
73 |
+
replit_password=replit_password,
|
74 |
+
)
|
75 |
+
|
76 |
+
for r in devon.run(history[-1][0]):
|
77 |
+
text, editor_image, browser_image, scratchpad_image = r
|
78 |
+
if type(text) == str:
|
79 |
+
history.append((None, text))
|
80 |
+
if editor_image is None:
|
81 |
+
editor_image = devon.editor_image
|
82 |
+
browser_image = devon.browser_image
|
83 |
+
scratchpad_image = devon.scratchpad_image
|
84 |
+
yield history, editor_image, browser_image, scratchpad_image
|
85 |
+
|
86 |
+
|
87 |
+
with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
88 |
+
with gr.Row():
|
89 |
+
with gr.Column():
|
90 |
+
multion_api_key_in = gr.Textbox(label="MultiOn API Key")
|
91 |
+
openai_api_key_in = gr.Textbox(label="OpenAI API Key")
|
92 |
+
with gr.Column():
|
93 |
+
replit_email_in = gr.Textbox(label="Replit Email")
|
94 |
+
replit_password_in = gr.Textbox(label="Replit Password")
|
95 |
+
with gr.Row():
|
96 |
+
with gr.Column():
|
97 |
+
chatbot = gr.Chatbot(
|
98 |
+
[], elem_id="chatbot", bubble_full_width=False, height=300
|
99 |
+
)
|
100 |
+
|
101 |
+
chat_input = gr.MultimodalTextbox(
|
102 |
+
value={
|
103 |
+
"text": "benchmark the perplexity api's resposne time with the api key abcdef"
|
104 |
+
},
|
105 |
+
interactive=True,
|
106 |
+
file_types=["image"],
|
107 |
+
placeholder="Enter message or upload file...",
|
108 |
+
show_label=False,
|
109 |
+
)
|
110 |
+
with gr.Column():
|
111 |
+
if devon:
|
112 |
+
editor_view = gr.Image(
|
113 |
+
devon.editor_image,
|
114 |
+
label="Editor",
|
115 |
+
)
|
116 |
+
else:
|
117 |
+
editor_view = gr.Image()
|
118 |
+
with gr.Row():
|
119 |
+
with gr.Column():
|
120 |
+
if devon:
|
121 |
+
browser_view = gr.Image(
|
122 |
+
devon.browser_image,
|
123 |
+
label="Browser",
|
124 |
+
)
|
125 |
+
else:
|
126 |
+
browser_view = gr.Image()
|
127 |
+
with gr.Column():
|
128 |
+
if devon:
|
129 |
+
scratchpad_view = gr.Image(
|
130 |
+
devon.scratchpad_image,
|
131 |
+
label="Scratchpad",
|
132 |
+
)
|
133 |
+
else:
|
134 |
+
scratchpad_view = gr.Image()
|
135 |
+
|
136 |
+
chat_msg = chat_input.submit(
|
137 |
+
add_message, [chatbot, chat_input], [chatbot, chat_input]
|
138 |
+
)
|
139 |
+
bot_msg = chat_msg.then(
|
140 |
+
bot,
|
141 |
+
[chatbot],
|
142 |
+
[chatbot, editor_view, browser_view, scratchpad_view],
|
143 |
+
api_name="bot_response",
|
144 |
+
)
|
145 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
146 |
+
|
147 |
+
multion_api_key_in.change(multion_api_key_update, multion_api_key_in)
|
148 |
+
openai_api_key_in.change(openai_api_key_update, openai_api_key_in)
|
149 |
+
replit_email_in.change(replit_email_update, replit_email_in)
|
150 |
+
replit_password_in.change(replit_password_update, replit_password_in)
|
151 |
+
|
152 |
+
# chatbot.like(print_like_dislike, None, None)
|
153 |
+
|
154 |
+
if __name__ == "__main__":
|
155 |
+
demo.queue()
|
156 |
+
demo.launch()
|
157 |
+
</gradio-file>
|
158 |
+
|
159 |
+
<gradio-file name="agent.py" >
|
160 |
+
from openai import OpenAI
|
161 |
+
from prompts import orchestrator_prompt
|
162 |
+
from prompts import programmer_notes
|
163 |
+
from prompts import notetaker_notes
|
164 |
+
from dotenv import load_dotenv
|
165 |
+
import time
|
166 |
+
import multion
|
167 |
+
from multion.client import MultiOn
|
168 |
+
import os
|
169 |
+
|
170 |
+
load_dotenv(".env.local")
|
171 |
+
|
172 |
+
# replit_email = os.getenv("REPLIT_EMAIL")
|
173 |
+
# replit_password = os.getenv("REPLIT_PASSWORD")
|
174 |
+
|
175 |
+
# multion_api_key = os.getenv("MULTION_API_KEY")
|
176 |
+
# multion.login(use_api=True, multion_api_key=multion_api_key)
|
177 |
+
|
178 |
+
# runpod_url = os.getenv("RUNPOD_URL")
|
179 |
+
|
180 |
+
image_temp = "https://miro.medium.com/v2/resize:fit:1200/0*n-2bW82Z6m6U2bij.jpeg"
|
181 |
+
|
182 |
+
|
183 |
+
class DevOn:
|
184 |
+
def __init__(
|
185 |
+
self,
|
186 |
+
editor_image,
|
187 |
+
browser_image,
|
188 |
+
scratchpad_image,
|
189 |
+
multion_api_key,
|
190 |
+
openai_api_key,
|
191 |
+
replit_email,
|
192 |
+
replit_password,
|
193 |
+
):
|
194 |
+
print(multion_api_key, openai_api_key)
|
195 |
+
self.editor_image = editor_image
|
196 |
+
self.browser_image = browser_image
|
197 |
+
self.scratchpad_image = scratchpad_image
|
198 |
+
self.local = os.getenv("WHERE_EXECUTE") == "local"
|
199 |
+
|
200 |
+
self.multion = MultiOn(api_key=multion_api_key)
|
201 |
+
|
202 |
+
self.replit_email = replit_email
|
203 |
+
self.replit_password = replit_password
|
204 |
+
|
205 |
+
self.programmer = self.multion.sessions.create(
|
206 |
+
url="https://replit.com/login", local=self.local, include_screenshot=True
|
207 |
+
)
|
208 |
+
self.programmer_logged_in = False
|
209 |
+
# self.editor_image = self.programmer.screenshot
|
210 |
+
self.editor_image = self.multion.sessions.screenshot(
|
211 |
+
session_id=self.programmer.session_id
|
212 |
+
).screenshot
|
213 |
+
print(self.editor_image)
|
214 |
+
time.sleep(1)
|
215 |
+
# print(self.programmer)
|
216 |
+
|
217 |
+
self.researcher = self.multion.sessions.create(
|
218 |
+
url="https://www.google.com", local=self.local, include_screenshot=True
|
219 |
+
)
|
220 |
+
# self.browser_image = self.researcher.screenshot
|
221 |
+
self.browser_image = self.multion.sessions.screenshot(
|
222 |
+
session_id=self.researcher.session_id
|
223 |
+
).screenshot
|
224 |
+
time.sleep(1)
|
225 |
+
|
226 |
+
self.notetaker = self.multion.sessions.create(
|
227 |
+
url="https://anotepad.com/", local=self.local, include_screenshot=True
|
228 |
+
)
|
229 |
+
# self.scratchpad_image = self.notetaker.screenshot
|
230 |
+
self.scratchpad_image = self.multion.sessions.screenshot(
|
231 |
+
session_id=self.notetaker.session_id
|
232 |
+
).screenshot
|
233 |
+
time.sleep(1)
|
234 |
+
|
235 |
+
self.done = True
|
236 |
+
self.task = ""
|
237 |
+
self.plan = ""
|
238 |
+
self.messages = []
|
239 |
+
self.client = OpenAI(api_key=openai_api_key)
|
240 |
+
|
241 |
+
def programmer_login(self):
|
242 |
+
if self.local:
|
243 |
+
cmd = "Create a new Python REPL."
|
244 |
+
else:
|
245 |
+
cmd = "Log in with the email {email} and the password {password}. Then create a new Python REPL.".format(
|
246 |
+
email=self.replit_email, password=self.replit_password
|
247 |
+
)
|
248 |
+
while True:
|
249 |
+
self.programmer = self.multion.sessions.step(
|
250 |
+
self.programmer.session_id,
|
251 |
+
cmd=cmd + "\n\n" + programmer_notes,
|
252 |
+
url="https://replit.com/login",
|
253 |
+
include_screenshot=True,
|
254 |
+
)
|
255 |
+
print(self.programmer)
|
256 |
+
print(
|
257 |
+
self.multion.sessions.screenshot(
|
258 |
+
session_id=self.programmer.session_id
|
259 |
+
).screenshot
|
260 |
+
)
|
261 |
+
# time.sleep(1)
|
262 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
263 |
+
# self.editor_image = self.programmer["screenshot"]
|
264 |
+
if self.programmer.status == "DONE":
|
265 |
+
break
|
266 |
+
|
267 |
+
self.editor_image = self.multion.sessions.screenshot(
|
268 |
+
session_id=self.programmer.session_id
|
269 |
+
).screenshot
|
270 |
+
time.sleep(1)
|
271 |
+
|
272 |
+
def prepare_messages(self):
|
273 |
+
messages = [
|
274 |
+
{"role": "user", "content": orchestrator_prompt},
|
275 |
+
{
|
276 |
+
"role": "user",
|
277 |
+
"content": "The Task given to you is: {task}".format(task=self.task),
|
278 |
+
},
|
279 |
+
{
|
280 |
+
"role": "user",
|
281 |
+
"content": "The current Plan state is: {plan}".format(plan=""),
|
282 |
+
},
|
283 |
+
]
|
284 |
+
for message in self.messages:
|
285 |
+
messages.append(message)
|
286 |
+
|
287 |
+
messages.append(
|
288 |
+
{
|
289 |
+
"role": "user",
|
290 |
+
"content": [
|
291 |
+
{
|
292 |
+
"type": "text",
|
293 |
+
"text": "This is the current state of the Programmer Intern.",
|
294 |
+
},
|
295 |
+
{"type": "image_url", "image_url": {"url": self.editor_image}},
|
296 |
+
],
|
297 |
+
}
|
298 |
+
)
|
299 |
+
messages.append(
|
300 |
+
{
|
301 |
+
"role": "user",
|
302 |
+
"content": [
|
303 |
+
{
|
304 |
+
"type": "text",
|
305 |
+
"text": "This is the current state of the Researcher Intern.",
|
306 |
+
},
|
307 |
+
{"type": "image_url", "image_url": {"url": self.browser_image}},
|
308 |
+
],
|
309 |
+
}
|
310 |
+
)
|
311 |
+
messages.append(
|
312 |
+
{
|
313 |
+
"role": "user",
|
314 |
+
"content": [
|
315 |
+
{
|
316 |
+
"type": "text",
|
317 |
+
"text": "This is the current state of the Notetaker Intern.",
|
318 |
+
},
|
319 |
+
{"type": "image_url", "image_url": {"url": self.scratchpad_image}},
|
320 |
+
],
|
321 |
+
}
|
322 |
+
)
|
323 |
+
return messages
|
324 |
+
|
325 |
+
def execute_action(self, action):
|
326 |
+
|
327 |
+
action_func = action.split(" ", 1)[0]
|
328 |
+
|
329 |
+
if action_func == "submit":
|
330 |
+
self.done = True
|
331 |
+
return
|
332 |
+
elif action_func == "update_plan":
|
333 |
+
action_arg = action.split(" ", 1)[1]
|
334 |
+
self.plan = action_arg
|
335 |
+
return
|
336 |
+
elif action_func == "programmer":
|
337 |
+
action_arg = action.split(" ", 1)[1]
|
338 |
+
while True:
|
339 |
+
self.programmer = self.multion.sessions.step(
|
340 |
+
self.programmer.session_id,
|
341 |
+
cmd=action_arg + "\n\n" + programmer_notes,
|
342 |
+
url="https://replit.com/login",
|
343 |
+
include_screenshot=True,
|
344 |
+
)
|
345 |
+
print(self.programmer)
|
346 |
+
if self.programmer.status == "NOT SURE":
|
347 |
+
self.messages.append(
|
348 |
+
{
|
349 |
+
"role": "user",
|
350 |
+
"content": "The Programmer says: {message}\n\nYour next reply will go to the programmer.".format(
|
351 |
+
message=self.programmer.message
|
352 |
+
),
|
353 |
+
}
|
354 |
+
)
|
355 |
+
chat_completion = self.client.chat.completions.create(
|
356 |
+
messages=self.prepare_messages(),
|
357 |
+
model="gpt-4-vision-preview",
|
358 |
+
# max_tokens=200,
|
359 |
+
)
|
360 |
+
action_arg = chat_completion.choices[0].message.content
|
361 |
+
self.messages.append({"role": "assistant", "content": action_arg})
|
362 |
+
else:
|
363 |
+
self.messages.append(
|
364 |
+
{
|
365 |
+
"role": "user",
|
366 |
+
"content": "The Programmer says: {message}".format(
|
367 |
+
message=self.programmer.message
|
368 |
+
),
|
369 |
+
}
|
370 |
+
)
|
371 |
+
# time.sleep(1)
|
372 |
+
# self.editor_image = self.programmer["screenshot"]
|
373 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
374 |
+
if self.programmer.status == "DONE":
|
375 |
+
break
|
376 |
+
self.editor_image = self.multion.sessions.screenshot(
|
377 |
+
session_id=self.programmer.session_id
|
378 |
+
).screenshot
|
379 |
+
print(self.editor_image)
|
380 |
+
time.sleep(1)
|
381 |
+
return
|
382 |
+
elif action_func == "researcher":
|
383 |
+
action_arg = action.split(" ", 1)[1]
|
384 |
+
while True:
|
385 |
+
self.researcher = self.multion.sessions.step(
|
386 |
+
self.researcher.session_id,
|
387 |
+
cmd=action_arg,
|
388 |
+
url="https://www.google.com",
|
389 |
+
include_screenshot=True,
|
390 |
+
)
|
391 |
+
print(self.researcher)
|
392 |
+
self.messages.append(
|
393 |
+
{
|
394 |
+
"role": "user",
|
395 |
+
"content": "The Researcher says: {message}".format(
|
396 |
+
message=self.researcher.message
|
397 |
+
),
|
398 |
+
}
|
399 |
+
)
|
400 |
+
# time.sleep(1)
|
401 |
+
# self.browser_image = self.researcher["screenshot"]
|
402 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
403 |
+
if self.researcher.status == "DONE":
|
404 |
+
break
|
405 |
+
self.browser_image = self.multion.sessions.screenshot(
|
406 |
+
session_id=self.researcher.session_id
|
407 |
+
).screenshot
|
408 |
+
print(self.browser_image)
|
409 |
+
time.sleep(1)
|
410 |
+
return
|
411 |
+
elif action_func == "notetaker":
|
412 |
+
action_arg = action.split(" ", 1)[1]
|
413 |
+
while True:
|
414 |
+
self.notetaker = self.multion.sessions.step(
|
415 |
+
self.notetaker.session_id,
|
416 |
+
cmd=action_arg + "\n\n" + notetaker_notes,
|
417 |
+
url="https://anotepad.com/",
|
418 |
+
include_screenshot=True,
|
419 |
+
)
|
420 |
+
print(self.notetaker)
|
421 |
+
self.messages.append(
|
422 |
+
{
|
423 |
+
"role": "user",
|
424 |
+
"content": "The Notetaker says: {message}".format(
|
425 |
+
message=self.notetaker.message
|
426 |
+
),
|
427 |
+
}
|
428 |
+
)
|
429 |
+
# time.sleep(1)
|
430 |
+
# self.scratchpad_image = self.notetaker["screenshot"]
|
431 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
432 |
+
if self.notetaker.status == "DONE":
|
433 |
+
break
|
434 |
+
self.scratchpad_image = self.multion.sessions.screenshot(
|
435 |
+
session_id=self.notetaker.session_id
|
436 |
+
).screenshot
|
437 |
+
print(self.scratchpad_image)
|
438 |
+
time.sleep(1)
|
439 |
+
return
|
440 |
+
elif action_func == "clarify":
|
441 |
+
action_arg = action.split(" ", 1)[1]
|
442 |
+
return
|
443 |
+
|
444 |
+
def orchestrator(self):
|
445 |
+
if not self.programmer_logged_in:
|
446 |
+
self.programmer_login()
|
447 |
+
self.programmer_logged_in = True
|
448 |
+
messages = self.prepare_messages()
|
449 |
+
chat_completion = self.client.chat.completions.create(
|
450 |
+
messages=messages,
|
451 |
+
model="gpt-4-vision-preview",
|
452 |
+
# max_tokens=200,
|
453 |
+
)
|
454 |
+
response = chat_completion.choices[0].message.content
|
455 |
+
action, explanation = response.split("Explanation: ", 1)
|
456 |
+
action = action.split("Action: ", 1)[1]
|
457 |
+
|
458 |
+
self.messages.append({"role": "assistant", "content": response})
|
459 |
+
self.messages.append(
|
460 |
+
{
|
461 |
+
"role": "user",
|
462 |
+
"content": "The current Plan state is: {plan}".format(plan=self.plan),
|
463 |
+
}
|
464 |
+
)
|
465 |
+
print(self.messages)
|
466 |
+
|
467 |
+
self.execute_action(action)
|
468 |
+
|
469 |
+
# temp
|
470 |
+
# self.done = True
|
471 |
+
return explanation
|
472 |
+
|
473 |
+
def run(self, prompt):
|
474 |
+
self.done = False
|
475 |
+
self.task = prompt
|
476 |
+
while not self.done:
|
477 |
+
curr_response = self.orchestrator()
|
478 |
+
yield (
|
479 |
+
curr_response,
|
480 |
+
self.editor_image,
|
481 |
+
self.browser_image,
|
482 |
+
self.scratchpad_image,
|
483 |
+
)
|
484 |
+
|
485 |
+
</gradio-file>
|
486 |
+
|
487 |
+
<gradio-file name="prompts.py">
|
488 |
+
orchestrator_prompt = """**General**
|
489 |
+
|
490 |
+
- You are DevOn, an expert Software Developer.
|
491 |
+
- You will be asked to develop a new software project from scratch. You will primarily work in Python. You will deal with large software projects spanning multiple files and user requirements.
|
492 |
+
- Your lifecycle will essentially circle around the Task, the State, your Plan, your Actions, and your Interns. Each of these are described in detail below.
|
493 |
+
- To start with, your Plan will be empty. You will receive a State (in the form of 3 images, one from each of your Interns) and a Task. You will construct a Plan outlining the steps you will need to take to complete the Task, then ask your Interns to do things in order to incrementally fulfil the steps and complete the Task.
|
494 |
+
- With each step, you will also provide an Explanation, explaining to the user what you are currently doing, so they may be able to keep track and monitor your progress. For example:
|
495 |
+
- Explanation: I am currently updating the plan based on the current state and the Task.
|
496 |
+
- Explanation: I am currently creating a file called utils.py which will contain utility functions.
|
497 |
+
|
498 |
+
**State**
|
499 |
+
|
500 |
+
**Interns**
|
501 |
+
|
502 |
+
- You have 3 interns who will help you with different tasks - a Programmer, a Researcher, and a Planner. Here’s some info about them:
|
503 |
+
- Programmer: the Programmer is great at writing code given very specific instructions but isn’t a good long term planner. The Programmer works on Replit. You can ask the Programmer to write some code in certain files, make new files, etc. You can even give loose instructions like “Make a new file and write basic skeleton for an Agent class in it.” Keep in mind that the Programmer works exclusively in an online Replit IDE environment. Make sure your Plan and your Actions take this into consideration.
|
504 |
+
- Researcher: the Researcher is very handy with a browser and great at finding out technical details, documentation, examples, miscellaneous information, etc. You can ask it to do things like “Find out how to make an LLM call using the Perplexity API”.
|
505 |
+
- Notetaker: the Notetaker has a notepad and can note down anything you want. You will be able to see the notepad at all times. Anytime you want anything written down just to keep track of it, ask the Planner to do so.
|
506 |
+
|
507 |
+
**Plan**
|
508 |
+
|
509 |
+
- You have a persistent object to keep track of things: a Plan.
|
510 |
+
- If the plan is empty, you will create a plan using the current state of things and the given task. You will do so using the update_plan action described below.
|
511 |
+
|
512 |
+
**Actions**
|
513 |
+
|
514 |
+
- There are 6 actions that you can take at the current time step. You must always take a valid action. You will complete the task by taking actions. You are free to take as many actions as needed (even hundreds), don’t try to rush by compressing multiple actions into one. These are the available actions:
|
515 |
+
- update_plan <plan>: Update Plan’s value to <plan>. This will replace the old value, not append to it. If there’s something from the old plan you wish to include in the updated one, make sure to include it in the <plan> you provide as an argument. Some examples how you can use this:
|
516 |
+
- update_plan In order to carry out the task of creating a Flask web server, I will need to take the following steps:
|
517 |
+
1) …
|
518 |
+
2) …
|
519 |
+
3) …
|
520 |
+
- programmer <task>: Ask the Programmer to carry out a <task>. Some examples of how you can use this:
|
521 |
+
- programmer Create a new Python file for utils called utils.py and write a generate_random_number() function in it that takes no parameters and returns a random number.
|
522 |
+
- programmer Go to the model.py file and import generate_random_number() from utils.
|
523 |
+
- researcher <task>: Ask the Researcher to carry out a <task>. The Researcher will reply to you with the information you asked for. Some examples of how you can use this:
|
524 |
+
- researcher Find out how the OpenAI API is used.
|
525 |
+
- researcher What is a SERP API I could use?
|
526 |
+
- notetaker <note>: Ask the Notetaker to carry out a <task>. Some examples of how you can use this:
|
527 |
+
- notetaker Note down the following information: MULTION_API_KEY=…
|
528 |
+
- notetaker Note down the following information: An example Chat Completions API call looks like the following:
|
529 |
+
from openai import OpenAI
|
530 |
+
client = OpenAI()
|
531 |
+
|
532 |
+
response = client.chat.completions.create(
|
533 |
+
model="gpt-3.5-turbo",
|
534 |
+
messages=[
|
535 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
536 |
+
{"role": "user", "content": "Who won the world series in 2020?"},
|
537 |
+
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
|
538 |
+
{"role": "user", "content": "Where was it played?"}
|
539 |
+
]
|
540 |
+
)
|
541 |
+
- clarify <question>: Clarify something about the Task. Sometimes, there may be missing information, such as logins, api keys, or some requirements of the Task may be unclear. Use this Action to clarify things from the user by asking <question>. Use this sparingly. Try and make decisions yourself. Some examples of how you can use this:
|
542 |
+
- clarify The Task mentions that I need to benchmark the Perplexity API. Could you provide your API Key?
|
543 |
+
- submit: The Task is completed and you are ready to submit the output (whatever the programmer has so far). This is end the execution. Only do this when you are completely sure.
|
544 |
+
|
545 |
+
**Important Notes**
|
546 |
+
|
547 |
+
- Respond only by taking an Action (and providing the accompanying Explanation). Any response from you must be one of the above Actions. No other text in the response, just the Action and the Explanation. You will structure your output as such:
|
548 |
+
”Action: <action>\nExplanation: <explanation>”
|
549 |
+
- You do not need to ask the Programmer to log in.
|
550 |
+
- You can see all the Interns screens. If it seems like an Intern has made a mistake or encountered an error, you can tell them about it using the relevant action and ask them to correct it. This is especially important with the Programmer.
|
551 |
+
- When you ask the programmer to write some code, ask it like this: "programmer memorize the following code and write it in the editor: <code>"
|
552 |
+
- When you ask the programmer to write some code, make sure the code does not include any double quotation marks, only single quotation marks. E.g. "hello world" should instead be 'hello world'.
|
553 |
+
- Do not ask the programmer to create new files.
|
554 |
+
- When writing code, it is preferable to keep it small and simple. Don't write too much fluff.
|
555 |
+
- Remember to only use single quotation marks.
|
556 |
+
"""
|
557 |
+
# programmer_notes = """Important Notes:
|
558 |
+
# Do not refresh the page ever to check for anything. Only wait. Do not refresh.
|
559 |
+
# You are working in a terminal environment.
|
560 |
+
# You will do everything using the terminal and only the terminal.
|
561 |
+
# If you need to create a new file, do so using the touch command on the terminal.
|
562 |
+
# If you need to see files in the current directory, do so using ls.
|
563 |
+
# If you need to view a files content, do so using the cat command on the terminal.
|
564 |
+
# To enter code into a file, use a single printf command. After the printf command has been completely typed, press enter. Typing the command and pressing enter must be 2 separate steps.
|
565 |
+
# Do not open a text editor like vim or nano.
|
566 |
+
# If you need to install a new package, use pip install on the terminal.
|
567 |
+
# Do not use the same command repeatedly.
|
568 |
+
# When you write code into a file, write it once, cat it once, then stop. Do no attempt to write again unless it is wrong.
|
569 |
+
# Remember that you need to press Enter after typing a command into the terminal. Only press enter after the command has been completely typed. Typing the command pressing enter must be 2 separate steps."""
|
570 |
+
|
571 |
+
programmer_notes = """Important Notes:
|
572 |
+
You are a Programmer who works in a Replit Environment exclusively. If you need to install a package, use the Shell and not the Console.
|
573 |
+
Do not refresh the page ever to check for anything. Only wait. Do not refresh. Do not create new files. Write your code in currently open editor window itself. Do not type double quotation marks. If you are asked to type code containing them, use single quotes instead."""
|
574 |
+
|
575 |
+
notetaker_notes = """Important Notes:
|
576 |
+
Don't write anything in the Note Title field.
|
577 |
+
Whatever notes you are told to make, write them in one go, don't press enter or type multiple times, because everytime you write, it will replace the prevoius content.
|
578 |
+
You do not need to Save the note. When asked to note something down, just write it on the notepad. That is enough."""
|
579 |
+
|
580 |
+
</gradio-file>
|
581 |
+
|
582 |
+
</gradio-lite>
|
583 |
+
</body>
|
584 |
+
</html>
|