From e2ed85f197d35f3b1016d98311eee5333b1e347e Mon Sep 17 00:00:00 2001 From: better629 Date: Wed, 27 Mar 2024 16:36:42 +0800 Subject: [PATCH] update andriod_assistant const and test data --- examples/andriod_assistant/README.md | 4 +-- .../roles/android_assistant.py | 4 +-- examples/andriod_assistant/tests/test.py | 13 ++++---- .../andriod_assistant/tests/test_for_an.py | 30 +++++++++++-------- examples/andriod_assistant/utils/const.py | 3 ++ 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/examples/andriod_assistant/README.md b/examples/andriod_assistant/README.md index 60649a573..9d5cb5c3e 100644 --- a/examples/andriod_assistant/README.md +++ b/examples/andriod_assistant/README.md @@ -17,13 +17,13 @@ ## Experiential Learning By designating the app to explore and the method of learning (automatic or manual demonstration), you can facilitate Android Assistant to master the functions of various apps, thereby generating respective documentation for later use during the phase termed as "Automation of routine tasks". For any given task objective, conducting approximately 20 cycles of exploration can considerably enhance the performance. You can experiment with both the automatic learning and manual demonstration modes for the "contacts" app by implementing the ensuing commands: ```bash -python run_assistant.py "your task description" --stage "learn" --mode "auto/manual" --app-name "Contacts" +python run_assistant.py "your task description" --stage "learn" --mode "auto or manual" --app-name "Contacts" ``` ## Free Your Hands Once the Android Assistant has completed ample exploration, you are all set to automate your tasks! By utilizing either text description or voice input, you can instruct the Android Assistant to perform the desired tasks across various applications. For the specific command processes, please see the following recommendations: ### By Text ```bash -python run_assistant.py "your task description" --stage "act" --mode "auto/manual" --app-name "app names" +python run_assistant.py "your task description" --stage "act" --mode "auto or manual" --app-name "app names" ``` ### By Voice coming soon diff --git a/examples/andriod_assistant/roles/android_assistant.py b/examples/andriod_assistant/roles/android_assistant.py index eccea298e..2c57521fe 100644 --- a/examples/andriod_assistant/roles/android_assistant.py +++ b/examples/andriod_assistant/roles/android_assistant.py @@ -14,6 +14,7 @@ from examples.andriod_assistant.actions.screenshot_parse import ScreenshotParse from examples.andriod_assistant.actions.self_learn_and_reflect import ( SelfLearnAndReflect, ) +from examples.andriod_assistant.utils.const import ROOT_PATH from examples.andriod_assistant.utils.schema import AndroidActionOutput, RunState from metagpt.actions.add_requirement import UserRequirement from metagpt.config2 import config @@ -40,8 +41,7 @@ class AndroidAssistant(Role): self._watch([UserRequirement, AndroidActionOutput]) self.task_desc = config.get_other("task_desc", "Just explore any app in this phone!") app_name = config.get_other("app_name", "demo") - curr_path = Path(__file__).parent - data_dir = curr_path.joinpath("..", "output") + data_dir = ROOT_PATH.joinpath("output") cur_datetime = datetime.fromtimestamp(int(time.time())).strftime("%Y-%m-%d_%H-%M-%S") """Firstly, we decide the state with user config, further, we can do it automatically, like if it's new app, diff --git a/examples/andriod_assistant/tests/test.py b/examples/andriod_assistant/tests/test.py index ee60d654b..4b3e0af88 100644 --- a/examples/andriod_assistant/tests/test.py +++ b/examples/andriod_assistant/tests/test.py @@ -5,7 +5,6 @@ import ast import asyncio import re -from pathlib import Path from examples.andriod_assistant.actions.parse_record_an import RECORD_PARSE_NODE from examples.andriod_assistant.prompts.operation_prompt import ( @@ -15,17 +14,19 @@ from examples.andriod_assistant.prompts.operation_prompt import ( tap_doc_template, text_doc_template, ) +from examples.andriod_assistant.utils.const import ROOT_PATH from examples.andriod_assistant.utils.schema import ActionOp, SwipeOp from metagpt.actions.action import Action from metagpt.config2 import config from metagpt.logs import logger from metagpt.utils.common import encode_image -TEST_BEFORE_PATH = Path("apps/demo_Contacts/labeled_screenshots/demo_Contacts_2024-01-30_21-50-19_1.png") -TEST_AFTER_PATH = Path("apps/demo_Contacts/labeled_screenshots/demo_Contacts_2024-01-30_21-50-19_2.png") -RECORD_PATH = Path("apps/demo_Contacts/record.txt") -TASK_DESC_PATH = Path("apps/demo_Contacts/task_desc.txt") -DOCS_DIR = Path("storage") +TASK_PATH = ROOT_PATH.parent.joinpath("data/demo_Contacts") +TEST_BEFORE_PATH = TASK_PATH.joinpath("labeled_screenshots/demo_Contacts_2024-01-24_12-07-55_3.png") +TEST_AFTER_PATH = TASK_PATH.joinpath("labeled_screenshots/demo_Contacts_2024-01-24_12-07-55_4.png") +RECORD_PATH = TASK_PATH.joinpath("record.txt") +TASK_DESC_PATH = TASK_PATH.joinpath("task_desc.txt") +DOCS_DIR = TASK_PATH.joinpath("storage") testaction = Action(name="test") diff --git a/examples/andriod_assistant/tests/test_for_an.py b/examples/andriod_assistant/tests/test_for_an.py index a5aa1fb09..2acf4601e 100644 --- a/examples/andriod_assistant/tests/test_for_an.py +++ b/examples/andriod_assistant/tests/test_for_an.py @@ -12,35 +12,41 @@ from examples.andriod_assistant.actions.screenshot_parse import ScreenshotParse from examples.andriod_assistant.actions.self_learn_and_reflect import ( SelfLearnAndReflect, ) +from examples.andriod_assistant.utils.const import ROOT_PATH from metagpt.environment.android_env.android_env import AndroidEnv -TASK_PATH = Path("apps/Contacts") +TASK_PATH = ROOT_PATH.joinpath("unitest_Contacts") DEMO_NAME = str(time.time()) -SELF_EXPLORE_DOC_PATH = TASK_PATH.joinpath("autodocs") -PARSE_RECORD_DOC_PATH = TASK_PATH.joinpath("demodocs") +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="emulator-5554", - xml_dir=Path("/sdcard"), - screenshot_dir=Path("/sdcard/Pictures/Screenshots"), + device_id=device_id, + xml_dir=xml_dir, + screenshot_dir=screenshot_dir, ) test_self_learning = SelfLearnAndReflect() test_env_manual_learn_android = AndroidEnv( - device_id="emulator-5554", - xml_dir=Path("/sdcard"), - screenshot_dir=Path("/sdcard/Pictures/Screenshots"), + 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="emulator-5554", - xml_dir=Path("/sdcard"), - screenshot_dir=Path("/sdcard/Pictures/Screenshots"), + device_id=device_id, + xml_dir=xml_dir, + screenshot_dir=screenshot_dir, ) test_screenshot_parse = ScreenshotParse() + if __name__ == "__main__": loop = asyncio.get_event_loop() diff --git a/examples/andriod_assistant/utils/const.py b/examples/andriod_assistant/utils/const.py index 5c373a6f9..0c7951156 100644 --- a/examples/andriod_assistant/utils/const.py +++ b/examples/andriod_assistant/utils/const.py @@ -2,4 +2,7 @@ # -*- coding: utf-8 -*- # @Desc : +from pathlib import Path + +ROOT_PATH = Path(__file__).parent.parent.absolute() ADB_EXEC_FAIL = "FAILED"