Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
agent.py
CHANGED
|
@@ -305,20 +305,319 @@ class DevOn:
|
|
| 305 |
)
|
| 306 |
print(self.messages)
|
| 307 |
|
| 308 |
-
self.execute_action(action)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
-
# temp
|
| 311 |
-
# self.done = True
|
| 312 |
return explanation
|
| 313 |
|
| 314 |
def run(self, prompt):
|
| 315 |
self.done = False
|
| 316 |
self.task = prompt
|
| 317 |
while not self.done:
|
| 318 |
-
curr_response = self.orchestrator()
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
self.
|
| 322 |
-
self.
|
| 323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
)
|
| 306 |
print(self.messages)
|
| 307 |
|
| 308 |
+
# self.execute_action(action)
|
| 309 |
+
|
| 310 |
+
action_func = action.split(" ", 1)[0]
|
| 311 |
+
|
| 312 |
+
if action_func == "submit":
|
| 313 |
+
self.done = True
|
| 314 |
+
elif action_func == "update_plan":
|
| 315 |
+
action_arg = action.split(" ", 1)[1]
|
| 316 |
+
self.plan = action_arg
|
| 317 |
+
elif action_func == "programmer":
|
| 318 |
+
action_arg = action.split(" ", 1)[1]
|
| 319 |
+
while True:
|
| 320 |
+
self.programmer = self.multion.sessions.step(
|
| 321 |
+
self.programmer.session_id,
|
| 322 |
+
cmd=action_arg + "\n\n" + programmer_notes,
|
| 323 |
+
url="https://replit.com/login",
|
| 324 |
+
include_screenshot=True,
|
| 325 |
+
)
|
| 326 |
+
print(self.programmer)
|
| 327 |
+
self.messages.append(
|
| 328 |
+
{
|
| 329 |
+
"role": "user",
|
| 330 |
+
"content": "The Programmer says: {message}".format(
|
| 331 |
+
message=self.programmer.message
|
| 332 |
+
),
|
| 333 |
+
}
|
| 334 |
+
)
|
| 335 |
+
if self.programmer.status in ["DONE", "NOT SURE"]:
|
| 336 |
+
break
|
| 337 |
+
self.editor_image = self.multion.sessions.screenshot(
|
| 338 |
+
session_id=self.programmer.session_id
|
| 339 |
+
).screenshot
|
| 340 |
+
print(self.editor_image)
|
| 341 |
+
time.sleep(1)
|
| 342 |
+
elif action_func == "researcher":
|
| 343 |
+
action_arg = action.split(" ", 1)[1]
|
| 344 |
+
while True:
|
| 345 |
+
self.researcher = self.multion.sessions.step(
|
| 346 |
+
self.researcher.session_id,
|
| 347 |
+
cmd=action_arg,
|
| 348 |
+
url="https://www.google.com",
|
| 349 |
+
include_screenshot=True,
|
| 350 |
+
)
|
| 351 |
+
print(self.researcher)
|
| 352 |
+
self.messages.append(
|
| 353 |
+
{
|
| 354 |
+
"role": "user",
|
| 355 |
+
"content": "The Researcher says: {message}".format(
|
| 356 |
+
message=self.researcher.message
|
| 357 |
+
),
|
| 358 |
+
}
|
| 359 |
+
)
|
| 360 |
+
# time.sleep(1)
|
| 361 |
+
# self.browser_image = self.researcher["screenshot"]
|
| 362 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
| 363 |
+
if self.researcher.status == "DONE":
|
| 364 |
+
break
|
| 365 |
+
self.browser_image = self.multion.sessions.screenshot(
|
| 366 |
+
session_id=self.researcher.session_id
|
| 367 |
+
).screenshot
|
| 368 |
+
print(self.browser_image)
|
| 369 |
+
time.sleep(1)
|
| 370 |
+
elif action_func == "notetaker":
|
| 371 |
+
action_arg = action.split(" ", 1)[1]
|
| 372 |
+
while True:
|
| 373 |
+
self.notetaker = self.multion.sessions.step(
|
| 374 |
+
self.notetaker.session_id,
|
| 375 |
+
cmd=action_arg + "\n\n" + notetaker_notes,
|
| 376 |
+
url="https://anotepad.com/",
|
| 377 |
+
include_screenshot=True,
|
| 378 |
+
)
|
| 379 |
+
print(self.notetaker)
|
| 380 |
+
self.messages.append(
|
| 381 |
+
{
|
| 382 |
+
"role": "user",
|
| 383 |
+
"content": "The Notetaker says: {message}".format(
|
| 384 |
+
message=self.notetaker.message
|
| 385 |
+
),
|
| 386 |
+
}
|
| 387 |
+
)
|
| 388 |
+
# time.sleep(1)
|
| 389 |
+
# self.scratchpad_image = self.notetaker["screenshot"]
|
| 390 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
| 391 |
+
if self.notetaker.status == "DONE":
|
| 392 |
+
break
|
| 393 |
+
self.scratchpad_image = self.multion.sessions.screenshot(
|
| 394 |
+
session_id=self.notetaker.session_id
|
| 395 |
+
).screenshot
|
| 396 |
+
print(self.scratchpad_image)
|
| 397 |
+
time.sleep(1)
|
| 398 |
+
elif action_func == "clarify":
|
| 399 |
+
action_arg = action.split(" ", 1)[1]
|
| 400 |
|
|
|
|
|
|
|
| 401 |
return explanation
|
| 402 |
|
| 403 |
def run(self, prompt):
|
| 404 |
self.done = False
|
| 405 |
self.task = prompt
|
| 406 |
while not self.done:
|
| 407 |
+
# curr_response = self.orchestrator()
|
| 408 |
+
|
| 409 |
+
if not self.programmer_logged_in:
|
| 410 |
+
# self.programmer_login()
|
| 411 |
+
if self.local:
|
| 412 |
+
cmd = "Create a new Python REPL."
|
| 413 |
+
else:
|
| 414 |
+
cmd = "Log in with the email {email} and the password {password}. Then create a new Python REPL.".format(
|
| 415 |
+
email=self.replit_email, password=self.replit_password
|
| 416 |
+
)
|
| 417 |
+
while True:
|
| 418 |
+
self.programmer = self.multion.sessions.step(
|
| 419 |
+
self.programmer.session_id,
|
| 420 |
+
cmd=cmd + "\n\n" + programmer_notes,
|
| 421 |
+
url="https://replit.com/login",
|
| 422 |
+
include_screenshot=True,
|
| 423 |
+
)
|
| 424 |
+
print(self.programmer)
|
| 425 |
+
print(
|
| 426 |
+
self.multion.sessions.screenshot(
|
| 427 |
+
session_id=self.programmer.session_id
|
| 428 |
+
).screenshot
|
| 429 |
+
)
|
| 430 |
+
# time.sleep(1)
|
| 431 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
| 432 |
+
# self.editor_image = self.programmer["screenshot"]
|
| 433 |
+
if self.programmer.status in ["DONE", "NOT SURE"]:
|
| 434 |
+
break
|
| 435 |
+
self.editor_image = self.multion.sessions.screenshot(
|
| 436 |
+
session_id=self.programmer.session_id
|
| 437 |
+
).screenshot
|
| 438 |
+
time.sleep(1)
|
| 439 |
+
yield (
|
| 440 |
+
"I am setting up the programming environment",
|
| 441 |
+
self.editor_image,
|
| 442 |
+
self.browser_image,
|
| 443 |
+
self.scratchpad_image,
|
| 444 |
+
)
|
| 445 |
+
|
| 446 |
+
self.editor_image = self.multion.sessions.screenshot(
|
| 447 |
+
session_id=self.programmer.session_id
|
| 448 |
+
).screenshot
|
| 449 |
+
time.sleep(1)
|
| 450 |
+
self.programmer_logged_in = True
|
| 451 |
+
messages = self.prepare_messages()
|
| 452 |
+
chat_completion = self.client.chat.completions.create(
|
| 453 |
+
messages=messages,
|
| 454 |
+
model="gpt-4-vision-preview",
|
| 455 |
+
# max_tokens=200,
|
| 456 |
)
|
| 457 |
+
response = chat_completion.choices[0].message.content
|
| 458 |
+
action, explanation = response.split("Explanation: ", 1)
|
| 459 |
+
action = action.split("Action: ", 1)[1]
|
| 460 |
+
|
| 461 |
+
self.messages.append({"role": "assistant", "content": response})
|
| 462 |
+
self.messages.append(
|
| 463 |
+
{
|
| 464 |
+
"role": "user",
|
| 465 |
+
"content": "The current Plan state is: {plan}".format(
|
| 466 |
+
plan=self.plan
|
| 467 |
+
),
|
| 468 |
+
}
|
| 469 |
+
)
|
| 470 |
+
print(self.messages)
|
| 471 |
+
|
| 472 |
+
# self.execute_action(action)
|
| 473 |
+
|
| 474 |
+
action_func = action.split(" ", 1)[0]
|
| 475 |
+
|
| 476 |
+
if action_func == "submit":
|
| 477 |
+
self.done = True
|
| 478 |
+
yield (
|
| 479 |
+
explanation,
|
| 480 |
+
self.editor_image,
|
| 481 |
+
self.browser_image,
|
| 482 |
+
self.scratchpad_image,
|
| 483 |
+
)
|
| 484 |
+
elif action_func == "update_plan":
|
| 485 |
+
action_arg = action.split(" ", 1)[1]
|
| 486 |
+
self.plan = action_arg
|
| 487 |
+
yield (
|
| 488 |
+
explanation,
|
| 489 |
+
self.editor_image,
|
| 490 |
+
self.browser_image,
|
| 491 |
+
self.scratchpad_image,
|
| 492 |
+
)
|
| 493 |
+
elif action_func == "programmer":
|
| 494 |
+
action_arg = action.split(" ", 1)[1]
|
| 495 |
+
while True:
|
| 496 |
+
self.programmer = self.multion.sessions.step(
|
| 497 |
+
self.programmer.session_id,
|
| 498 |
+
cmd=action_arg + "\n\n" + programmer_notes,
|
| 499 |
+
url="https://replit.com/login",
|
| 500 |
+
include_screenshot=True,
|
| 501 |
+
)
|
| 502 |
+
print(self.programmer)
|
| 503 |
+
self.messages.append(
|
| 504 |
+
{
|
| 505 |
+
"role": "user",
|
| 506 |
+
"content": "The Programmer says: {message}".format(
|
| 507 |
+
message=self.programmer.message
|
| 508 |
+
),
|
| 509 |
+
}
|
| 510 |
+
)
|
| 511 |
+
if self.programmer.status in ["DONE", "NOT SURE"]:
|
| 512 |
+
break
|
| 513 |
+
self.editor_image = self.multion.sessions.screenshot(
|
| 514 |
+
session_id=self.programmer.session_id
|
| 515 |
+
).screenshot
|
| 516 |
+
print(self.editor_image)
|
| 517 |
+
time.sleep(1)
|
| 518 |
+
yield (
|
| 519 |
+
explanation,
|
| 520 |
+
self.editor_image,
|
| 521 |
+
self.browser_image,
|
| 522 |
+
self.scratchpad_image,
|
| 523 |
+
)
|
| 524 |
+
self.editor_image = self.multion.sessions.screenshot(
|
| 525 |
+
session_id=self.programmer.session_id
|
| 526 |
+
).screenshot
|
| 527 |
+
print(self.editor_image)
|
| 528 |
+
time.sleep(1)
|
| 529 |
+
elif action_func == "researcher":
|
| 530 |
+
action_arg = action.split(" ", 1)[1]
|
| 531 |
+
while True:
|
| 532 |
+
self.researcher = self.multion.sessions.step(
|
| 533 |
+
self.researcher.session_id,
|
| 534 |
+
cmd=action_arg,
|
| 535 |
+
url="https://www.google.com",
|
| 536 |
+
include_screenshot=True,
|
| 537 |
+
)
|
| 538 |
+
print(self.researcher)
|
| 539 |
+
self.messages.append(
|
| 540 |
+
{
|
| 541 |
+
"role": "user",
|
| 542 |
+
"content": "The Researcher says: {message}".format(
|
| 543 |
+
message=self.researcher.message
|
| 544 |
+
),
|
| 545 |
+
}
|
| 546 |
+
)
|
| 547 |
+
# time.sleep(1)
|
| 548 |
+
# self.browser_image = self.researcher["screenshot"]
|
| 549 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
| 550 |
+
if self.researcher.status == "DONE":
|
| 551 |
+
break
|
| 552 |
+
self.browser_image = self.multion.sessions.screenshot(
|
| 553 |
+
session_id=self.researcher.session_id
|
| 554 |
+
).screenshot
|
| 555 |
+
print(self.browser_image)
|
| 556 |
+
time.sleep(1)
|
| 557 |
+
yield (
|
| 558 |
+
explanation,
|
| 559 |
+
self.editor_image,
|
| 560 |
+
self.browser_image,
|
| 561 |
+
self.scratchpad_image,
|
| 562 |
+
)
|
| 563 |
+
self.browser_image = self.multion.sessions.screenshot(
|
| 564 |
+
session_id=self.researcher.session_id
|
| 565 |
+
).screenshot
|
| 566 |
+
print(self.browser_image)
|
| 567 |
+
time.sleep(1)
|
| 568 |
+
elif action_func == "notetaker":
|
| 569 |
+
action_arg = action.split(" ", 1)[1]
|
| 570 |
+
while True:
|
| 571 |
+
self.notetaker = self.multion.sessions.step(
|
| 572 |
+
self.notetaker.session_id,
|
| 573 |
+
cmd=action_arg + "\n\n" + notetaker_notes,
|
| 574 |
+
url="https://anotepad.com/",
|
| 575 |
+
include_screenshot=True,
|
| 576 |
+
)
|
| 577 |
+
print(self.notetaker)
|
| 578 |
+
self.messages.append(
|
| 579 |
+
{
|
| 580 |
+
"role": "user",
|
| 581 |
+
"content": "The Notetaker says: {message}".format(
|
| 582 |
+
message=self.notetaker.message
|
| 583 |
+
),
|
| 584 |
+
}
|
| 585 |
+
)
|
| 586 |
+
# time.sleep(1)
|
| 587 |
+
# self.scratchpad_image = self.notetaker["screenshot"]
|
| 588 |
+
# yield ("", self.editor_image, self.browser_image, self.scratchpad_image)
|
| 589 |
+
if self.notetaker.status == "DONE":
|
| 590 |
+
break
|
| 591 |
+
self.scratchpad_image = self.multion.sessions.screenshot(
|
| 592 |
+
session_id=self.notetaker.session_id
|
| 593 |
+
).screenshot
|
| 594 |
+
print(self.scratchpad_image)
|
| 595 |
+
time.sleep(1)
|
| 596 |
+
yield (
|
| 597 |
+
explanation,
|
| 598 |
+
self.editor_image,
|
| 599 |
+
self.browser_image,
|
| 600 |
+
self.scratchpad_image,
|
| 601 |
+
)
|
| 602 |
+
self.scratchpad_image = self.multion.sessions.screenshot(
|
| 603 |
+
session_id=self.notetaker.session_id
|
| 604 |
+
).screenshot
|
| 605 |
+
print(self.scratchpad_image)
|
| 606 |
+
time.sleep(1)
|
| 607 |
+
elif action_func == "clarify":
|
| 608 |
+
action_arg = action.split(" ", 1)[1]
|
| 609 |
+
yield (
|
| 610 |
+
explanation,
|
| 611 |
+
self.editor_image,
|
| 612 |
+
self.browser_image,
|
| 613 |
+
self.scratchpad_image,
|
| 614 |
+
)
|
| 615 |
+
|
| 616 |
+
# return explanation
|
| 617 |
+
|
| 618 |
+
# yield (
|
| 619 |
+
# curr_response,
|
| 620 |
+
# self.editor_image,
|
| 621 |
+
# self.browser_image,
|
| 622 |
+
# self.scratchpad_image,
|
| 623 |
+
# )
|