From 2a945e057a6008e60968368685aceb8288dff543 Mon Sep 17 00:00:00 2001 From: heroding77 <2441145504@qq.com> Date: Fri, 15 Dec 2023 00:45:06 +0800 Subject: [PATCH] update action_lib --- examples/11_file_classification_new.py | 6 +- examples/9_zip_and_unzip_new.py | 86 +++++++++++++++++ examples/config.json | 4 +- .../action_description/check_weather.txt | 1 - .../create_text_file_and_write_something.txt | 1 - .../enable_do_not_disturb.txt | 1 - .../action_description/execute_sql.txt | 1 - .../action_description/open_document.txt | 1 - .../action_description/open_picture.txt | 1 - .../organize_app_layout.txt | 1 - .../action_description/play_light_music.txt | 1 - .../action_description/python_interpreter.txt | 16 ---- .../set_20_minute_alarm.txt | 1 - .../action_description/turn_on_dark_mode.txt | 1 - .../action_description/turn_on_light_mode.txt | 1 - .../action_description/unzip_files.txt | 1 - .../action_description/zip_files.txt | 1 - jarvis/action_lib/actions.json | 56 ----------- .../create_text_file_and_write_something.py | 36 ------- .../action_lib/code/enable_do_not_disturb.py | 20 ---- jarvis/action_lib/code/execute_sql.py | 58 ------------ jarvis/action_lib/code/install_package.py | 16 ---- jarvis/action_lib/code/open_document.py | 28 ------ jarvis/action_lib/code/open_picture.py | 11 --- jarvis/action_lib/code/organize_app_layout.py | 18 ---- jarvis/action_lib/code/play_light_music.py | 32 ------- jarvis/action_lib/code/set_20_minute_alarm.py | 50 ---------- jarvis/action_lib/code/turn_on_dark_mode.py | 36 ------- jarvis/action_lib/code/turn_on_light_mode.py | 35 ------- jarvis/action_lib/code/unzip_files.py | 26 ------ jarvis/action_lib/code/zip_files.py | 40 -------- jarvis/action_lib/vectordb/chroma.sqlite3 | Bin 708608 -> 708608 bytes jarvis/agent/jarvis_agent.py | 88 ++++++++++++------ jarvis/agent/prompt.py | 3 +- jarvis/core/action_manager.py | 55 +++++------ working_dir/agent.txt | 4 + .../code/check_weather.py | 0 .../code/python_interpreter.py | 0 38 files changed, 185 insertions(+), 552 deletions(-) create mode 100644 examples/9_zip_and_unzip_new.py delete mode 100644 jarvis/action_lib/action_description/check_weather.txt delete mode 100644 jarvis/action_lib/action_description/create_text_file_and_write_something.txt delete mode 100644 jarvis/action_lib/action_description/enable_do_not_disturb.txt delete mode 100644 jarvis/action_lib/action_description/execute_sql.txt delete mode 100644 jarvis/action_lib/action_description/open_document.txt delete mode 100644 jarvis/action_lib/action_description/open_picture.txt delete mode 100644 jarvis/action_lib/action_description/organize_app_layout.txt delete mode 100644 jarvis/action_lib/action_description/play_light_music.txt delete mode 100644 jarvis/action_lib/action_description/python_interpreter.txt delete mode 100644 jarvis/action_lib/action_description/set_20_minute_alarm.txt delete mode 100644 jarvis/action_lib/action_description/turn_on_dark_mode.txt delete mode 100644 jarvis/action_lib/action_description/turn_on_light_mode.txt delete mode 100644 jarvis/action_lib/action_description/unzip_files.txt delete mode 100644 jarvis/action_lib/action_description/zip_files.txt delete mode 100644 jarvis/action_lib/code/create_text_file_and_write_something.py delete mode 100644 jarvis/action_lib/code/enable_do_not_disturb.py delete mode 100644 jarvis/action_lib/code/execute_sql.py delete mode 100644 jarvis/action_lib/code/open_document.py delete mode 100644 jarvis/action_lib/code/open_picture.py delete mode 100644 jarvis/action_lib/code/organize_app_layout.py delete mode 100644 jarvis/action_lib/code/play_light_music.py delete mode 100644 jarvis/action_lib/code/set_20_minute_alarm.py delete mode 100644 jarvis/action_lib/code/turn_on_dark_mode.py delete mode 100644 jarvis/action_lib/code/turn_on_light_mode.py delete mode 100644 jarvis/action_lib/code/unzip_files.py delete mode 100644 jarvis/action_lib/code/zip_files.py create mode 100644 working_dir/agent.txt rename {jarvis/action_lib => working_dir}/code/check_weather.py (100%) rename {jarvis/action_lib => working_dir}/code/python_interpreter.py (100%) diff --git a/examples/11_file_classification_new.py b/examples/11_file_classification_new.py index 10147d7..5ea3e8b 100644 --- a/examples/11_file_classification_new.py +++ b/examples/11_file_classification_new.py @@ -1,6 +1,6 @@ from jarvis.agent.openai_agent import OpenAIAgent from jarvis.environment.py_env import PythonEnv -from jarvis.agent.jarvis_agent import ExecutionModule +from jarvis.agent.jarvis_agent import ExecutionModule, JarvisAgent ''' Made By DZC & WZM @@ -17,7 +17,8 @@ action_lib_path = "../jarvis/action_lib" # use to look up existed skill code and extract information retrieve_agent = OpenAIAgent(config_path="./config.json", action_lib_dir=action_lib_path) # use to create new skills -execute_agent = ExecutionModule(config_path="./config.json", action_lib_dir=action_lib_path) +jarvis_agent = JarvisAgent(config_path="./config.json", action_lib_dir=action_lib_path) +execute_agent = jarvis_agent.executor # We assume that the response result comes from the task planning agent. response = ''' @@ -80,6 +81,7 @@ for action, description in zip(actions, task_descriptions): # If the task still cannot be completed, an error message will be reported. if need_mend == True: print("I can't Do this Task!!") + break else: # The task is completed, save the code, args_description, action_description in lib execute_agent.store_action(action, current_code) diff --git a/examples/9_zip_and_unzip_new.py b/examples/9_zip_and_unzip_new.py new file mode 100644 index 0000000..602b17d --- /dev/null +++ b/examples/9_zip_and_unzip_new.py @@ -0,0 +1,86 @@ +from jarvis.agent.openai_agent import OpenAIAgent +from jarvis.environment.py_env import PythonEnv +from jarvis.agent.jarvis_agent import ExecutionModule, JarvisAgent + +''' +Made By DZC & WZM +target: Classify files in a specified folder. +''' + +# path of action lib +action_lib_path = "../jarvis/action_lib" +# args_description_path = action_lib_path + "/args_description" +# action_description_path = action_lib_path + "/action_description" +# code_path = action_lib_path + "/code" +# vectordb_path = action_lib_path + "/vectordb" + +# use to look up existed skill code and extract information +retrieve_agent = OpenAIAgent(config_path="./config.json", action_lib_dir=action_lib_path) +# use to create new skills +jarvis_agent = JarvisAgent(config_path="./config.json", action_lib_dir=action_lib_path) +execute_agent = jarvis_agent.executor + +# We assume that the response result comes from the task planning agent. +response = ''' +Thought: In order to solve this task, first search the txt text in the document file in the working directory. If the text contains the word "agent", put the path of the text into agent.txt and wrap it in a new line. The second step is put the retrieved files into the folder named agent, the path of the retrieved files is placed in the txt file named agent, Each line is the path of a file. + +Actions: +1. zip_files Zip all the files in the folder called test2 and name the zip file as test2.zip. +2. unzip_files Unzip test2.zip in the folder called test2 to the folder called test. +Check local action_lib, the required action code is in the library, according to the function description in the code, combined with the information provided by the user, You can instantiate classes for different tasks. + +''' + +# Get actions and corresponding descriptions +actions = retrieve_agent.extract_information(response, begin_str='', end_str='') +task_descriptions = retrieve_agent.extract_information(response, begin_str='', end_str='') + +# Loop all the actions +for action, description in zip(actions, task_descriptions): + # Create python tool class code + code = execute_agent.generate_action(action, description) + print(code) + + # Execute python tool class code + state = execute_agent.execute_action(code, description) + print(state) + + # Check whether the code runs correctly, if not, amend the code + need_mend = False + trial_times = 0 + critique = '' + # If no error is reported, check whether the task is completed + if state.error == None: + critique, score = execute_agent.judge_action(code, description, state) + if score <= 8: + print("critique: {}".format(critique)) + need_mend = True + else: + need_mend = True + # The code failed to complete its task, fix the code + current_code = code + while (trial_times < execute_agent.max_iter and need_mend == True): + trial_times += 1 + print("current amend times: {}".format(trial_times)) + new_code = execute_agent.amend_action(current_code, description, state, critique) + current_code = new_code + # Run the current code and check for errors + state = execute_agent.execute_action(current_code, description) + print(state) + # Recheck + if state.error == None: + critique, score = execute_agent.judge_action(current_code, description, state) + # The task execution is completed and the loop exits + if score > 8: + need_mend = False + break + print("critique: {}".format(critique)) + else: # The code still needs to be corrected + need_mend = True + + # If the task still cannot be completed, an error message will be reported. + if need_mend == True: + print("I can't Do this Task!!") + else: # The task is completed, save the code, args_description, action_description in lib + execute_agent.store_action(action, current_code) + diff --git a/examples/config.json b/examples/config.json index 18b456b..5d86d42 100644 --- a/examples/config.json +++ b/examples/config.json @@ -1,5 +1,5 @@ { - "model_name": "gpt-3.5-turbo-1106", + "model_name": "gpt-4-1106-preview", "OPENAI_API_KEY": "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", "OPENAI_ORGANIZATION": "org-fSyygvftM73W0pK4VjoK395W", "config": { @@ -11,7 +11,7 @@ "LLM_type": "OpenAI", "LLM": { "temperature": 0.0, - "model": "gpt-3.5-turbo-1106", + "model": "gpt-4-1106-preview", "log_path": "logs/god" }, "agents": { diff --git a/jarvis/action_lib/action_description/check_weather.txt b/jarvis/action_lib/action_description/check_weather.txt deleted file mode 100644 index 56593a8..0000000 --- a/jarvis/action_lib/action_description/check_weather.txt +++ /dev/null @@ -1 +0,0 @@ -check the weather of the target place \ No newline at end of file diff --git a/jarvis/action_lib/action_description/create_text_file_and_write_something.txt b/jarvis/action_lib/action_description/create_text_file_and_write_something.txt deleted file mode 100644 index a89f9fa..0000000 --- a/jarvis/action_lib/action_description/create_text_file_and_write_something.txt +++ /dev/null @@ -1 +0,0 @@ -Create a text file and write something in it. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/enable_do_not_disturb.txt b/jarvis/action_lib/action_description/enable_do_not_disturb.txt deleted file mode 100644 index c6d3e9b..0000000 --- a/jarvis/action_lib/action_description/enable_do_not_disturb.txt +++ /dev/null @@ -1 +0,0 @@ -enable do not disturb mode \ No newline at end of file diff --git a/jarvis/action_lib/action_description/execute_sql.txt b/jarvis/action_lib/action_description/execute_sql.txt deleted file mode 100644 index 65b7721..0000000 --- a/jarvis/action_lib/action_description/execute_sql.txt +++ /dev/null @@ -1 +0,0 @@ -Using turn_on_light_mode() will change your system into the light mode. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/open_document.txt b/jarvis/action_lib/action_description/open_document.txt deleted file mode 100644 index df006d4..0000000 --- a/jarvis/action_lib/action_description/open_document.txt +++ /dev/null @@ -1 +0,0 @@ -open the target document in your offered file path. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/open_picture.txt b/jarvis/action_lib/action_description/open_picture.txt deleted file mode 100644 index 24eb124..0000000 --- a/jarvis/action_lib/action_description/open_picture.txt +++ /dev/null @@ -1 +0,0 @@ -Using open_picture() will open the picture you want. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/organize_app_layout.txt b/jarvis/action_lib/action_description/organize_app_layout.txt deleted file mode 100644 index 13cd3d1..0000000 --- a/jarvis/action_lib/action_description/organize_app_layout.txt +++ /dev/null @@ -1 +0,0 @@ -Using organize_app_layout() will help user reorganize their Desktop layout for better working condition and focus more easily. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/play_light_music.txt b/jarvis/action_lib/action_description/play_light_music.txt deleted file mode 100644 index 86f84f7..0000000 --- a/jarvis/action_lib/action_description/play_light_music.txt +++ /dev/null @@ -1 +0,0 @@ -play light music \ No newline at end of file diff --git a/jarvis/action_lib/action_description/python_interpreter.txt b/jarvis/action_lib/action_description/python_interpreter.txt deleted file mode 100644 index a6a319f..0000000 --- a/jarvis/action_lib/action_description/python_interpreter.txt +++ /dev/null @@ -1,16 +0,0 @@ -用来执行Python代码。代码必须是一个函数, -函数名必须得是 'solution',代码对应你的思考过程。代码实例格式如下: -```python -# import 依赖包 -import time -def solution(): - # 初始化一些变量 - print("hello world!") - # 步骤一 - #mid_variable = func(variable_names_with_real_meaning) - # 步骤 x - #mid_variable = func(mid_variable) - # 最后结果 - #final_answer = func(mid_variable) - return "return!" -``` \ No newline at end of file diff --git a/jarvis/action_lib/action_description/set_20_minute_alarm.txt b/jarvis/action_lib/action_description/set_20_minute_alarm.txt deleted file mode 100644 index 84a11d4..0000000 --- a/jarvis/action_lib/action_description/set_20_minute_alarm.txt +++ /dev/null @@ -1 +0,0 @@ -set 20 minute alarm \ No newline at end of file diff --git a/jarvis/action_lib/action_description/turn_on_dark_mode.txt b/jarvis/action_lib/action_description/turn_on_dark_mode.txt deleted file mode 100644 index 9469f95..0000000 --- a/jarvis/action_lib/action_description/turn_on_dark_mode.txt +++ /dev/null @@ -1 +0,0 @@ -Using turn_on_dark_mode() will change your system into the dark mode. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/turn_on_light_mode.txt b/jarvis/action_lib/action_description/turn_on_light_mode.txt deleted file mode 100644 index 65b7721..0000000 --- a/jarvis/action_lib/action_description/turn_on_light_mode.txt +++ /dev/null @@ -1 +0,0 @@ -Using turn_on_light_mode() will change your system into the light mode. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/unzip_files.txt b/jarvis/action_lib/action_description/unzip_files.txt deleted file mode 100644 index 203826b..0000000 --- a/jarvis/action_lib/action_description/unzip_files.txt +++ /dev/null @@ -1 +0,0 @@ -Unzip test2.zip in the folder called test2 to the folder called test. \ No newline at end of file diff --git a/jarvis/action_lib/action_description/zip_files.txt b/jarvis/action_lib/action_description/zip_files.txt deleted file mode 100644 index 5dca9f5..0000000 --- a/jarvis/action_lib/action_description/zip_files.txt +++ /dev/null @@ -1 +0,0 @@ -Zip all the files in the specified folder \ No newline at end of file diff --git a/jarvis/action_lib/actions.json b/jarvis/action_lib/actions.json index 0d7fc2e..38254eb 100644 --- a/jarvis/action_lib/actions.json +++ b/jarvis/action_lib/actions.json @@ -1,40 +1,8 @@ { - "open_picture": { - "code": "from jarvis.action.base_action import BaseAction\n\n\nclass open_picture(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"Using open_picture() will open the picture you want.\"\n self.action_type = 'BASH'\n\n def __call__(self, *args, **kwargs):\n return 'shortcuts run \"open_picture\"'\n", - "description": "Using open_picture() will open the picture you want." - }, "view_cpu_usage": { "code": "import os\nfrom jarvis.action.base_action import BaseAction\nimport subprocess\n\nclass view_cpu_usage(BaseAction):\n def __init__(self):\n self._description = \"Open the terminal interface and view the system's CPU usage.\"\n\n def __call__(self, working_directory=None, *args, **kwargs):\n \"\"\"\n Open the terminal interface and view the system's CPU usage.\n\n Args:\n working_directory (str): The working directory where the terminal will be opened.\n \n Returns:\n None\n \"\"\"\n # Check if working_directory is provided, if not, use the current working directory\n if working_directory:\n # Change the current working directory to the provided working_directory\n os.chdir(working_directory)\n \n # Open the terminal and call relevant instructions to view the system's CPU usage\n subprocess.run([\"gnome-terminal\", \"--\", \"top\"])\n", "description": "Open the terminal interface and view the system's CPU usage." }, - "create_text_file_and_write_something": { - "code": "from jarvis.action.base_action import BaseAction\nimport os\n\nclass create_text_file_and_write_something(BaseAction):\n def __init__(self):\n self._description = \"Create a text file and write something in it.\"\n\n def __call__(self, working_directory, folder_name, file_name, content):\n \"\"\"\n Create a text file and write something in it.\n\n Args:\n working_directory (str): The working directory where the folder and file will be created.\n folder_name (str): The name of the folder where the file will be created.\n file_name (str): The name of the text file to be created.\n content (str): The content to be written in the text file.\n\n Returns:\n None\n \"\"\"\n # Change the current working directory to the specified working directory\n os.chdir(working_directory)\n\n # Create the folder if it doesn't exist\n folder_path = os.path.join(working_directory, folder_name)\n if not os.path.exists(folder_path):\n os.makedirs(folder_path)\n\n # Create and write to the text file\n file_path = os.path.join(folder_path, file_name)\n with open(file_path, 'w') as file:\n file.write(content)\n\n# Example of how to use the class\n# create_text_file_and_write_something_instance = create_text_file_and_write_something()\n# create_text_file_and_write_something_instance(working_directory='/home/heroding/\u684c\u9762/Jarvis/working_dir', folder_name='myfold', file_name='result.txt', content='hello world')\n", - "description": "Create a text file and write something in it." - }, - "open_document": { - "code": "from jarvis.action.base_action import BaseAction\nfrom jarvis.atom_action.operations.media import view_office_document, play_video, play_audio, view_txt\nfrom jarvis.action.get_os_version import get_os_version, check_os_version\n\nclass open_document(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"open the target document in your offered file path.\"\n self.system_version = get_os_version()\n try:\n check_os_version(self.system_version)\n except ValueError as e:\n print(e)\n self.action_type = 'BASH'\n\n def __call__(self, path: str, type: str, *args, **kwargs):\n # \u5982\u679c\u662foffcie\u6587\u4ef6\n if type == 'doc' or type == 'docx' or type == 'ppt' or type == 'pptx' or type == 'xls' or type == 'xlsx' or type == 'pdf':\n view_office_document(path)\n # \u5982\u679c\u662f\u89c6\u9891\u6587\u4ef6\n elif type == 'avi' or type == 'mp4' or type == 'mkv':\n play_video(path)\n # \u5982\u679c\u662f\u97f3\u9891\u6587\u4ef6\n elif type == 'mp3' or type == 'wav':\n play_audio(path)\n # \u5982\u679c\u662f\u6587\u672c\u6587\u4ef6\u6216\u8005\u5176\u5b83\u6587\u4ef6\n else:\n view_txt(path)\n", - "description": "open the target document in your offered file path." - }, - "organize_app_layout": { - "code": "from jarvis.action.base_action import BaseAction\n\n\nclass organize_app_layout(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"Using organize_app_layout() will help user reorganize their Desktop layout for better working condition and focus more easily.\"\n self._timeout = 15\n\n def __call__(self, *args, **kwargs):\n return 'shortcuts run \"Organize APP Layout\"'\n\n # @property\n # def _command(self) -> str:\n # return 'shortcuts run \"Organize APP Layout\"'\n #\n # def _success(self) -> str:\n # return \"Successfully organized the app's layout\"\n", - "description": "Using organize_app_layout() will help user reorganize their Desktop layout for better working condition and focus more easily." - }, - "set_20_minute_alarm": { - "code": "from jarvis.action.base_action import BaseAction\n# from jarvis.atom_action.operations.system import terminal_show_file_content\n# import requests\nimport subprocess\nimport datetime\n\n\nclass set_20_minute_alarm(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"set 20 minute alarm\"\n self.action_type = 'Python'\n\n def __call__(self) -> None:\n # Sets an alarm for 20 minutes from now using AppleScript\n # The script creates a new reminder with an alert\n current_time = datetime.datetime.now()\n alarm_time = current_time + datetime.timedelta(minutes=20)\n alarm_time_str = alarm_time.strftime('%Y-%m-%d %H:%M:%S')\n\n applescript = f\"\"\"\n tell application \"Reminders\"\n set newReminder to make new reminder\n tell newReminder\n set name to \"20 Minute Alarm\"\n set remind me date to date \"{alarm_time_str}\"\n end tell\n end tell\n \"\"\"\n subprocess.run([\"osascript\", \"-e\", applescript])\n\n# def set_20_minute_alarm():\n# # Sets an alarm for 20 minutes from now using AppleScript\n# # The script creates a new reminder with an alert\n# current_time = datetime.datetime.now()\n# alarm_time = current_time + datetime.timedelta(minutes=20)\n# alarm_time_str = alarm_time.strftime('%Y-%m-%d %H:%M:%S')\n\n# applescript = f\"\"\"\n# tell application \"Reminders\"\n# set newReminder to make new reminder\n# tell newReminder\n# set name to \"20 Minute Alarm\"\n# set remind me date to date \"{alarm_time_str}\"\n# end tell\n# end tell\n# \"\"\"\n# subprocess.run([\"osascript\", \"-e\", applescript])\n\n# set_20_minute_alarm()\n", - "description": "set 20 minute alarm" - }, - "play_light_music": { - "code": "from jarvis.action.base_action import BaseAction\n# from jarvis.atom_action.operations.system import terminal_show_file_content\n# import requests\nimport subprocess\n\n\nclass play_light_music(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"play light music\"\n self.action_type = 'Python'\n\n def __call__(self) -> None:\n # This function uses AppleScript to enable Do Not Disturb mode on a Mac.\n applescript = \"\"\"\n tell application \"Music\"\n play playlist \"light music\"\n end tell\n \"\"\"\n subprocess.run([\"osascript\", \"-e\", applescript])\n\n\n# def play_light_music():\n# # Plays a playlist named \"light music\" in iTunes or Music app\n# applescript = \"\"\"\n# tell application \"Music\"\n# play playlist \"light music\"\n# end tell\n# \"\"\"\n# subprocess.run([\"osascript\", \"-e\", applescript])\n\n# play_light_music()\n", - "description": "play light music" - }, - "enable_do_not_disturb": { - "code": "from jarvis.action.base_action import BaseAction\n# from jarvis.atom_action.operations.system import terminal_show_file_content\n# import requests\nimport subprocess\n\n\nclass enable_do_not_disturb(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"enable do not disturb mode\"\n self.action_type = 'Python'\n\n def __call__(self) -> None:\n # This function uses AppleScript to enable Do Not Disturb mode on a Mac.\n applescript = f\"\"\"\n tell application \"Shortcuts Events\"\n run shortcut \"enable_do_not_disturb\"\n end tell\n \"\"\"\n subprocess.run([\"osascript\", \"-e\", applescript])\n", - "description": "enable do not disturb mode" - }, - "unzip_files": { - "code": "from jarvis.action.base_action import BaseAction\nimport os\nimport zipfile\n\nclass unzip_files(BaseAction):\n def __init__(self):\n self._description = \"Unzip test2.zip in the folder called test2 to the folder called test.\"\n\n def __call__(self, *args, **kwargs):\n # Get the working directory from the user-provided information\n working_dir = \"/home/heroding/\u684c\u9762/Jarvis/working_dir\"\n\n # Change the current working directory to the specified working directory\n os.chdir(working_dir)\n\n # Define the source zip file and the destination folder\n source_zip = \"test2/test2.zip\"\n destination_folder = \"test\"\n\n # Unzip the files\n with zipfile.ZipFile(source_zip, 'r') as zip_ref:\n zip_ref.extractall(destination_folder)\n\n# Example of how to use the class:\n# unzip_task = unzip_files()\n# unzip_task()\n", - "description": "Unzip test2.zip in the folder called test2 to the folder called test." - }, "create_folder": { "code": "from jarvis.action.base_action import BaseAction\nimport os\n\nclass create_folder(BaseAction):\n def __init__(self):\n self._description = \"Create a folder under the default working directory.\"\n\n def __call__(self, working_directory=None, folder_name='myfold', *args, **kwargs):\n \"\"\"\n Create a folder under the specified working directory or the default working directory.\n\n Args:\n working_directory (str): The path of the working directory. If not provided, the default working directory will be used.\n folder_name (str): The name of the folder to be created. Default is 'myfold'.\n\n Returns:\n None\n \"\"\"\n # Check if the working_directory is provided, if not, use the default working directory\n if working_directory:\n os.chdir(working_directory)\n\n # Create the folder\n os.makedirs(folder_name)\n\n# Example of how to use the class\n# create_folder_action = create_folder()\n# create_folder_action(working_directory='/home/heroding/\u684c\u9762/Jarvis/working_dir', folder_name='my_new_folder')\n", "description": "Create a folder under the default working directory." @@ -43,32 +11,8 @@ "code": "from jarvis.action.base_action import BaseAction\nimport subprocess\nimport os\n\nclass open_text_file(BaseAction):\n def __init__(self):\n self._description = \"Open the specified text file in the specified folder using the default text viewer on Ubuntu.\"\n\n def __call__(self, folder_name, file_name, working_directory=None):\n \"\"\"\n Open the specified text file in the specified folder using the default text viewer on Ubuntu.\n\n Args:\n folder_name (str): The name of the folder containing the text file.\n file_name (str): The name of the text file to be opened.\n working_directory (str, optional): The working directory where the folder is located. If not provided, the current working directory will be used.\n\n Returns:\n None\n \"\"\"\n # If the working directory is provided, use it. Otherwise, use the current working directory.\n if working_directory:\n os.chdir(working_directory)\n\n # Construct the file path\n file_path = os.path.join(folder_name, file_name)\n\n # Open the text file using the default text viewer on Ubuntu\n subprocess.run(['xdg-open', file_path])\n\n# Example of how to use the class:\n# open_file_task = open_text_file()\n# open_file_task(folder_name='myfold', file_name='result.txt', working_directory='/home/heroding/\u684c\u9762/Jarvis/working_dir')\n", "description": "Open the specified text file in the specified folder using the default text viewer on Ubuntu." }, - "execute_sql": { - "code": "from jarvis.action.base_action import BaseAction\n\n\n_COMMAND = \"\"\"\nfrom jarvis.action_lib.execute_sql import execute_sql\naction = execute_sql()\naction.run(db_path='../tasks/travel/database/travel.db', query='PRAGMA table_info(railway)')\n\"\"\"\n\n\nclass execute_sql(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"Using turn_on_light_mode() will change your system into the light mode.\"\n\n def __call__(self, query: str = 'PRAGMA table_info(railway)'):\n if not query:\n return \"No query, return\"\n import sqlite3\n\n # conn = sqlite3.connect('../../tasks/travel/database/travel.db') \u539f\u6765\n conn = sqlite3.connect('../tasks/travel/database/travel.db') # wzm\u4fee\u6539\uff0c\u5c06\u6570\u636e\u5e93\u8def\u5f84\u6539\u4e3a\u76f8\u5bf9\u4e8e\u5de5\u4f5c\u76ee\u5f55\u7684\n cursor = conn.cursor()\n results = {\n \"query\": query,\n \"result\": None,\n \"error\": None\n }\n try:\n cursor.execute(query)\n results['result'] = cursor.fetchall()\n except Exception as e:\n results['error'] = str(e)\n conn.commit()\n conn.close()\n\n return results\n # @property\n # def _command(self):\n # return self._python(_COMMAND)\n\n # def _success(self):\n # return \"Successfully turned the system into the Light Mode\"\n\n # def __call__(self, *args, **kwargs):\n #\n # command = 'shortcuts run \"Dark Mode\"'\n # try:\n # # result = subprocess.run([command, \"Dark Mode\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n # result = subprocess.run([command], capture_output=True, check=True,\n # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL)\n # if result.returncode == 0:\n # return result\n # except subprocess.CalledProcessError as e:\n # return e\n # except subprocess.TimeoutExpired:\n # raise TimeoutError(f\"Command '{command}' timed out after {self.timeout} seconds.\")\n\n", - "description": "Using turn_on_light_mode() will change your system into the light mode." - }, "install_package": { "code": "from jarvis.action.base_action import BaseAction\nimport subprocess\nimport sys\n\n\nclass install_package(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"install environment missing package.\"\n self.action_type = 'BASH'\n\n def __call__(self, package: str, *args, **kwargs):\n\n \"\"\"\n Install a Python package using pip.\n\n Args:\n package_name (str): Name of the package to install.\n \"\"\"\n try:\n subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])\n print(f\"Package '{package}' installed successfully.\")\n except subprocess.CalledProcessError as e:\n print(f\"Failed to install package '{package}'. Error: {e}\")\n \n # try:\n # # \u68c0\u67e5pip\u662f\u5426\u5df2\u5b89\u88c5\n # print(\"check pip ...\")\n # subprocess.check_call([sys.executable, '-m', 'pip', '--version'])\n # except subprocess.CalledProcessError:\n # # \u5b89\u88c5pip\n # print(\"Installing pip...\")\n # subprocess.check_call([sys.executable, '-m', 'ensurepip'])\n\n # # \u5b89\u88c5\u6307\u5b9a\u7684\u5305\n # try:\n # print(f\"Installing {package}...\")\n # subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])\n # print(f\"{package} installed successfully.\")\n # except subprocess.CalledProcessError:\n # print(f\"Failed to install {package}.\") \n\n", "description": "install environment missing package." - }, - "turn_on_light_mode": { - "code": "from jarvis.action.base_action import BaseAction\n\n\nclass turn_on_light_mode(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"Using turn_on_light_mode() will change your system into the light mode.\"\n\n def __call__(self, *args, **kwargs):\n return 'shortcuts run \"Light Mode\"'\n\n # @property\n # def _command(self):\n # return 'shortcuts run \"Light Mode\"'\n # return self._python(\n # self._import(\"atom\", \"operations\"),\n # \"adjust_theme('Adwaita')\"\n # )\n\n # def _success(self):\n # return \"Successfully turned the system into the Light Mode\"\n\n # def __call__(self, *args, **kwargs):\n #\n # command = 'shortcuts run \"Dark Mode\"'\n # try:\n # # result = subprocess.run([command, \"Dark Mode\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n # result = subprocess.run([command], capture_output=True, check=True,\n # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL)\n # if result.returncode == 0:\n # return result\n # except subprocess.CalledProcessError as e:\n # return e\n # except subprocess.TimeoutExpired:\n # raise TimeoutError(f\"Command '{command}' timed out after {self.timeout} seconds.\")\n", - "description": "Using turn_on_light_mode() will change your system into the light mode." - }, - "zip_files": { - "code": "from jarvis.action.base_action import BaseAction\nimport os\nimport zipfile\n\nclass zip_files(BaseAction):\n def __init__(self):\n self._description = \"Zip all the files in the specified folder\"\n\n def __call__(self, folder_name):\n \"\"\"\n Zip all the files in the specified folder and name the zip file as the folder name.\n\n Args:\n folder_name (str): The name of the folder containing the files to be zipped.\n\n Returns:\n None\n \"\"\"\n try:\n # Get the current working directory\n current_dir = os.getcwd()\n\n # Change the current working directory to the specified folder\n os.chdir(folder_name)\n\n # Get the list of files in the folder\n file_list = os.listdir()\n\n # Create a zip file with the folder name\n with zipfile.ZipFile(f\"{folder_name}.zip\", \"w\") as zipf:\n # Add each file in the folder to the zip file\n for file in file_list:\n zipf.write(file)\n\n except FileNotFoundError as e:\n print(f\"Error: {e}\")\n\n finally:\n # Change the working directory back to the original directory\n os.chdir(current_dir)\n", - "description": "Zip all the files in the specified folder" - }, - "turn_on_dark_mode": { - "code": "from jarvis.action.base_action import BaseAction\n\n\nclass turn_on_dark_mode(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"Using turn_on_dark_mode() will change your system into the dark mode.\"\n self.action_type = 'BASH'\n\n def __call__(self, *args, **kwargs):\n return 'shortcuts run \"Dark Mode\"'\n\n # @property\n # def _command(self):\n # return 'shortcuts run \"Dark Mode\"'\n # return self._python(\n # self._import(\"atom\", \"operations\"),\n # \"adjust_theme('Adwaita-dark')\"\n # )\n\n # def _success(self):\n # return \"Successfully turned the system into the Dark Mode\"\n\n # def __call__(self, *args, **kwargs):\n #\n # command = 'shortcuts run \"Dark Mode\"'\n # try:\n # # result = subprocess.run([command, \"Dark Mode\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n # result = subprocess.run([command], capture_output=True, check=True,\n # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL)\n # if result.returncode == 0:\n # return result\n # except subprocess.CalledProcessError as e:\n # return e\n # except subprocess.TimeoutExpired:\n # raise TimeoutError(f\"Command '{command}' timed out after {self.timeout} seconds.\")\n", - "description": "Using turn_on_dark_mode() will change your system into the dark mode." - }, - "python_interpreter": { - "code": "import copy\nimport io\nfrom contextlib import redirect_stdout\nfrom typing import Any, Optional\n\nfrom jarvis.action.base_action import BaseAction\nfrom jarvis.core.schema import ActionReturn\n\n\nclass GenericRuntime:\n GLOBAL_DICT = {}\n LOCAL_DICT = None\n HEADERS = []\n\n def __init__(self):\n self._global_vars = copy.copy(self.GLOBAL_DICT)\n self._local_vars = copy.copy(\n self.LOCAL_DICT) if self.LOCAL_DICT else None\n\n for c in self.HEADERS:\n self.exec_code(c)\n\n def exec_code(self, code_piece: str) -> None:\n exec(code_piece, self._global_vars)\n\n def eval_code(self, expr: str) -> Any:\n return eval(expr, self._global_vars)\n\n\nDEFAULT_DESCRIPTION = \"\"\"\u7528\u6765\u6267\u884cPython\u4ee3\u7801\u3002\u4ee3\u7801\u5fc5\u987b\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\n\u51fd\u6570\u540d\u5fc5\u987b\u5f97\u662f 'solution'\uff0c\u4ee3\u7801\u5bf9\u5e94\u4f60\u7684\u601d\u8003\u8fc7\u7a0b\u3002\u4ee3\u7801\u5b9e\u4f8b\u683c\u5f0f\u5982\u4e0b\uff1a\n```python\n# import \u4f9d\u8d56\u5305\nimport time\ndef solution():\n # \u521d\u59cb\u5316\u4e00\u4e9b\u53d8\u91cf\n print(\"hello world!\")\n # \u6b65\u9aa4\u4e00\n #mid_variable = func(variable_names_with_real_meaning)\n # \u6b65\u9aa4 x\n #mid_variable = func(mid_variable)\n # \u6700\u540e\u7ed3\u679c\n #final_answer = func(mid_variable)\n return \"return!\"\n```\"\"\"\n\n\nclass python_interpreter(BaseAction):\n \"\"\"A Python executor that can execute Python scripts.\n\n Args:\n description (str): The description of the action. Defaults to\n DEFAULT_DESCRIPTION.\n answer_symbol (str, Optional): the answer symbol from LLM\n answer_expr (str, Optional): the answer function name of the Python\n script. Default to 'solution()'.\n answer_from_stdout (boolean): whether the execution results is from\n stdout.\n name (str, optional): The name of the action. If None, the name will\n be class nameDefaults to None.\n timeout (int): Upper bound of waiting time for Python script execution.\n \"\"\"\n\n def __init__(self,\n description: str = DEFAULT_DESCRIPTION,\n answer_symbol: Optional[str] = None,\n answer_expr: Optional[str] = 'solution()',\n answer_from_stdout: bool = False,\n name: Optional[str] = None,\n timeout: int = 20) -> None:\n super().__init__(description, name, timeout)\n\n self.answer_symbol = answer_symbol\n self.answer_expr = answer_expr\n self.answer_from_stdout = answer_from_stdout\n\n def __call__(self, command: str) -> ActionReturn:\n self.runtime = GenericRuntime()\n self._call(command)\n\n def _call(self, command: str) -> ActionReturn:\n tool_return = ActionReturn(url=None, args=None, type=self.name)\n try:\n if '```python' in command:\n command = command.split('```python')[1].split('```')[0]\n elif '```' in command:\n command = command.split('```')[1].split('```')[0]\n tool_return.args = dict(text='```python\\n' + command + '\\n```')\n command = command.split('\\n')\n\n if self.answer_from_stdout:\n program_io = io.StringIO()\n with redirect_stdout(program_io):\n self.runtime.exec_code('\\n'.join(command))\n program_io.seek(0)\n res = program_io.readlines()[-1]\n elif self.answer_symbol:\n self.runtime.exec_code('\\n'.join(command))\n res = self.runtime._global_vars[self.answer_symbol]\n elif self.answer_expr:\n self.runtime.exec_code('\\n'.join(command))\n res = self.runtime.eval_code(self.answer_expr)\n else:\n self.runtime.exec_code('\\n'.join(command[:-1]))\n res = self.runtime.eval_code(command[-1])\n except Exception as e:\n tool_return.errmsg = repr(e)\n tool_return.type = self.name\n # tool_return.state = ActionStatusCode.API_ERROR\n return tool_return\n try:\n tool_return.result = dict(text=str(res))\n # tool_return.state = ActionStatusCode.SUCCESS\n except Exception as e:\n tool_return.errmsg = repr(e)\n tool_return.type = self.name\n # tool_return.state = ActionStatusCode.API_ERROR\n return tool_return\n", - "description": "\u7528\u6765\u6267\u884cPython\u4ee3\u7801\u3002\u4ee3\u7801\u5fc5\u987b\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\n\u51fd\u6570\u540d\u5fc5\u987b\u5f97\u662f 'solution'\uff0c\u4ee3\u7801\u5bf9\u5e94\u4f60\u7684\u601d\u8003\u8fc7\u7a0b\u3002\u4ee3\u7801\u5b9e\u4f8b\u683c\u5f0f\u5982\u4e0b\uff1a\n```python\n# import \u4f9d\u8d56\u5305\nimport time\ndef solution():\n # \u521d\u59cb\u5316\u4e00\u4e9b\u53d8\u91cf\n print(\"hello world!\")\n # \u6b65\u9aa4\u4e00\n #mid_variable = func(variable_names_with_real_meaning)\n # \u6b65\u9aa4 x\n #mid_variable = func(mid_variable)\n # \u6700\u540e\u7ed3\u679c\n #final_answer = func(mid_variable)\n return \"return!\"\n```" - }, - "check_weather": { - "code": "from jarvis.action.base_action import BaseAction\nfrom jarvis.atom_action.operations.system import terminal_show_file_content\nimport requests\nimport tempfile\n\nclass check_weather(BaseAction):\n def __init__(self) -> None:\n super().__init__()\n self._description = \"check the weather of the target place\"\n self.action_type = 'BASH'\n\n def __call__(self, *places) -> None:\n # \u4f8b\u5b50curl wttr.in/anhui?m\n placeStr = \"\"\n if(len(places) > 1):\n placeStr = \"+\".join(places[::-1])\n elif(len(places) == 1):\n placeStr = places[0]\n weather_api = \"http://wttr.in/{place}?m?\".format(place=placeStr)\n response = requests.get(weather_api)\n res = \"\u6682\u65e0\u5929\u6c14\u6570\u636e\"\n if(response != None):\n res = response.text\n terminal_show_file_content\n with tempfile.NamedTemporaryFile('w', delete=True) as temp:\n temp.write(res)\n temp.flush()\n terminal_show_file_content(temp.name)\n\n\n\n\n", - "description": "check the weather of the target place" } } \ No newline at end of file diff --git a/jarvis/action_lib/code/create_text_file_and_write_something.py b/jarvis/action_lib/code/create_text_file_and_write_something.py deleted file mode 100644 index 1d959b7..0000000 --- a/jarvis/action_lib/code/create_text_file_and_write_something.py +++ /dev/null @@ -1,36 +0,0 @@ -from jarvis.action.base_action import BaseAction -import os - -class create_text_file_and_write_something(BaseAction): - def __init__(self): - self._description = "Create a text file and write something in it." - - def __call__(self, working_directory, folder_name, file_name, content): - """ - Create a text file and write something in it. - - Args: - working_directory (str): The working directory where the folder and file will be created. - folder_name (str): The name of the folder where the file will be created. - file_name (str): The name of the text file to be created. - content (str): The content to be written in the text file. - - Returns: - None - """ - # Change the current working directory to the specified working directory - os.chdir(working_directory) - - # Create the folder if it doesn't exist - folder_path = os.path.join(working_directory, folder_name) - if not os.path.exists(folder_path): - os.makedirs(folder_path) - - # Create and write to the text file - file_path = os.path.join(folder_path, file_name) - with open(file_path, 'w') as file: - file.write(content) - -# Example of how to use the class -# create_text_file_and_write_something_instance = create_text_file_and_write_something() -# create_text_file_and_write_something_instance(working_directory='/home/heroding/桌面/Jarvis/working_dir', folder_name='myfold', file_name='result.txt', content='hello world') diff --git a/jarvis/action_lib/code/enable_do_not_disturb.py b/jarvis/action_lib/code/enable_do_not_disturb.py deleted file mode 100644 index 2198520..0000000 --- a/jarvis/action_lib/code/enable_do_not_disturb.py +++ /dev/null @@ -1,20 +0,0 @@ -from jarvis.action.base_action import BaseAction -# from jarvis.atom_action.operations.system import terminal_show_file_content -# import requests -import subprocess - - -class enable_do_not_disturb(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "enable do not disturb mode" - self.action_type = 'Python' - - def __call__(self) -> None: - # This function uses AppleScript to enable Do Not Disturb mode on a Mac. - applescript = f""" - tell application "Shortcuts Events" - run shortcut "enable_do_not_disturb" - end tell - """ - subprocess.run(["osascript", "-e", applescript]) diff --git a/jarvis/action_lib/code/execute_sql.py b/jarvis/action_lib/code/execute_sql.py deleted file mode 100644 index e9513e6..0000000 --- a/jarvis/action_lib/code/execute_sql.py +++ /dev/null @@ -1,58 +0,0 @@ -from jarvis.action.base_action import BaseAction - - -_COMMAND = """ -from jarvis.action_lib.execute_sql import execute_sql -action = execute_sql() -action.run(db_path='../tasks/travel/database/travel.db', query='PRAGMA table_info(railway)') -""" - - -class execute_sql(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "Using turn_on_light_mode() will change your system into the light mode." - - def __call__(self, query: str = 'PRAGMA table_info(railway)'): - if not query: - return "No query, return" - import sqlite3 - - # conn = sqlite3.connect('../../tasks/travel/database/travel.db') 原来 - conn = sqlite3.connect('../tasks/travel/database/travel.db') # wzm修改,将数据库路径改为相对于工作目录的 - cursor = conn.cursor() - results = { - "query": query, - "result": None, - "error": None - } - try: - cursor.execute(query) - results['result'] = cursor.fetchall() - except Exception as e: - results['error'] = str(e) - conn.commit() - conn.close() - - return results - # @property - # def _command(self): - # return self._python(_COMMAND) - - # def _success(self): - # return "Successfully turned the system into the Light Mode" - - # def __call__(self, *args, **kwargs): - # - # command = 'shortcuts run "Dark Mode"' - # try: - # # result = subprocess.run([command, "Dark Mode"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - # result = subprocess.run([command], capture_output=True, check=True, - # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL) - # if result.returncode == 0: - # return result - # except subprocess.CalledProcessError as e: - # return e - # except subprocess.TimeoutExpired: - # raise TimeoutError(f"Command '{command}' timed out after {self.timeout} seconds.") - diff --git a/jarvis/action_lib/code/install_package.py b/jarvis/action_lib/code/install_package.py index 63593e5..6238eb0 100644 --- a/jarvis/action_lib/code/install_package.py +++ b/jarvis/action_lib/code/install_package.py @@ -23,20 +23,4 @@ class install_package(BaseAction): except subprocess.CalledProcessError as e: print(f"Failed to install package '{package}'. Error: {e}") - # try: - # # 检查pip是否已安装 - # print("check pip ...") - # subprocess.check_call([sys.executable, '-m', 'pip', '--version']) - # except subprocess.CalledProcessError: - # # 安装pip - # print("Installing pip...") - # subprocess.check_call([sys.executable, '-m', 'ensurepip']) - - # # 安装指定的包 - # try: - # print(f"Installing {package}...") - # subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) - # print(f"{package} installed successfully.") - # except subprocess.CalledProcessError: - # print(f"Failed to install {package}.") diff --git a/jarvis/action_lib/code/open_document.py b/jarvis/action_lib/code/open_document.py deleted file mode 100644 index 61f8957..0000000 --- a/jarvis/action_lib/code/open_document.py +++ /dev/null @@ -1,28 +0,0 @@ -from jarvis.action.base_action import BaseAction -from jarvis.atom_action.operations.media import view_office_document, play_video, play_audio, view_txt -from jarvis.action.get_os_version import get_os_version, check_os_version - -class open_document(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "open the target document in your offered file path." - self.system_version = get_os_version() - try: - check_os_version(self.system_version) - except ValueError as e: - print(e) - self.action_type = 'BASH' - - def __call__(self, path: str, type: str, *args, **kwargs): - # 如果是offcie文件 - if type == 'doc' or type == 'docx' or type == 'ppt' or type == 'pptx' or type == 'xls' or type == 'xlsx' or type == 'pdf': - view_office_document(path) - # 如果是视频文件 - elif type == 'avi' or type == 'mp4' or type == 'mkv': - play_video(path) - # 如果是音频文件 - elif type == 'mp3' or type == 'wav': - play_audio(path) - # 如果是文本文件或者其它文件 - else: - view_txt(path) diff --git a/jarvis/action_lib/code/open_picture.py b/jarvis/action_lib/code/open_picture.py deleted file mode 100644 index e6f2c2d..0000000 --- a/jarvis/action_lib/code/open_picture.py +++ /dev/null @@ -1,11 +0,0 @@ -from jarvis.action.base_action import BaseAction - - -class open_picture(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "Using open_picture() will open the picture you want." - self.action_type = 'BASH' - - def __call__(self, *args, **kwargs): - return 'shortcuts run "open_picture"' diff --git a/jarvis/action_lib/code/organize_app_layout.py b/jarvis/action_lib/code/organize_app_layout.py deleted file mode 100644 index cb46293..0000000 --- a/jarvis/action_lib/code/organize_app_layout.py +++ /dev/null @@ -1,18 +0,0 @@ -from jarvis.action.base_action import BaseAction - - -class organize_app_layout(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "Using organize_app_layout() will help user reorganize their Desktop layout for better working condition and focus more easily." - self._timeout = 15 - - def __call__(self, *args, **kwargs): - return 'shortcuts run "Organize APP Layout"' - - # @property - # def _command(self) -> str: - # return 'shortcuts run "Organize APP Layout"' - # - # def _success(self) -> str: - # return "Successfully organized the app's layout" diff --git a/jarvis/action_lib/code/play_light_music.py b/jarvis/action_lib/code/play_light_music.py deleted file mode 100644 index e12d8c1..0000000 --- a/jarvis/action_lib/code/play_light_music.py +++ /dev/null @@ -1,32 +0,0 @@ -from jarvis.action.base_action import BaseAction -# from jarvis.atom_action.operations.system import terminal_show_file_content -# import requests -import subprocess - - -class play_light_music(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "play light music" - self.action_type = 'Python' - - def __call__(self) -> None: - # This function uses AppleScript to enable Do Not Disturb mode on a Mac. - applescript = """ - tell application "Music" - play playlist "light music" - end tell - """ - subprocess.run(["osascript", "-e", applescript]) - - -# def play_light_music(): -# # Plays a playlist named "light music" in iTunes or Music app -# applescript = """ -# tell application "Music" -# play playlist "light music" -# end tell -# """ -# subprocess.run(["osascript", "-e", applescript]) - -# play_light_music() diff --git a/jarvis/action_lib/code/set_20_minute_alarm.py b/jarvis/action_lib/code/set_20_minute_alarm.py deleted file mode 100644 index 4a698f4..0000000 --- a/jarvis/action_lib/code/set_20_minute_alarm.py +++ /dev/null @@ -1,50 +0,0 @@ -from jarvis.action.base_action import BaseAction -# from jarvis.atom_action.operations.system import terminal_show_file_content -# import requests -import subprocess -import datetime - - -class set_20_minute_alarm(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "set 20 minute alarm" - self.action_type = 'Python' - - def __call__(self) -> None: - # Sets an alarm for 20 minutes from now using AppleScript - # The script creates a new reminder with an alert - current_time = datetime.datetime.now() - alarm_time = current_time + datetime.timedelta(minutes=20) - alarm_time_str = alarm_time.strftime('%Y-%m-%d %H:%M:%S') - - applescript = f""" - tell application "Reminders" - set newReminder to make new reminder - tell newReminder - set name to "20 Minute Alarm" - set remind me date to date "{alarm_time_str}" - end tell - end tell - """ - subprocess.run(["osascript", "-e", applescript]) - -# def set_20_minute_alarm(): -# # Sets an alarm for 20 minutes from now using AppleScript -# # The script creates a new reminder with an alert -# current_time = datetime.datetime.now() -# alarm_time = current_time + datetime.timedelta(minutes=20) -# alarm_time_str = alarm_time.strftime('%Y-%m-%d %H:%M:%S') - -# applescript = f""" -# tell application "Reminders" -# set newReminder to make new reminder -# tell newReminder -# set name to "20 Minute Alarm" -# set remind me date to date "{alarm_time_str}" -# end tell -# end tell -# """ -# subprocess.run(["osascript", "-e", applescript]) - -# set_20_minute_alarm() diff --git a/jarvis/action_lib/code/turn_on_dark_mode.py b/jarvis/action_lib/code/turn_on_dark_mode.py deleted file mode 100644 index 0d23752..0000000 --- a/jarvis/action_lib/code/turn_on_dark_mode.py +++ /dev/null @@ -1,36 +0,0 @@ -from jarvis.action.base_action import BaseAction - - -class turn_on_dark_mode(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "Using turn_on_dark_mode() will change your system into the dark mode." - self.action_type = 'BASH' - - def __call__(self, *args, **kwargs): - return 'shortcuts run "Dark Mode"' - - # @property - # def _command(self): - # return 'shortcuts run "Dark Mode"' - # return self._python( - # self._import("atom", "operations"), - # "adjust_theme('Adwaita-dark')" - # ) - - # def _success(self): - # return "Successfully turned the system into the Dark Mode" - - # def __call__(self, *args, **kwargs): - # - # command = 'shortcuts run "Dark Mode"' - # try: - # # result = subprocess.run([command, "Dark Mode"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - # result = subprocess.run([command], capture_output=True, check=True, - # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL) - # if result.returncode == 0: - # return result - # except subprocess.CalledProcessError as e: - # return e - # except subprocess.TimeoutExpired: - # raise TimeoutError(f"Command '{command}' timed out after {self.timeout} seconds.") diff --git a/jarvis/action_lib/code/turn_on_light_mode.py b/jarvis/action_lib/code/turn_on_light_mode.py deleted file mode 100644 index 1933dc8..0000000 --- a/jarvis/action_lib/code/turn_on_light_mode.py +++ /dev/null @@ -1,35 +0,0 @@ -from jarvis.action.base_action import BaseAction - - -class turn_on_light_mode(BaseAction): - def __init__(self) -> None: - super().__init__() - self._description = "Using turn_on_light_mode() will change your system into the light mode." - - def __call__(self, *args, **kwargs): - return 'shortcuts run "Light Mode"' - - # @property - # def _command(self): - # return 'shortcuts run "Light Mode"' - # return self._python( - # self._import("atom", "operations"), - # "adjust_theme('Adwaita')" - # ) - - # def _success(self): - # return "Successfully turned the system into the Light Mode" - - # def __call__(self, *args, **kwargs): - # - # command = 'shortcuts run "Dark Mode"' - # try: - # # result = subprocess.run([command, "Dark Mode"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - # result = subprocess.run([command], capture_output=True, check=True, - # text=True, shell=True, timeout=self.timeout, stdin=subprocess.DEVNULL) - # if result.returncode == 0: - # return result - # except subprocess.CalledProcessError as e: - # return e - # except subprocess.TimeoutExpired: - # raise TimeoutError(f"Command '{command}' timed out after {self.timeout} seconds.") diff --git a/jarvis/action_lib/code/unzip_files.py b/jarvis/action_lib/code/unzip_files.py deleted file mode 100644 index 9f7536a..0000000 --- a/jarvis/action_lib/code/unzip_files.py +++ /dev/null @@ -1,26 +0,0 @@ -from jarvis.action.base_action import BaseAction -import os -import zipfile - -class unzip_files(BaseAction): - def __init__(self): - self._description = "Unzip test2.zip in the folder called test2 to the folder called test." - - def __call__(self, *args, **kwargs): - # Get the working directory from the user-provided information - working_dir = "/home/heroding/桌面/Jarvis/working_dir" - - # Change the current working directory to the specified working directory - os.chdir(working_dir) - - # Define the source zip file and the destination folder - source_zip = "test2/test2.zip" - destination_folder = "test" - - # Unzip the files - with zipfile.ZipFile(source_zip, 'r') as zip_ref: - zip_ref.extractall(destination_folder) - -# Example of how to use the class: -# unzip_task = unzip_files() -# unzip_task() diff --git a/jarvis/action_lib/code/zip_files.py b/jarvis/action_lib/code/zip_files.py deleted file mode 100644 index 0dd1143..0000000 --- a/jarvis/action_lib/code/zip_files.py +++ /dev/null @@ -1,40 +0,0 @@ -from jarvis.action.base_action import BaseAction -import os -import zipfile - -class zip_files(BaseAction): - def __init__(self): - self._description = "Zip all the files in the specified folder" - - def __call__(self, folder_name): - """ - Zip all the files in the specified folder and name the zip file as the folder name. - - Args: - folder_name (str): The name of the folder containing the files to be zipped. - - Returns: - None - """ - try: - # Get the current working directory - current_dir = os.getcwd() - - # Change the current working directory to the specified folder - os.chdir(folder_name) - - # Get the list of files in the folder - file_list = os.listdir() - - # Create a zip file with the folder name - with zipfile.ZipFile(f"{folder_name}.zip", "w") as zipf: - # Add each file in the folder to the zip file - for file in file_list: - zipf.write(file) - - except FileNotFoundError as e: - print(f"Error: {e}") - - finally: - # Change the working directory back to the original directory - os.chdir(current_dir) diff --git a/jarvis/action_lib/vectordb/chroma.sqlite3 b/jarvis/action_lib/vectordb/chroma.sqlite3 index 47acc55e2613f46251ec0c66f52dd54a2852fe80..5226c0bcaa2ad3e59eaaad330f473ed0f24e440c 100644 GIT binary patch delta 17708 zcmb`vcU)6VvpAldB=jVxh*$|WtVmNKI|oI@24cm66%hrc2`Ki6y*EU}-g`$yvU6vg_btr;4hXt!`B{ zdsKI0c0fdmR=+`&PouWlwRfOr)osuE^)O`5Y*kik*rwV}&o*awjf~Q&RO&VaB|`1% zq(7|E>Z4Tp8Tu&0D?^C*aenfD|Ik}aowY7)R09cEl2(6MolLj-tF=K|LgrnMDuhfk ztzocgC_NvP{i;Xx?0!9rT4NPeCf!J<8$mR?>Ly)Wjnvyms2uFBYV3XOZa9WJ{4yBz z^BwLxta2D{KifV{Ure{=fBv|vcG|3)s%!P1fAS-H{nl#j`l><*xLJHDJ3F+LR`*-g zh;D>vX|gx;<#qOrzG+&=zUt2TUZxJ}>{amxwT7Bnf4cI~X3tN`k<^#z`+4=8S=xMU z>aV*Iw^a`M3o2uRQ8wD?FBs+~&nnUY#{ zO|?U8d|FCUjJZ!r?4YE$(2|i|MfyD&6P#)M$S2B zS76smeZr`Y&OM)^_EAUgPF4S=tKFm3+EiDqai2hIp>dz_lkuhTL4n&_b-qzuf#$NG zGHEpZQRlw=t@beJjMr7hZ^pOAC&qim>p8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5&;&*yC?>8nJr7AS(X8pWqXFcsY7 zq)M6WXsD%{lq_M!K}x)#bJat9x+QF|#Vi*9u8bdP!ID%hf)PMnTVwaa5NYnv_9 zi?E@KvslJZkGs+*8nDnJ|79S)}Yd=xnlD<3B(lsaMt)8+W&sJDM zR(Jn!WGGmla$-Ww<4daZUbdm^QW_2ihm7vU+qiBYFar?Ev@$=Ah%3F>h^ivL!mI7WA5N!aCoS&JGp9wDghwi z^9B-E*9uzRH@iTFKCA?bOyaiz-e2%aY(FgGNFxAj7J&Jm0{$ji{pd@{RoGaTX~*ue z0h^Nj81QL$QAc18cNvZWGk$XDIM21i<(9hT6QETISe}AY6r4{Aq(~78MBf6#mRYci{HQ07s$T=WU`eCEYB}TT0 zJji+=OfdjE2VQ0XYv1o<0M_o~?9xtW+sUvQ-D|#nyzF4Z)?VJjc&vp(?2>gz2mUni zLI-kfU>s{t?q)#Nia~bC+B?9o*8b~EjCZ09(=2A~r!humZ4@KZ3uR$gYkTxCENg^r z2C!SUau*x5x_v*R*`{e-USii0y^JuhwRgH0fVprl14x!RqU0Lqn%}#Jzl_A3Kfy>= zlMln_a~|ZfX!U|Z$_R{SweF-#R6NMS8l3Gy9}?7*xE?`Ipr+XO16J@)h|T`I+gugJuXSgB~qS+@3?(sz7dW!V_tQD`Z zi%KT)#zti@t_ykL(IZNtq9I-f*@l0TCh;9)?2H&**Q2Z%y zoo{?7nbHOOgWE|ZA 0] -print("\nRows where column A is greater than 0:") -pint(filtered_df) - - -''',"Use pandas to operate on random arrays", ''' -Traceback (most recent call last): - File "/home/heroding/桌面/Jarvis/working_dir/test.py", line 18, in + # 筛选出A列值大于0的行 + filtered_df = df[df['A'] > 0] + print("\nRows where column A is greater than 0:") pint(filtered_df) - ^^^^ -NameError: name 'pint' is not defined. Did you mean: 'print'? -''', "/home/heroding/桌面/Jarvis/tasks/travel/run_task", "cache general.py __pycache__ run.py serve.py simulator.py") + + + ''',"Use pandas to operate on random arrays", ''' + Traceback (most recent call last): + File "/home/heroding/桌面/Jarvis/working_dir/test.py", line 18, in + pint(filtered_df) + ^^^^ + NameError: name 'pint' is not defined. Did you mean: 'print'? + ''', "/home/heroding/桌面/Jarvis/tasks/travel/run_task", "cache general.py __pycache__ run.py serve.py simulator.py") diff --git a/jarvis/agent/prompt.py b/jarvis/agent/prompt.py index b536e22..dc52ffb 100644 --- a/jarvis/agent/prompt.py +++ b/jarvis/agent/prompt.py @@ -157,8 +157,9 @@ prompt = { ''', '_LINUX_USER_TASK_DECOMPOSE_PROMPT' : ''' User's information are as follows: - Task: {task} System Version: {system_version} + Task: {task} + Action List: {action_list} ''', }, diff --git a/jarvis/core/action_manager.py b/jarvis/core/action_manager.py index 31bee2b..8f72823 100644 --- a/jarvis/core/action_manager.py +++ b/jarvis/core/action_manager.py @@ -47,7 +47,7 @@ class ActionManager: @property def programs(self): programs = "" - for action_name, entry in self.actions.items(): + for _, entry in self.actions.items(): programs += f"{entry['code']}\n\n" return programs @@ -155,29 +155,32 @@ class ActionManager: f"\033[33m delete {action} args description txt successfully! \033[0m" ) -# demo -# actionManager = ActionManager(config_path="../../examples/config.json", action_lib_dir="../action_lib", retrieval_top_k=1) -# sys.path.append('../action_lib/code') -# # 添加所有任务代码 -# files = glob.glob("../action_lib/code" + "/*.py") -# for file in files: -# if file.endswith('.py') and "__init__" not in file: -# class_name = file[:-3].split('/')[-1] # 去除.py后缀,获取类名 -# print(f"当前类:{class_name}") -# module = importlib.import_module(class_name) -# # get origin code -# source_code = inspect.getsource(module) -# # get class object -# tmp_obj = getattr(module, class_name)() -# # 报错到向量数据库和字典 -# actionManager.add_new_action({ -# "task_name": class_name, -# "code": source_code, -# "description": tmp_obj.description -# }) -# # 检索 -# res = actionManager.retrieve_actions("give me a picture from web") -# print(res[0]) -# 删除 -# actionManager.delete_action("retrieve_document") \ No newline at end of file +if __name__ == '__main__': + actionManager = ActionManager(config_path="../../examples/config.json", action_lib_dir="../action_lib", retrieval_top_k=1) + # action_list = json.dumps(actionManager.descriptions) + # print(action_list) + # sys.path.append('../action_lib/code') + # # 添加所有任务代码 + # files = glob.glob("../action_lib/code" + "/*.py") + # for file in files: + # if file.endswith('.py') and "__init__" not in file: + # class_name = file[:-3].split('/')[-1] # 去除.py后缀,获取类名 + # print(f"当前类:{class_name}") + # module = importlib.import_module(class_name) + # # get origin code + # source_code = inspect.getsource(module) + # # get class object + # tmp_obj = getattr(module, class_name)() + # # 报错到向量数据库和字典 + # actionManager.add_new_action({ + # "task_name": class_name, + # "code": source_code, + # "description": tmp_obj.description + # }) + # # 检索 + # res = actionManager.retrieve_actions("give me a picture from web") + # print(res[0]) + + # 删除 + actionManager.delete_action("retrieve_document") \ No newline at end of file diff --git a/working_dir/agent.txt b/working_dir/agent.txt new file mode 100644 index 0000000..90e2e45 --- /dev/null +++ b/working_dir/agent.txt @@ -0,0 +1,4 @@ +/home/heroding/桌面/Jarvis/working_dir/document/4.txt +/home/heroding/桌面/Jarvis/working_dir/document/3.txt +/home/heroding/桌面/Jarvis/working_dir/document/1.txt +/home/heroding/桌面/Jarvis/working_dir/document/2.txt diff --git a/jarvis/action_lib/code/check_weather.py b/working_dir/code/check_weather.py similarity index 100% rename from jarvis/action_lib/code/check_weather.py rename to working_dir/code/check_weather.py diff --git a/jarvis/action_lib/code/python_interpreter.py b/working_dir/code/python_interpreter.py similarity index 100% rename from jarvis/action_lib/code/python_interpreter.py rename to working_dir/code/python_interpreter.py