mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-26 15:49:42 +02:00
mv android_assistant folder and fix conflicts
This commit is contained in:
parent
7652880c95
commit
48348a37b4
33 changed files with 86 additions and 142 deletions
1
tests/data/andriod_assistant/.gitignore
vendored
Normal file
1
tests/data/andriod_assistant/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
!*.png
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 611 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 840 KiB |
2
tests/data/andriod_assistant/demo_Contacts/record.txt
Normal file
2
tests/data/andriod_assistant/demo_Contacts/record.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
tap(9):::android.view.ViewGroup_1067_236_android.widget.TextView_183_204_Apps_2
|
||||
stop
|
||||
1
tests/data/andriod_assistant/demo_Contacts/task_desc.txt
Normal file
1
tests/data/andriod_assistant/demo_Contacts/task_desc.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
Create a contact in Contacts App named zjy with a phone number +86 18831933368
|
||||
|
|
@ -9,11 +9,7 @@ from pathlib import Path
|
|||
from typing import List, Tuple
|
||||
|
||||
import pytest
|
||||
<<<<<<< HEAD
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
=======
|
||||
from pydantic import ValidationError
|
||||
>>>>>>> 7f8ae1f2 (update gpt4-v)
|
||||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.actions.action_node import ActionNode, ReviewMode, ReviseMode
|
||||
|
|
|
|||
3
tests/metagpt/ext/android_assistant/__init__.py
Normal file
3
tests/metagpt/ext/android_assistant/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc :
|
||||
88
tests/metagpt/ext/android_assistant/test_an.py
Normal file
88
tests/metagpt/ext/android_assistant/test_an.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : test on android emulator action. After Modify Role Test, this script is discarded.
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from metagpt.const import TEST_DATA_PATH
|
||||
from metagpt.environment.android.android_env import AndroidEnv
|
||||
from metagpt.ext.android_assistant.actions.manual_record import ManualRecord
|
||||
from metagpt.ext.android_assistant.actions.parse_record import ParseRecord
|
||||
from metagpt.ext.android_assistant.actions.screenshot_parse import ScreenshotParse
|
||||
from metagpt.ext.android_assistant.actions.self_learn_and_reflect import (
|
||||
SelfLearnAndReflect,
|
||||
)
|
||||
|
||||
TASK_PATH = TEST_DATA_PATH.joinpath("andriod_assistant/unitest_Contacts")
|
||||
TASK_PATH.mkdir(parents=True, exist_ok=True)
|
||||
DEMO_NAME = str(time.time())
|
||||
SELF_EXPLORE_DOC_PATH = TASK_PATH.joinpath("auto_docs")
|
||||
PARSE_RECORD_DOC_PATH = TASK_PATH.joinpath("demo_docs")
|
||||
|
||||
device_id = "emulator-5554"
|
||||
xml_dir = Path("/sdcard")
|
||||
screenshot_dir = Path("/sdcard/Pictures/Screenshots")
|
||||
|
||||
test_env_self_learn_android = AndroidEnv(
|
||||
device_id=device_id,
|
||||
xml_dir=xml_dir,
|
||||
screenshot_dir=screenshot_dir,
|
||||
)
|
||||
test_self_learning = SelfLearnAndReflect()
|
||||
|
||||
test_env_manual_learn_android = AndroidEnv(
|
||||
device_id=device_id,
|
||||
xml_dir=xml_dir,
|
||||
screenshot_dir=screenshot_dir,
|
||||
)
|
||||
test_manual_record = ManualRecord()
|
||||
test_manual_parse = ParseRecord()
|
||||
|
||||
test_env_screenshot_parse_android = AndroidEnv(
|
||||
device_id=device_id,
|
||||
xml_dir=xml_dir,
|
||||
screenshot_dir=screenshot_dir,
|
||||
)
|
||||
test_screenshot_parse = ScreenshotParse()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
test_action_list = [
|
||||
test_self_learning.run(
|
||||
round_count=20,
|
||||
task_desc="Create a contact in Contacts App named zjy with a phone number +86 18831933368 ",
|
||||
last_act="",
|
||||
task_dir=TASK_PATH / "demos" / f"self_learning_{DEMO_NAME}",
|
||||
docs_dir=SELF_EXPLORE_DOC_PATH,
|
||||
env=test_env_self_learn_android,
|
||||
),
|
||||
test_manual_record.run(
|
||||
# demo_name=DEMO_NAME,
|
||||
task_dir=TASK_PATH / "demos" / f"manual_record_{DEMO_NAME}",
|
||||
task_desc="Create a contact in Contacts App named zjy with a phone number +86 18831933368 ",
|
||||
env=test_env_manual_learn_android,
|
||||
),
|
||||
test_manual_parse.run(
|
||||
app_name="Contacts",
|
||||
# demo_name=DEMO_NAME,
|
||||
task_dir=TASK_PATH / "demos" / f"manual_record_{DEMO_NAME}", # 修要修改
|
||||
docs_dir=PARSE_RECORD_DOC_PATH, # 需要修改
|
||||
env=test_env_manual_learn_android,
|
||||
),
|
||||
test_screenshot_parse.run(
|
||||
round_count=20,
|
||||
task_desc="Create a contact in Contacts App named zjy with a phone number +86 18831933368 ",
|
||||
last_act="",
|
||||
task_dir=TASK_PATH / f"act_{DEMO_NAME}",
|
||||
docs_dir=PARSE_RECORD_DOC_PATH,
|
||||
env=test_env_screenshot_parse_android,
|
||||
grid_on=False,
|
||||
),
|
||||
]
|
||||
|
||||
loop.run_until_complete(asyncio.gather(*test_action_list))
|
||||
loop.close()
|
||||
29
tests/metagpt/ext/android_assistant/test_parse_record.py
Normal file
29
tests/metagpt/ext/android_assistant/test_parse_record.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : test case (imgs from appagent's)
|
||||
|
||||
import asyncio
|
||||
|
||||
from metagpt.actions.action import Action
|
||||
from metagpt.const import TEST_DATA_PATH
|
||||
from metagpt.ext.android_assistant.actions.parse_record import ParseRecord
|
||||
|
||||
TASK_PATH = TEST_DATA_PATH.joinpath("andriod_assistant/demo_Contacts")
|
||||
TEST_BEFORE_PATH = TASK_PATH.joinpath("labeled_screenshots/0_labeled.png")
|
||||
TEST_AFTER_PATH = TASK_PATH.joinpath("labeled_screenshots/1_labeled.png")
|
||||
RECORD_PATH = TASK_PATH.joinpath("record.txt")
|
||||
TASK_DESC_PATH = TASK_PATH.joinpath("task_desc.txt")
|
||||
DOCS_DIR = TASK_PATH.joinpath("storage")
|
||||
|
||||
test_action = Action(name="test")
|
||||
|
||||
|
||||
async def manual_learn_test():
|
||||
parse_record = ParseRecord()
|
||||
await parse_record.run(app_name="demo_Contacts", task_dir=TASK_PATH, docs_dir=DOCS_DIR)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(manual_learn_test())
|
||||
loop.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue