mirror of
https://github.com/OS-Copilot/OS-Copilot.git
synced 2026-01-10 04:28:00 -05:00
del action
This commit is contained in:
5
config.json
Normal file
5
config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"model_name": "gpt-4-1106-preview",
|
||||
"OPENAI_API_KEY": "",
|
||||
"OPENAI_ORGANIZATION": ""
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.agent.linux_skill_create_agent import LinuxSkillCreateAgent
|
||||
import time
|
||||
'''
|
||||
Made By DZC & WZM
|
||||
target: View system CPU usage.
|
||||
'''
|
||||
# environment
|
||||
environment = PythonEnv()
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
# use to look up existed skill code and extract information
|
||||
retrieve_agent = OpenAIAgent(config_path="./config.json")
|
||||
# use to create new skills
|
||||
skill_create_agent = LinuxSkillCreateAgent(config_path="./config.json")
|
||||
|
||||
# We assume that the response result comes from the task planning agent.
|
||||
response = '''
|
||||
Thought: In order to solve this task, we need to open the terminal interface in the current operating system environment and call relevant instructions on this terminal to view the system's CPU usage.
|
||||
|
||||
Actions:
|
||||
1. <action>view_cpu_usage</action> <description>open the terminal interface in the current operating system environment and call relevant instructions on the terminal to view the system's CPU usage.</description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# Loop all the actions
|
||||
for action, description in zip(actions, task_descriptions):
|
||||
# Create python tool class code
|
||||
create_msg = skill_create_agent.skill_create_format_message(task_name=action, task_description=description, working_dir=environment.working_dir)
|
||||
code = skill_create_agent.extract_python_code(create_msg)
|
||||
print(code)
|
||||
|
||||
# Create the invoke of the tool class
|
||||
invoke_msg = skill_create_agent.invoke_generate_format_message(code, description,working_dir=environment.working_dir)
|
||||
invoke = skill_create_agent.extract_information(invoke_msg, begin_str='<invoke>', end_str='</invoke>')[0]
|
||||
print("************************<invoke>**************************")
|
||||
print(invoke)
|
||||
print("************************</invoke>*************************")
|
||||
code = code + '\n' + invoke
|
||||
|
||||
# Run the tool code
|
||||
state = environment.step(code)
|
||||
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:
|
||||
judge_result = skill_create_agent.task_judge_format_message(code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
if judge == False:
|
||||
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 < 3 and need_mend == True):
|
||||
trial_times += 1
|
||||
print("current amend times: {}".format(trial_times))
|
||||
amend_msg = skill_create_agent.skill_amend_format_message(current_code, description, state.error, state.result, state.pwd, state.ls, critique)
|
||||
print(amend_msg)
|
||||
new_code = skill_create_agent.extract_python_code(amend_msg)
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = environment.step(current_code)
|
||||
print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
judge_result = skill_create_agent.task_judge_format_message(current_code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
# The task execution is completed and the loop exits
|
||||
if judge == True:
|
||||
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 in lib
|
||||
file_path = action_lib_path + "/" + action + '.py'
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
lines = current_code.strip().splitlines()
|
||||
if lines:
|
||||
# Remove the invoke code of the python file
|
||||
lines.pop()
|
||||
final_code = '\n'.join(lines)
|
||||
f.write(final_code)
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.agent.linux_skill_create_agent import LinuxSkillCreateAgent
|
||||
import time
|
||||
'''
|
||||
Made By DZC & WZM
|
||||
target: Classify files in a specified folder.
|
||||
'''
|
||||
# environment
|
||||
environment = PythonEnv()
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
args_description_lib_path = action_lib_path + "/args_description_lib"
|
||||
action_description_lib_path = action_lib_path + "/action_description_lib"
|
||||
# use to look up existed skill code and extract information
|
||||
retrieve_agent = OpenAIAgent(config_path="./config.json")
|
||||
# use to create new skills
|
||||
skill_create_agent = LinuxSkillCreateAgent(config_path="./config.json")
|
||||
|
||||
# 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. <action>retrieve_document</action> <description>search the txt text in the folder call document in the working directory. If the text contains the word "agent", put the full path of the text into agent.txt and wrap it in a new line.</description>
|
||||
2. <action>organize_document</action> <description>put the retrieved files into the folder named agent, the path of the retrieved files is placed in the txt file named agent.txt, Each line is the path of a file.</description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# Loop all the actions
|
||||
for action, description in zip(actions, task_descriptions):
|
||||
# Create python tool class code
|
||||
create_msg = skill_create_agent.skill_create_format_message(task_name=action, task_description=description, working_dir=environment.working_dir)
|
||||
code = skill_create_agent.extract_python_code(create_msg)
|
||||
print(code)
|
||||
|
||||
# Create the invoke of the tool class
|
||||
invoke_msg = skill_create_agent.invoke_generate_format_message(code, description,working_dir=environment.working_dir)
|
||||
invoke = skill_create_agent.extract_information(invoke_msg, begin_str='<invoke>', end_str='</invoke>')[0]
|
||||
print("************************<invoke>**************************")
|
||||
print(invoke)
|
||||
print("************************</invoke>*************************")
|
||||
code = code + '\n' + invoke
|
||||
|
||||
# Run the tool code
|
||||
state = environment.step(code)
|
||||
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:
|
||||
judge_result = skill_create_agent.task_judge_format_message(code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
score = int(judge_result['score'])
|
||||
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 < 3 and need_mend == True):
|
||||
trial_times += 1
|
||||
print("current amend times: {}".format(trial_times))
|
||||
amend_msg = skill_create_agent.skill_amend_format_message(current_code, description, state.error, state.result, state.pwd, state.ls, critique)
|
||||
print(amend_msg)
|
||||
new_code = skill_create_agent.extract_python_code(amend_msg)
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = environment.step(current_code)
|
||||
print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
judge_result = skill_create_agent.task_judge_format_message(current_code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
score = int(judge_result['score'])
|
||||
# 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 in lib
|
||||
code_file_path = action_lib_path + '/' + action + '.py'
|
||||
args_description_file_path = args_description_lib_path + '/' + action + '.txt'
|
||||
action_description_file_path = action_description_lib_path + '/' + action + '.txt'
|
||||
args_description = skill_create_agent.extract_args_description(current_code)
|
||||
action_description = skill_create_agent.extract_action_description(current_code)
|
||||
with open(code_file_path, 'w', encoding='utf-8') as f:
|
||||
lines = current_code.strip().splitlines()
|
||||
if lines:
|
||||
# Remove the invoke code of the python file
|
||||
lines.pop()
|
||||
final_code = '\n'.join(lines)
|
||||
f.write(final_code)
|
||||
with open(args_description_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(args_description)
|
||||
with open(action_description_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(action_description)
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
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"
|
||||
working_dir_path = "../working_dir"
|
||||
# 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. <action>retrieve_document</action> <description>search the txt text in the folder call document in the working directory. If the text contains the word "agent", put the full path of the text into agent.txt and wrap it in a new line.</description>
|
||||
2. <action>organize_document</action> <description>put the retrieved files into the folder named agent, the path of the retrieved files is placed in the txt file named agent.txt, Each line is the path of a file.</description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# Loop all the actions
|
||||
for action, description in zip(actions, task_descriptions):
|
||||
# Create python tool class code
|
||||
code = execute_agent.generate_action(action, description)
|
||||
# Execute python tool class code
|
||||
state = execute_agent.execute_action(code, description)
|
||||
# Check whether the code runs correctly, if not, amend the code
|
||||
need_mend = False
|
||||
trial_times = 0
|
||||
critique = ''
|
||||
score = 0
|
||||
# If no error is reported, check whether the task is completed
|
||||
if state.error == None:
|
||||
critique, judge, score = execute_agent.judge_action(code, description, state)
|
||||
if not judge:
|
||||
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)
|
||||
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, judge, score = execute_agent.judge_action(current_code, description, state)
|
||||
# The task execution is completed and the loop exits
|
||||
if judge:
|
||||
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, if code is save the code, args_description, action_description in lib
|
||||
if score >= 8:
|
||||
execute_agent.store_action(action, current_code)
|
||||
@@ -1,31 +0,0 @@
|
||||
import os
|
||||
|
||||
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
# from jarvis.enviroment.old_env import BaseEnviroment
|
||||
from jarvis.environment.bash_env import BashEnv
|
||||
|
||||
|
||||
'''
|
||||
A minimal example for base env and openai agent
|
||||
The goal of this example is to demonstrate how agent parse response to get actions, and env execute those actions.
|
||||
'''
|
||||
|
||||
# environment = BaseEnviroment()
|
||||
environment = BashEnv()
|
||||
agent = OpenAIAgent(config_path="examples/config.json")
|
||||
|
||||
response = '''
|
||||
Thought: To set up the working environment, we can focus on two sub-goals: turning on dark mode and organizing the app layout.
|
||||
|
||||
Actions:
|
||||
1. <action>turn_on_dark_mode</action>
|
||||
2. <action>turn_on_light_mode</action>'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
import time
|
||||
for a in action:
|
||||
command = agent.action_lib[a]
|
||||
print(a, command)
|
||||
print(environment.step(command))
|
||||
time.sleep(2)
|
||||
@@ -1,30 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.old_env import BaseEnviroment
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
'''
|
||||
A minimal example for base env and openai agent
|
||||
The goal of this example is to demonstrate how agent parse response to get actions, and env execute those actions.
|
||||
'''
|
||||
|
||||
# environment = BaseEnviroment()
|
||||
environment = PythonEnv()
|
||||
agent = OpenAIAgent(config_path="config.json")
|
||||
|
||||
response = '''
|
||||
Thought: To set up the working environment, we can focus on two sub-goals: turning on dark mode and organizing the app layout.
|
||||
|
||||
Actions:
|
||||
1. <action>execute_sql</action>'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
import time
|
||||
for a in action:
|
||||
command = agent.action_lib[a] + '\nprint({tool_name}()())'.format(tool_name=a)
|
||||
# print(a, command)
|
||||
print(environment.step(command).result)
|
||||
# time.sleep(2)
|
||||
|
||||
# from jarvis.action_lib.execute_sql import execute_sql as ExecuteSQL
|
||||
|
||||
# action = ExecuteSQL()
|
||||
# action(query='SELECT * FROM railway\nWHERE number="D1000";')
|
||||
@@ -1,55 +0,0 @@
|
||||
from jarvis.action_lib.python_interpreter import PythonInterpreter, DEFAULT_DESCRIPTION
|
||||
|
||||
|
||||
# a = PythonInterpreter()
|
||||
# a(DEFAULT_DESCRIPTION)
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
# 执行 cd 命令
|
||||
current_dir = os.getcwd()
|
||||
print("当前工作目录:", current_dir)
|
||||
|
||||
command = 'gogogo && cd .. && pwd'
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
stout = result.stdout.strip().split('\n')
|
||||
out = "\n".join(stout[:-1])
|
||||
pwd = stout[-1]
|
||||
|
||||
print("out", out)
|
||||
print("pwd", pwd)
|
||||
print(result.stderr)
|
||||
|
||||
# 打印当前目录
|
||||
print("当前目录:", current_dir)
|
||||
#
|
||||
# self.env_state = EnvState()
|
||||
# self.env_state.command.append(_command)
|
||||
# command = _command + self.log_execute
|
||||
# subprocess.run(["tmux", "send-keys", "-t", self.server_name, command, "Enter"])
|
||||
# time.sleep(self.timeout)
|
||||
# self.observe()
|
||||
# return self.env_state
|
||||
#
|
||||
#
|
||||
# command = "pwd" + self.log_state
|
||||
# subprocess.run(["tmux", "send-keys", "-t", self.server_name, command, "Enter"])
|
||||
# time.sleep(1)
|
||||
# self.env_state.pwd = self.read_log(self.state_log_path)
|
||||
# self.working_dir = self.env_state.pwd[0].strip()
|
||||
# # print("working dir:", self.working_dir)
|
||||
# result = subprocess.run(['ls'], cwd=self.working_dir, capture_output=True, text=True)
|
||||
# self.env_state.ls = [result.stdout]
|
||||
# # 输出执行结果
|
||||
# # print(result.stdout)
|
||||
# # for _command in ["pwd", "ls"]:
|
||||
# # command = _command + self.log_state
|
||||
# # subprocess.run(["tmux", "send-keys", "-t", self.server_name, command, "Enter"])
|
||||
# # # todo 处理异步的问题,可能提交过去还没执行完。
|
||||
# # time.sleep(self.timeout)
|
||||
# # if _command == "pwd":
|
||||
# # self.env_state.pwd = self.read_log(self.state_log_path)
|
||||
# # else:
|
||||
# # self.env_state.ls = self.read_log(self.state_log_path)
|
||||
# self.env_state.result = self.read_log(self.execute_log_path)
|
||||
@@ -1,39 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.agent.skill_creator import SkillCreator
|
||||
# from jarvis.enviroment.old_env import BaseEnviroment
|
||||
from jarvis.environment.bash_env import BashEnv
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
|
||||
'''
|
||||
A minimal example for creating new skills
|
||||
'''
|
||||
|
||||
# environment = BaseEnviroment()
|
||||
environment = PythonEnv()
|
||||
agent = OpenAIAgent(config_path="examples/config.json")
|
||||
skill_creator = SkillCreator(config_path="examples/config.json")
|
||||
|
||||
response = '''
|
||||
Thought: Taking a 20-minute break means we can focus on the following three sub-tasks: 1. Enable Do Not Disturb mode; 2. Play some light music; 3. Set a 20-minute alarm.
|
||||
|
||||
Actions:
|
||||
0. <action>set_30_minute_alarm</action>
|
||||
1. <action>enable_do_not_disturb</action>
|
||||
2. <action>play_light_music</action>
|
||||
3. <action>set_20_minute_alarm</action>'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
import time
|
||||
for a in action:
|
||||
if a in agent.action_lib:
|
||||
command = agent.action_lib[a]
|
||||
print("Successfully read the '{}' command from the action lib.".format(a))
|
||||
else:
|
||||
print("There is no '{}' command in the action lib and a new one needs to be created.".format(a))
|
||||
response = skill_creator.format_message(a)
|
||||
print(response)
|
||||
|
||||
|
||||
print(a, command)
|
||||
print(environment.step(command))
|
||||
time.sleep(2)
|
||||
@@ -1,29 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
|
||||
'''
|
||||
Made By DZC
|
||||
The function is to be able to open any type of document.
|
||||
'''
|
||||
|
||||
environment = PythonEnv()
|
||||
agent = OpenAIAgent(config_path="examples/config.json")
|
||||
|
||||
response = '''
|
||||
Thought: To open a document named , we can focus on one goal: open the specified document(word, pdf, pptx, txt etc.).
|
||||
|
||||
Actions:
|
||||
1. <action>open_document</action>
|
||||
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.
|
||||
|
||||
|
||||
invoke:
|
||||
1. <invoke>open_document()("/home/heroding/桌面/rnn.pptx" , "pptx")</invoke>
|
||||
'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
invoke = agent.extract_invoke(response, begin_str='<invoke>', end_str='</invoke>')
|
||||
|
||||
for (i, a) in enumerate(action):
|
||||
command = agent.action_lib[a] + "\n" + invoke[i]
|
||||
print(environment.step(command).result)
|
||||
@@ -1,29 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.old_env import BaseEnviroment
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.environment.bash_env import BashEnv
|
||||
import time
|
||||
'''
|
||||
Made By WZM
|
||||
用处:查看指定区域这几天的天气
|
||||
'''
|
||||
|
||||
# environment = BaseEnviroment()
|
||||
environment = PythonEnv()
|
||||
agent = OpenAIAgent(config_path="config.json")
|
||||
|
||||
response = '''
|
||||
Thought: To set up the working environment, we can focus on two sub-goals: turning on dark mode and organizing the app layout.
|
||||
|
||||
Actions:
|
||||
1. <action>check_weather</action> <invoke>check_weather()("shanghai","putuo")</invoke>
|
||||
|
||||
'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
invoke = agent.extract_action(response, begin_str='<invoke>', end_str='</invoke>')
|
||||
|
||||
for (i,a) in enumerate(action):
|
||||
command = agent.action_lib[a] + "\n" + invoke[i]
|
||||
print(environment.step(command).result)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
|
||||
'''
|
||||
Made By DZC
|
||||
The function is to install environment missing package.
|
||||
'''
|
||||
|
||||
environment = PythonEnv()
|
||||
agent = OpenAIAgent(config_path="config.json")
|
||||
|
||||
response = '''
|
||||
Thought: To install environment missing package , we can focus on one goal: run "pip install xxx" in Bash.
|
||||
|
||||
Actions:
|
||||
1. <action>install_package</action>
|
||||
|
||||
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.
|
||||
|
||||
invoke:
|
||||
1. <invoke>install_package()("numpy")</invoke>
|
||||
'''
|
||||
|
||||
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
|
||||
invoke = agent.extract_invoke(response, begin_str='<invoke>', end_str='</invoke>')
|
||||
|
||||
for (i, a) in enumerate(action):
|
||||
command = agent.action_lib[a] + "\n" + invoke[i]
|
||||
print(environment.step(command).result)
|
||||
@@ -1,102 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.agent.linux_skill_creator import LinuxSkillCreator
|
||||
from jarvis.agent.linux_skill_amend import LinuxSkillAmend
|
||||
from jarvis.agent.linux_invoke_generator import LinuxInvokeGenerator
|
||||
from jarvis.agent.linux_task_judger import LinuxTaskJudger
|
||||
'''
|
||||
Made By WZM & DZC
|
||||
target: use jarvis lib code to generate pipeline
|
||||
'''
|
||||
# environment
|
||||
environment = PythonEnv()
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
# use to look up existed skill code and extract information
|
||||
agent = OpenAIAgent(config_path="./config.json")
|
||||
# use to create a new skill code
|
||||
skillCreator = LinuxSkillCreator(config_path="./config.json")
|
||||
# use to generate the invoke code of the python tool class
|
||||
invokeGenerator = LinuxInvokeGenerator(config_path="./config.json")
|
||||
# use to judge wheter the task can be executed
|
||||
taskJudger = LinuxTaskJudger(config_path="./config.json")
|
||||
# use to amend the code
|
||||
skillAmender = LinuxSkillAmend(config_path="./config.json")
|
||||
|
||||
# We assume that the response result comes from the task planning agent.
|
||||
response = '''
|
||||
Thought: In order to solve this task, first create a folder named test2, then create a file named sth2.txt in the folder directory, and finally write the text "hello world" into it. We can parse the above steps into the following actions and corresponding descriptions.
|
||||
|
||||
Actions:
|
||||
1. <action>create_folder</action> <description>create a folder which is named test2 under the default working directory</description>
|
||||
2. <action>create_file</action> <description>create a txt file which is named sth2.txt under a directory named test2 which is under the working directory.Then Write hello world in it.</description>
|
||||
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.
|
||||
|
||||
'''
|
||||
|
||||
action = agent.extract_information(response, begin_str='<action>', end_str='</action>')
|
||||
task_description = agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# loop all the subtasks
|
||||
for a,t in zip(action,task_description):
|
||||
# create python tool class code
|
||||
msg = skillCreator.format_message(task_name=a,task_description=t,working_dir=environment.working_dir)
|
||||
code = skillCreator.extract_python_code(msg)
|
||||
print(code)
|
||||
|
||||
# create the invoke code
|
||||
msg_invoke = invokeGenerator.invoke_generator(code, t,working_dir=environment.working_dir)
|
||||
print(msg_invoke)
|
||||
invoke = agent.extract_information(msg_invoke, begin_str='<invoke>', end_str='</invoke>')[0]
|
||||
code = code + '\n' + invoke
|
||||
|
||||
# execute the tool code
|
||||
state = environment.step(code)
|
||||
print(state)
|
||||
|
||||
# check whether the code runs correctly, if not, amend the code
|
||||
need_amend = False
|
||||
trial_times = 0
|
||||
critique = ""
|
||||
if state.error == None:
|
||||
judge_result = taskJudger.judge(code, t, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
if judge_result['judge'] == False:
|
||||
print("critique:{}".format(critique))
|
||||
need_amend = True
|
||||
else:
|
||||
need_amend = True
|
||||
# amend code and recheck
|
||||
current_code = code
|
||||
while (trial_times < 3) and (need_amend == True):
|
||||
trial_times += 1
|
||||
print("current amend times: {}".format(trial_times))
|
||||
amend_result = skillAmender.amend_code(current_code, t, state.error, state.result, state.pwd, state.ls, critique)
|
||||
print(amend_result)
|
||||
new_code = skillAmender.extract_python_code(amend_result)
|
||||
current_code = new_code
|
||||
state = environment.step(current_code)
|
||||
print(state)
|
||||
# recheck
|
||||
if state.error == None:
|
||||
judge_result = taskJudger.judge(current_code, t, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
if judge_result['judge'] == True:
|
||||
need_amend = False
|
||||
break
|
||||
print("critique:{}".format(critique))
|
||||
else:
|
||||
need_amend = True
|
||||
# save code or warning
|
||||
if need_amend == True:
|
||||
print("I can't Do this Task!!")
|
||||
else:
|
||||
# save to action lib
|
||||
file_path = action_lib_path + '/' + a + '.py'
|
||||
with open(file_path, "w") as file:
|
||||
lines = current_code.strip().splitlines()
|
||||
if lines:
|
||||
# remove the invoke code of the python file
|
||||
lines.pop()
|
||||
final_code = '\n'.join(lines)
|
||||
file.write(final_code)
|
||||
@@ -1,105 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.agent.linux_skill_create_agent import LinuxSkillCreateAgent
|
||||
import time
|
||||
'''
|
||||
Made By DZC & WZM
|
||||
target: Create a new folder in the specified directory and create a txt file, then write the hello word into the file.
|
||||
'''
|
||||
# environment
|
||||
environment = PythonEnv()
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
# use to look up existed skill code and extract information
|
||||
retrieve_agent = OpenAIAgent(config_path="./config.json")
|
||||
# use to create new skills
|
||||
skill_create_agent = LinuxSkillCreateAgent(config_path="./config.json")
|
||||
|
||||
# We assume that the response result comes from the task planning agent.
|
||||
response = '''
|
||||
Thought: In order to solve this task, first create a folder named test2, then create a file named sth2.txt in the folder directory, and finally write the text "hello world" into it. We can parse the above steps into the following actions and corresponding descriptions.
|
||||
|
||||
Actions:
|
||||
1. <action>create_folder</action> <description>create a folder which is named myfold under the default working directory</description>
|
||||
2. <action>create_text_file_and_write_something</action> <description>create a txt file which is named result.txt under a directory named myfold which is under the working directory.Then Write hello world in it.</description>
|
||||
3. <action>open_text_file</action> <description>open the file named result.txt in the folder named myfold through unbuntu text viewer.</description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# Loop all the actions
|
||||
for action, description in zip(actions, task_descriptions):
|
||||
# Create python tool class code
|
||||
create_msg = skill_create_agent.skill_create_format_message(task_name=action, task_description=description, working_dir=environment.working_dir)
|
||||
code = skill_create_agent.extract_python_code(create_msg)
|
||||
print(code)
|
||||
|
||||
# Create the invoke of the tool class
|
||||
invoke_msg = skill_create_agent.invoke_generate_format_message(code, description,working_dir=environment.working_dir)
|
||||
invoke = skill_create_agent.extract_information(invoke_msg, begin_str='<invoke>', end_str='</invoke>')[0]
|
||||
print("************************<invoke>**************************")
|
||||
print(invoke)
|
||||
print("************************</invoke>*************************")
|
||||
code = code + '\n' + invoke
|
||||
|
||||
# Run the tool code
|
||||
state = environment.step(code)
|
||||
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:
|
||||
judge_result = skill_create_agent.task_judge_format_message(code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
if judge == False:
|
||||
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 < 3 and need_mend == True):
|
||||
trial_times += 1
|
||||
print("current amend times: {}".format(trial_times))
|
||||
amend_msg = skill_create_agent.skill_amend_format_message(current_code, description, state.error, state.result, state.pwd, state.ls, critique)
|
||||
print(amend_msg)
|
||||
new_code = skill_create_agent.extract_python_code(amend_msg)
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = environment.step(current_code)
|
||||
print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
judge_result = skill_create_agent.task_judge_format_message(current_code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
# The task execution is completed and the loop exits
|
||||
if judge == True:
|
||||
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 in lib
|
||||
file_path = action_lib_path + "/" + action + '.py'
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
lines = current_code.strip().splitlines()
|
||||
if lines:
|
||||
# Remove the invoke code of the python file
|
||||
lines.pop()
|
||||
final_code = '\n'.join(lines)
|
||||
f.write(final_code)
|
||||
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
from jarvis.agent.openai_agent import OpenAIAgent
|
||||
from jarvis.environment.py_env import PythonEnv
|
||||
from jarvis.agent.linux_skill_create_agent import LinuxSkillCreateAgent
|
||||
import time
|
||||
'''
|
||||
Made By DZC & WZM
|
||||
target: Zip files in a specific folder and unzip them in the specified folder.
|
||||
'''
|
||||
# environment
|
||||
environment = PythonEnv()
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
# use to look up existed skill code and extract information
|
||||
retrieve_agent = OpenAIAgent(config_path="./config.json")
|
||||
# use to create new skills
|
||||
skill_create_agent = LinuxSkillCreateAgent(config_path="./config.json")
|
||||
|
||||
# We assume that the response result comes from the task planning agent.
|
||||
response = '''
|
||||
Thought: In order to solve this task, first compress files in the folder test2, then decompress them in folder test.
|
||||
|
||||
Actions:
|
||||
1. <action>zip_files</action> <description>Zip all the files in the folder called test2 and name the zip file as test2.zip. </description>
|
||||
2. <action>unzip_files</action> <description>Unzip test2.zip in the folder called test2 to the folder called test. </description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# Loop all the actions
|
||||
for action, description in zip(actions, task_descriptions):
|
||||
# Create python tool class code
|
||||
create_msg = skill_create_agent.skill_create_format_message(task_name=action, task_description=description, working_dir=environment.working_dir)
|
||||
code = skill_create_agent.extract_python_code(create_msg)
|
||||
print(code)
|
||||
|
||||
# Create the invoke of the tool class
|
||||
invoke_msg = skill_create_agent.invoke_generate_format_message(code, description,working_dir=environment.working_dir)
|
||||
invoke = skill_create_agent.extract_information(invoke_msg, begin_str='<invoke>', end_str='</invoke>')[0]
|
||||
print("************************<invoke>**************************")
|
||||
print(invoke)
|
||||
print("************************</invoke>*************************")
|
||||
code = code + '\n' + invoke
|
||||
|
||||
# Run the tool code
|
||||
state = environment.step(code)
|
||||
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:
|
||||
judge_result = skill_create_agent.task_judge_format_message(code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
if judge == False:
|
||||
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 < 3 and need_mend == True):
|
||||
trial_times += 1
|
||||
print("current amend times: {}".format(trial_times))
|
||||
amend_msg = skill_create_agent.skill_amend_format_message(current_code, description, state.error, state.result, state.pwd, state.ls, critique)
|
||||
print(amend_msg)
|
||||
new_code = skill_create_agent.extract_python_code(amend_msg)
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = environment.step(current_code)
|
||||
print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
judge_result = skill_create_agent.task_judge_format_message(current_code, description, state.result, state.pwd, state.ls)
|
||||
critique = judge_result['reasoning']
|
||||
judge = judge_result['judge']
|
||||
# The task execution is completed and the loop exits
|
||||
if judge == True:
|
||||
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 in lib
|
||||
file_path = action_lib_path + "/" + action + '.py'
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
lines = current_code.strip().splitlines()
|
||||
if lines:
|
||||
# Remove the invoke code of the python file
|
||||
lines.pop()
|
||||
final_code = '\n'.join(lines)
|
||||
f.write(final_code)
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
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. <action>zip_files</action> <description>Zip all the files in the folder called document and name the zip file as agent. </description>
|
||||
2. <action>unzip_files</action> <description>Unzip agent.zip to the folder called myfold. </description>
|
||||
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='<action>', end_str='</action>')
|
||||
task_descriptions = retrieve_agent.extract_information(response, begin_str='<description>', end_str='</description>')
|
||||
|
||||
# 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)
|
||||
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)
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
from jarvis.agent.jarvis_agent import JarvisAgent
|
||||
|
||||
'''
|
||||
Made By DZC
|
||||
'''
|
||||
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
jarvis_agent = JarvisAgent(config_path="./config.json", action_lib_dir=action_lib_path)
|
||||
planning_agent = jarvis_agent.planner
|
||||
retrieve_agent = jarvis_agent.retriever
|
||||
execute_agent = jarvis_agent.executor
|
||||
|
||||
# task = '''
|
||||
# Move the text files containing the word 'agent' from the folder named 'document' to the path '/home/heroding/桌面/Jarvis/working_dir/agent'.
|
||||
# '''
|
||||
|
||||
task = '''
|
||||
请给我华东师范大学数据学院高明老师的信息。
|
||||
'''
|
||||
|
||||
# relevant action
|
||||
retrieve_action_name = retrieve_agent.retrieve_action_name(task)
|
||||
retrieve_action_description_pair = retrieve_agent.retrieve_action_description_pair(retrieve_action_name)
|
||||
# decompose task
|
||||
planning_agent.decompose_task(task, retrieve_action_description_pair)
|
||||
|
||||
# retrieve existing action
|
||||
for action_name, action_node in planning_agent.action_node.items():
|
||||
type = action_node.type
|
||||
if type == 'General':
|
||||
action_description = action_node.description
|
||||
retrieve_action = retrieve_agent.retrieve_action_name(action_description, 3)
|
||||
retrieve_action_code_pair = retrieve_agent.retrieve_action_code_pair(retrieve_action)
|
||||
planning_agent.update_action(action_name, relevant_action=retrieve_action_code_pair)
|
||||
|
||||
# iter each subtask
|
||||
while planning_agent.execute_list:
|
||||
action = planning_agent.execute_list[0]
|
||||
action_node = planning_agent.action_node[action]
|
||||
description = action_node.description
|
||||
code = action_node.code
|
||||
relevant_code = action_node.relevant_action
|
||||
type = action_node.type
|
||||
pre_tasks_info = planning_agent.get_pre_tasks_info(action)
|
||||
if type == 'QA':
|
||||
answer = execute_agent.question_and_answer_action(pre_tasks_info, task)
|
||||
print(answer)
|
||||
break
|
||||
# Create python tool class code and invoke
|
||||
if type == 'API':
|
||||
api_path = execute_agent.extract_API_Path(description)
|
||||
code = execute_agent.api_action(description, api_path, pre_tasks_info)
|
||||
invoke = ''
|
||||
else:
|
||||
code, invoke = execute_agent.generate_action(action, description, pre_tasks_info, relevant_code)
|
||||
# Execute python tool class code
|
||||
state = execute_agent.execute_action(code, invoke, type)
|
||||
current_code = ''
|
||||
# Check whether the code runs correctly, if not, amend the code
|
||||
if type == 'General':
|
||||
need_mend = False
|
||||
trial_times = 0
|
||||
critique = ''
|
||||
score = 0
|
||||
# If no error is reported, check whether the task is completed
|
||||
if state.error == None:
|
||||
critique, judge, score = execute_agent.judge_action(code, description, state)
|
||||
if not judge:
|
||||
print("critique: {}".format(critique))
|
||||
need_mend = True
|
||||
else:
|
||||
# Determine whether it is caused by an error outside the code
|
||||
reasoning, error_type = execute_agent.analysis_action(code, description, state)
|
||||
if error_type == 'replan':
|
||||
relevant_action_name = retrieve_agent.retrieve_action_name(reasoning)
|
||||
relevant_action_description_pair = retrieve_agent.retrieve_action_description_pair(relevant_action_name)
|
||||
planning_agent.replan_task(reasoning, action)
|
||||
continue
|
||||
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, invoke = execute_agent.amend_action(current_code, description, state, critique, pre_tasks_info)
|
||||
critique = ''
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = execute_agent.execute_action(current_code, invoke, type)
|
||||
# print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
critique, judge, score = execute_agent.judge_action(current_code, description, state)
|
||||
# The task execution is completed and the loop exits
|
||||
if judge:
|
||||
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!!")
|
||||
break
|
||||
else: # The task is completed, if code is save the code, args_description, action_description in lib
|
||||
if score >= 7:
|
||||
execute_agent.store_action(action, current_code)
|
||||
print("Current task execution completed!!!")
|
||||
planning_agent.update_action(action, current_code, state.result, status=True, type=type)
|
||||
planning_agent.execute_list.remove(action)
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
from jarvis.agent.jarvis_agent import JarvisAgent
|
||||
|
||||
'''
|
||||
Made By DZC
|
||||
'''
|
||||
|
||||
# path of action lib
|
||||
action_lib_path = "../jarvis/action_lib"
|
||||
jarvis_agent = JarvisAgent(config_path="./config.json", action_lib_dir=action_lib_path)
|
||||
planning_agent = jarvis_agent.planner
|
||||
retrieve_agent = jarvis_agent.retriever
|
||||
execute_agent = jarvis_agent.executor
|
||||
|
||||
task = '''
|
||||
Move the text files containing the word 'agent' from the folder named 'document' to the path '/home/heroding/桌面/Jarvis/working_dir/agent'.
|
||||
'''
|
||||
|
||||
# task = '''
|
||||
# Download a dog picture from the Internet to the working directory.
|
||||
# '''
|
||||
|
||||
# relevant action
|
||||
retrieve_action_name = retrieve_agent.retrieve_action_name(task)
|
||||
retrieve_action_description_pair = retrieve_agent.retrieve_action_description_pair(retrieve_action_name)
|
||||
# decompose task
|
||||
planning_agent.decompose_task(task, retrieve_action_description_pair)
|
||||
|
||||
# retrieve existing tools
|
||||
for action_name, action_node in planning_agent.action_node.items():
|
||||
action_description = action_node.description
|
||||
retrieve_action = retrieve_agent.retrieve_action_name(action_description, 3)
|
||||
retrieve_action_code_pair = retrieve_agent.retrieve_action_code_pair(retrieve_action)
|
||||
code = retrieve_agent.action_code_filter(retrieve_action_code_pair, action_description)
|
||||
planning_agent.update_action(action_name, code, relevant_action=retrieve_action_code_pair)
|
||||
|
||||
# iter each subtask
|
||||
while planning_agent.execute_list:
|
||||
action = planning_agent.execute_list[0]
|
||||
action_node = planning_agent.action_node[action]
|
||||
description = action_node.description
|
||||
code = action_node.code
|
||||
pre_tasks_info = planning_agent.get_pre_tasks_info(action)
|
||||
if not code:
|
||||
# Create python tool class code
|
||||
code = execute_agent.generate_action(action, description)
|
||||
# Execute python tool class code
|
||||
state = execute_agent.execute_action(code, description, pre_tasks_info)
|
||||
# Check whether the code runs correctly, if not, amend the code
|
||||
need_mend = False
|
||||
trial_times = 0
|
||||
critique = ''
|
||||
score = 0
|
||||
# If no error is reported, check whether the task is completed
|
||||
if state.error == None:
|
||||
critique, judge, score = execute_agent.judge_action(code, description, state)
|
||||
if not judge:
|
||||
print("critique: {}".format(critique))
|
||||
need_mend = True
|
||||
else:
|
||||
# Determine whether it is caused by an error outside the code
|
||||
reasoning, type = execute_agent.analysis_action(code, description, state)
|
||||
if type == 'replan':
|
||||
relevant_action_name = retrieve_agent.retrieve_action_name(reasoning)
|
||||
relevant_action_description_pair = retrieve_agent.retrieve_action_description_pair(relevant_action_name)
|
||||
planning_agent.replan_task(reasoning, action )
|
||||
continue
|
||||
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)
|
||||
critique = ''
|
||||
current_code = new_code
|
||||
# Run the current code and check for errors
|
||||
state = execute_agent.execute_action(current_code, description, pre_tasks_info)
|
||||
# print(state)
|
||||
# Recheck
|
||||
if state.error == None:
|
||||
critique, judge, score = execute_agent.judge_action(current_code, description, state)
|
||||
# The task execution is completed and the loop exits
|
||||
if judge:
|
||||
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!!")
|
||||
break
|
||||
else: # The task is completed, if code is save the code, args_description, action_description in lib
|
||||
if score >= 8 and not action_node.code:
|
||||
execute_agent.store_action(action, current_code)
|
||||
print("Current task execution completed!!!")
|
||||
planning_agent.update_action(action, current_code, state.result, status=True)
|
||||
planning_agent.execute_list.remove(action)
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"model_name": "gpt-4-1106-preview",
|
||||
"OPENAI_API_KEY": "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",
|
||||
"OPENAI_ORGANIZATION": "org-fSyygvftM73W0pK4VjoK395W",
|
||||
"config": {
|
||||
"API_KEY": "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",
|
||||
"MAX_CHAT_HISTORY": "10",
|
||||
"User_Names": "[\"User\"]",
|
||||
"TOP_K": "3"
|
||||
},
|
||||
"LLM_type": "OpenAI",
|
||||
"LLM": {
|
||||
"temperature": 0.0,
|
||||
"model": "gpt-4-1106-preview",
|
||||
"log_path": "logs/god"
|
||||
},
|
||||
"agents": {
|
||||
"Yang bufan": {
|
||||
"style": "indifferent and idle",
|
||||
"roles": {
|
||||
"Response_state": "Yang bufan"
|
||||
}
|
||||
},
|
||||
"User": {
|
||||
"style": "soso",
|
||||
"roles": {
|
||||
"Response_state": "User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,483 +0,0 @@
|
||||
data_id = {
|
||||
"test" : {
|
||||
"level1" : [
|
||||
'6af95c8f-8cbf-4c12-b02c-f9a23cc1ecb9',
|
||||
'198ffd8f-6041-458d-bacc-fe49872cfa43',
|
||||
'7b10295b-5287-41d7-897c-663fe194c04d',
|
||||
'cf0682db-1e31-4a36-913f-aedd501e44d1',
|
||||
'07ed8ebc-535a-4c2f-9677-3e434a08f7fd',
|
||||
'd89733a3-7d86-4ed8-b5a3-bf4831b06e3c',
|
||||
'cfd773c8-371f-425c-b081-f254f96c0530',
|
||||
'fcf5b93d-27fd-4637-ac5d-fad4e445ca94',
|
||||
'fece4d7a-4093-47b8-b58c-68ec591ec4c8',
|
||||
'fa7bc619-bf17-4ef7-be80-c0e32144140f',
|
||||
'8e41f740-f193-4540-a7b1-62e0f4b804a0',
|
||||
'c7003252-fc58-44bf-92f5-ec3991a49d00',
|
||||
'6e343c42-7f09-4df5-aab9-22c0293c2d30',
|
||||
'7556cbdb-c736-4efa-b3ef-2ebc2c8f4da3',
|
||||
'5b5e7996-4de6-46c4-8be2-0943417886e5',
|
||||
'6f7d28c6-6a8c-44b2-8ea9-0988c1096a2a',
|
||||
'5b89b147-cdab-40e1-be5b-819bc076c270',
|
||||
'07d803c0-7975-4da2-a62b-c8abafcdad9d',
|
||||
'5e76cfc3-f33d-4416-b8ae-3ef292830207',
|
||||
'2102c078-d0f8-4a66-91d7-caca752bf55b',
|
||||
'269f42c1-d767-4426-baf3-0d91c4423177',
|
||||
'3157eb2e-2b7c-48ae-8676-437c64d813d5',
|
||||
'c1e3311d-5112-4690-bcdc-7da181657835',
|
||||
'55aeb0ce-9170-4959-befb-59f6116887a4',
|
||||
'2baa3989-5618-4f3b-9449-8b18e3e59281',
|
||||
'198f2b40-958b-497b-a685-15fdc0587481',
|
||||
'543eadae-e80a-44ba-b98d-6e8c4040dae8',
|
||||
'97f452b6-f144-4224-bfe4-b6a8e0bbce6a',
|
||||
'e196e50c-09fb-4a3a-81a9-c81ef41b0708',
|
||||
'4d8fc0e1-69c0-4fa9-9db1-05935ec5633e',
|
||||
'df30cd5b-cce6-475d-907d-69927f32d006',
|
||||
'60fbc5a3-2805-4ad4-8eef-b58843b5053b',
|
||||
'9845712b-bb09-45f8-a0a4-df29b7093877',
|
||||
'8770c47d-56ad-42cf-b0a6-7e48d0d19019',
|
||||
'5bbf523f-b902-4d7d-8e8d-212d00018733',
|
||||
'70510d87-5004-4e4a-b078-21abf699dc12',
|
||||
'7c215d46-91c7-424e-9f22-37d43ab73ea6',
|
||||
'67592f4a-f0ce-4d1f-be02-fde74748926f',
|
||||
'86ca62df-b518-48e7-9115-1b0b800e5453',
|
||||
'7805912b-c8da-4134-9b54-b590f884352a',
|
||||
'fcd80879-4f1d-49d8-b6d6-2993607432c2',
|
||||
'68d05bcc-e6cd-43f1-8e9e-e73d507cd02f',
|
||||
'91d929df-7666-4eed-894c-1bafe5b2e883',
|
||||
'171dd6d2-d1d4-439b-8d4e-7507018a816b',
|
||||
'e013fc18-abfc-4101-9acc-6273112517f6',
|
||||
'680d7d77-c0c7-49c8-88fd-f8ec623645e9',
|
||||
'220a2b08-ffdc-4665-af4e-025670f5408b',
|
||||
'3c5f0280-b1a3-43cf-817e-c3fa0016b1e2',
|
||||
'355b827f-fff0-4e0c-9ff0-65dea0609838',
|
||||
'a15f8d90-115d-4376-98b3-c866be21ef8f',
|
||||
'adbc62c6-dc67-4bd8-a245-e1ed36b0d733',
|
||||
'66bd1b1c-443b-4b4e-a108-0fa06527dd62',
|
||||
'302a5b22-7599-4f9d-966b-445db74a0533',
|
||||
'beeee382-3b29-4be2-b6c7-e54e3543c93f',
|
||||
'7245af7c-404e-4d60-9ef4-94ed301e5315',
|
||||
'8488761b-6d5a-4be0-86d6-5cf8d6c13efe',
|
||||
'1dd3f5f0-a467-4336-b1e1-78ea886a2244',
|
||||
'cadc593c-ebde-43ec-afa6-a8a4e95c0e38',
|
||||
'cbdb17dc-62d9-4463-b648-2eaacfeba4e5',
|
||||
'b78952b8-af19-4ffa-9275-cfa41a255b8a',
|
||||
'07c3029f-7095-455d-a9e9-cd5e34001b38',
|
||||
'01af5e27-e389-4c69-a133-412e16532b67',
|
||||
'68ccf11a-bcd3-41e5-a5ee-3e29253449e9',
|
||||
'f1ba834a-3bcb-4e55-836c-06cc1e2ccb9f',
|
||||
'dd024dd9-8da6-4d4e-aee1-ed0d999035a9',
|
||||
'314b3c26-3e8d-4f8c-a9aa-c77275072e0b',
|
||||
'27ee81e0-9f94-4b2d-8ab5-3c7033fcefca',
|
||||
'8f515e77-1b54-4183-bd5d-3c5f71674931',
|
||||
'bdb2f8ff-83a3-4288-a019-68c7968198f6',
|
||||
'22f61d58-b420-4afb-a641-39ef09c65603',
|
||||
'b01a3c5f-56ce-4fee-bc15-afd2047bc976',
|
||||
'f2ea141f-073c-4a86-af4c-fd1f2e7903fc',
|
||||
'2131de62-c9b7-4f08-a28f-ccbd9e4809f3',
|
||||
'f08e2efd-1885-4437-8c88-90a20558ad1d',
|
||||
'32f386b9-73ee-4455-b412-ddad508aa979',
|
||||
'd62cbee6-47c7-4918-825d-3b73b1af7e85',
|
||||
'91f2bf12-5280-4efc-b9a7-26e67ca850b4',
|
||||
'c9adfc66-ee9e-437a-aa54-e76ab00d9a4a',
|
||||
'dfa03d6c-402b-43fc-9222-5738f8bdfd0c',
|
||||
'7cf5f072-4c37-4ccb-8c4e-a8f66fcdd9e1',
|
||||
'52e8ce1c-09bd-4537-8e2d-67d1648779b9',
|
||||
'f9f97b63-52e5-482f-beb8-c0f3cfac163e',
|
||||
'52fcc23e-4e68-43da-9410-f8f33632006f',
|
||||
'4dccff35-158b-4647-8ad0-b7432112077d',
|
||||
'0a5a5fd6-97b7-4cce-ad9f-bdaaee042bec',
|
||||
'ebfd308e-59c1-4389-8812-7ea4cda7f4bc',
|
||||
'2648baca-4e35-4353-8772-4da848c8440e',
|
||||
'e8719a2f-6bbd-40b6-95b5-7706f7a6445a',
|
||||
'4c386922-5c65-4f33-86d5-107a97ad6654',
|
||||
'b74aa3b0-16a7-4a79-a8df-0cbdcf1d2eb8',
|
||||
'b9c62d30-86f8-4b36-80b6-afb34852cea6',
|
||||
'70e0a9c6-24bf-48ed-afa1-f0d0eaaa0209',
|
||||
'de21a804-9b9e-40b6-aede-392e3360b147'
|
||||
],
|
||||
"level2" : [
|
||||
'c80ed443-b494-4e86-bec8-10ecb41c2326',
|
||||
'6583799b-573a-4e95-8b28-4f0397bd45c2',
|
||||
'12a682d7-8e8e-4d4c-8102-a97628027441',
|
||||
'4044eab7-1282-42bd-a559-3bf3a4d5858e',
|
||||
'6ace0798-0d0f-4122-8705-78acebf23191',
|
||||
'4033181f-1988-476b-bc33-6da0f96d7bd0',
|
||||
'7707f3dd-1aa6-42f5-847a-b66f3eaf2ee4',
|
||||
'cd886ddd-2d12-4347-9c7a-64774f66a3d3',
|
||||
'ac8e6d96-57a8-4936-a910-2bb04794b041',
|
||||
'862862cb-519c-492a-8bee-309f3a8a5191',
|
||||
'c7d40b93-4ee9-4643-8a25-1bb1d5c00f06',
|
||||
'ca0a4c14-4b97-43e7-8923-539d61050ae3',
|
||||
'15c0b8fe-d3be-45df-a759-13a488d4baaa',
|
||||
'adfc0afb-3ef2-4e79-b66b-c49823b6b913',
|
||||
'68ff53a8-e1a1-42b0-9180-3c0a37187387',
|
||||
'48f56def-d539-4780-a3f5-591a925a88bf',
|
||||
'e20d0329-72bc-4634-ab37-47a217c2cfb6',
|
||||
'78cfc686-0e24-4e8e-acb4-291198301286',
|
||||
'3f9f12e1-c848-4925-afea-eb484e17e986',
|
||||
'640e86a8-a261-4f6a-b507-0f510484eeff',
|
||||
'35320d83-246a-4367-8ed8-c04a93c68daa',
|
||||
'880c9d7d-aeb1-4fb0-a389-b9a88c451b50',
|
||||
'8f697523-6988-4c4f-8d72-760a45681f68',
|
||||
'c265a892-f429-454a-bfc1-d2164b520a90',
|
||||
'a0dcc222-691e-4b03-ac75-c4493991ab80',
|
||||
'02d0c7de-3cb6-43db-8b42-bb5be0923e28',
|
||||
'f5d0b1c6-5e15-4c55-b60c-9fc855dda5cf',
|
||||
'c134398d-e1eb-4dab-97a1-6d9f715e53d0',
|
||||
'07f6a90e-ee1d-4d2b-ae1d-3556d66a9e11',
|
||||
'a4a37f5c-b160-43ed-8484-fe74572cb2c1',
|
||||
'411e5d0e-52db-492f-97a3-bd93658c0357',
|
||||
'9ace56cc-2454-4de2-8e39-d8fec7be6f44',
|
||||
'f94d6a97-9825-4308-8c69-fe6be4f6dff5',
|
||||
'06d24738-d12e-484a-999a-b6119f4167f4',
|
||||
'965a4ea3-bb77-4ddd-9ee6-3160a6f8b8ef',
|
||||
'4e4b3e43-7240-47b2-8594-8dacd70ee12e',
|
||||
'c3c656c0-b288-476d-85d6-6d7a95ad19ef',
|
||||
'd6f433d5-4203-47d4-990a-28dbf99e6afd',
|
||||
'cca708f8-277f-4d9c-920c-26e8065b82ad',
|
||||
'99b5ea36-0310-49c4-85d8-9ae83a96029a',
|
||||
'35a5c13a-6012-461f-abfc-cde9e5a0a0dd',
|
||||
'2bb16c35-403a-4d4c-859e-a88ccd55f876',
|
||||
'56376d48-f456-4c24-a917-834be04c7608',
|
||||
'44eb0217-9ba3-47c8-9e1c-6325d26e6f90',
|
||||
'f4b55162-e06c-4ac0-be0e-78546bc87204',
|
||||
'03c577c9-4227-48a9-9b75-f8f598de14c1',
|
||||
'fe8f4748-5d00-4a27-9070-090a0cfdeac4',
|
||||
'e8b226bf-2ccd-4748-973d-08dad7aa8253',
|
||||
'208b8625-c49d-4cf1-95b6-4ced3bff82fb',
|
||||
'074f5cd6-d287-49d6-bc0a-f7d40fbf2f08',
|
||||
'2f14e114-55de-464f-af9b-82443c6ad5ba',
|
||||
'44cb62e5-b0c5-4f12-b96f-21e80ed2062d',
|
||||
'bb505145-7a10-4d23-8af9-39d2b833be3f',
|
||||
'e463d411-6260-4d93-b5b4-6d9b1f619d5c',
|
||||
'1c4c108b-fd1a-4251-8a23-20efeaefcae9',
|
||||
'4810c253-7b06-447d-8bf6-64558ac5f00f',
|
||||
'2372640f-a119-4960-b624-5ffbe81d6f3f',
|
||||
'8aa22ddc-fe80-464c-9c96-8d534fa5c7d5',
|
||||
'ffad7d0a-e20d-461f-b5be-07804917235d',
|
||||
'04893fc3-34fc-4117-8457-a717ad01a6a9',
|
||||
'25575ca4-9632-428a-8789-5a6910475451',
|
||||
'0a8063da-eae2-4f84-8603-e71e8714ec23',
|
||||
'b923ed47-f382-4c56-90fa-fbafb0ea1cca',
|
||||
'24db55fc-5bd5-402e-8b85-f01d4d50d8c2',
|
||||
'21aba0e0-03d6-4541-b467-a0384ca5298a',
|
||||
'5093d134-9bc8-41c0-8dd2-094a59ddc002',
|
||||
'be353748-74eb-4904-8f17-f180ce087f1a',
|
||||
'021f63bc-b8cf-484d-a373-ca468fa8ab37',
|
||||
'405c2f42-5d01-46d1-97eb-2e96b7cee542',
|
||||
'0a3d99c6-d130-49a8-a8bc-6cd5999cc3b4',
|
||||
'2e6c39b3-5988-4569-9401-3dde97425be6',
|
||||
'00f49e33-3f00-4e8d-9ea5-a85bc7f3462f',
|
||||
'55caccf7-8c3b-4d40-842a-825789f55dd7',
|
||||
'4d317450-948c-4445-b15a-a170813a05e5',
|
||||
'427348d3-797e-4bfc-88ef-d5780f982d58',
|
||||
'6dc2ac8a-dfb8-48bc-a9f0-73d5435106b1',
|
||||
'5c418120-2a9f-4bae-8aee-d37ac26f8465',
|
||||
'd9060545-9e29-4a0b-8a1d-57211c462637',
|
||||
'2698c8fa-868a-4ce6-9290-6cb397d1e071',
|
||||
'e8df5ee8-e804-4ab4-a5b5-f737ffb7c37a',
|
||||
'23bcfab0-f47b-4dcb-8599-459c329ac153',
|
||||
'82b89810-1217-4ad8-aa9f-26e7c74ba6e5',
|
||||
'b1a37359-2e2e-4521-bb3d-cecdf3ec5419',
|
||||
'15b85766-24c0-4ee9-98f7-3ff237c89dc8',
|
||||
'e87720bf-7dbe-49c2-b91c-bfc23b14d157',
|
||||
'456cd699-e6f0-4729-a18e-077ffc7337c0',
|
||||
'dbb02ff7-f947-491b-9ce2-41e3df16dbb8',
|
||||
'e58ea654-994a-44fd-aaff-bf033c715c56',
|
||||
'e47bd787-8024-425e-985c-7809bd992fa5',
|
||||
'fb59de38-e688-43f9-a959-a687e6cd0ebc',
|
||||
'e26e4f19-0c1c-430d-a881-66e52b9043f5',
|
||||
'aac4df0d-407a-45f2-add5-d9b31ebe1ddc',
|
||||
'698799a7-33df-4892-9ecd-76600ad91b96',
|
||||
'c16acedc-7a4e-4df5-a007-200faa5c67e5',
|
||||
'1b738608-485d-4456-98d3-31ad60f77284',
|
||||
'9961d869-f827-4540-bcf0-1e09c2cba3b0',
|
||||
'ff43a8cd-3850-42a4-bdb1-1eea53a8fcb7',
|
||||
'd8f6be13-17f3-450a-b68f-89d7de943cf1',
|
||||
'ed5e2ddd-6a3b-43a2-b6dc-a6c8862e06d7',
|
||||
'6178671d-6f80-4e0d-9672-54afaf7b527b',
|
||||
'b3654e47-4307-442c-a09c-945b33b913c6',
|
||||
'd543b75f-96e6-4b04-bf2c-60acd0d48246',
|
||||
'70e18502-7ff4-4aa7-85ed-f5587cc582c9',
|
||||
'b4d2d683-7870-4940-8eaf-03cd1355873a',
|
||||
'c7adc367-cf65-43f5-acc6-b3cc8b61c51e',
|
||||
'900bb2d0-c2ae-43a6-b25b-62f96c3770e3',
|
||||
'afd1efe6-03dd-478c-9eb1-e562355ee94e',
|
||||
'f30a836f-420f-4738-80af-d2491e072dab',
|
||||
'f1746e25-adf7-4565-8365-56f3d3536c92',
|
||||
'cd8166fc-8a04-43b8-956a-785c6513671a',
|
||||
'3cc53dbf-1ab9-4d21-a56a-fc0151c10f89',
|
||||
'b548db79-fabd-4bbc-81f3-43097159a3a5',
|
||||
'9b98305b-af16-489e-adbc-41b5c5a0ec2d',
|
||||
'd50b8ecb-a8aa-4696-ad84-403ef15e2c8b',
|
||||
'cebff819-f4d7-4b4a-8c42-31bed1a062c5',
|
||||
'5f2b2e54-5047-4394-81be-198230c3b508',
|
||||
'd219675a-0552-4fe0-8c5a-ae7365501f00',
|
||||
'9aefe06d-0921-4941-96b4-154de9ee4f05',
|
||||
'bb686773-a454-44d5-b193-cfccfdb90dee',
|
||||
'633d1eae-8748-43e3-889a-0830c1c870c4',
|
||||
'2b2e4e18-a825-4285-aeb1-8d93d2521627',
|
||||
'59b3cfb0-a06a-4ac5-b54e-81c9db8b0957',
|
||||
'f2fa52f6-fc8a-498c-98d3-17f66c848d1b',
|
||||
'07c930f4-40a4-4be7-9165-ce8ad24bdbf9',
|
||||
'063800f6-8832-4856-972b-17b877612533',
|
||||
'462413b8-642c-4a4d-be27-1a9406100e31',
|
||||
'c771f182-c66e-4c81-b1b8-80f924e7ca9a',
|
||||
'5cb40f44-29b4-49de-a924-03e68191a994',
|
||||
'763a8789-8aa9-4254-aa12-779bec9c7aef',
|
||||
'e4b6ca51-c70d-45f7-90dd-cbd1790df1cb',
|
||||
'fb488ce0-520c-4f3b-b953-b52b4130fb06',
|
||||
'b201ae2a-fdab-4e13-a687-174d557d608a',
|
||||
'fb349e07-d6c6-4d98-9a0e-1a3567f7d9bd',
|
||||
'4866d2d0-e86f-4541-9801-4faa9b910a35',
|
||||
'6de7d951-8dfe-449f-a808-76e2359b75b8',
|
||||
'b74b4ce7-4f03-42b5-b60e-62da7ffa282e',
|
||||
'd366cc70-86f1-4dca-bf12-440479c825fe',
|
||||
'3013b87b-dc19-466a-b803-6b7239b9fd9c',
|
||||
'ed30357a-9648-49fd-8d34-a78e71d0984c',
|
||||
'a582f258-4e42-47db-8669-4280537fe223',
|
||||
'f7f36b51-3ad4-4149-af93-1b4355b438b0',
|
||||
'd31b3ec0-bf91-42dd-82fb-43655964505d',
|
||||
'c47d5037-f591-4958-a27c-c9c89dc30df0',
|
||||
'8c638aa7-81d9-4d06-9ae4-0c0a5540ea5b',
|
||||
'021a5339-744f-42b7-bd9b-9368b3efda7a',
|
||||
'eb0292b5-a09a-451b-8cd1-a8671095a0d0',
|
||||
'67f89b20-03eb-4f2d-8cbc-a94e5cc05343',
|
||||
'aea1ea38-dfd0-41ab-ad79-badc3c69c784',
|
||||
'0870ef1f-c712-4e67-8940-8581cc9455dd',
|
||||
'fa93f13c-5967-41ad-9ccb-6a351be9f625',
|
||||
'9e72b135-afa1-4e39-9e21-ea34d0726e20',
|
||||
'b4395888-4e6d-4d02-b7ee-11dbccdb802d',
|
||||
'4b52450e-0c0d-434e-8358-85e80cb2514c',
|
||||
'9ca9bc20-1a0b-4076-9937-7724e3491cf8',
|
||||
'd8434132-f196-4048-82c3-c06facff53c0',
|
||||
'f6d29ef1-0e4d-41cb-ac25-e60023b3bd96',
|
||||
'4cf4a5c1-7c9c-4cce-94cb-57b8be196244',
|
||||
'e395eb42-8b78-4995-9f8b-25e3a56ab359',
|
||||
'd0e1cd7d-0af2-4ca0-8e9d-7a3fa0687e7f'
|
||||
],
|
||||
"level3" : [
|
||||
'e14448e9-5243-4b07-86e1-22e657f96bcf',
|
||||
'11016eca-0f56-443b-985e-a927bd4fc1b0',
|
||||
'5f862c5d-1d51-4efa-bbd0-eb313579b5f8',
|
||||
'17a9628e-ccef-433c-9109-acaf024d5a55',
|
||||
'460ef201-c5f4-41f4-9acd-e4215384e678',
|
||||
'7dc97fbf-c452-4b5d-9d19-db275daccd39',
|
||||
'c4456885-2f03-436f-8fe9-0b4ca6822cdb',
|
||||
'7674ee67-d671-462f-9e51-129944749a0a',
|
||||
'ec9cb96f-0499-449e-b8f4-3eff8663ddd4',
|
||||
'2e958b48-d4bf-4dc5-b051-442a2ef70630',
|
||||
'83692c1b-eab1-49f1-9ef4-151708310689',
|
||||
'c68c0db6-1929-4194-8602-56dce5ddbd29',
|
||||
'335024e1-aa6a-4a48-bba5-fad4ebd8868c',
|
||||
'2db1003c-96b9-4e26-9223-5a2d491d26ac',
|
||||
'fa06024a-119e-47e9-bf90-f543a3b330b6',
|
||||
'd6059b3e-e1da-43b4-ac26-ecad2984909b',
|
||||
'943255a6-8c56-4cf8-9faf-c74743960097',
|
||||
'd82180c3-39f0-4008-a883-24d5226fc49b',
|
||||
'028f0446-9529-4be4-af42-4a25d4ccda5a',
|
||||
'80e1a640-960b-4b65-9bbf-fd94c2ec55fa',
|
||||
'b7767ed5-20c7-4243-86b1-e8bd9a3d2a64',
|
||||
'de41fdda-d03c-4655-a3f2-33d9a22e789a',
|
||||
'1276e220-1482-424f-9c05-ae459f9de38e',
|
||||
'7e7d97af-7472-4150-815d-8a6400aa0dc8',
|
||||
'ed7354ce-7c07-47b0-bc2a-d9f5bbc50bc7',
|
||||
'ca94a79c-30ee-4c9c-9be6-57b4bb4284d3',
|
||||
'8b553092-3d44-4ab3-8d1e-932aabc1e143',
|
||||
'3415b0bd-f53f-4397-b657-b3204d43235e',
|
||||
'e5de797e-4429-425e-80b4-2fed4620c52b',
|
||||
'634fca59-03b2-4cdf-9ce4-0205df22f256',
|
||||
'98efafc6-c376-4b53-be91-a130e1d90e02',
|
||||
'41220f73-ec72-47c1-ba53-a6e50e4896b9',
|
||||
'967ad395-7b16-43a2-83e7-41df7cd6401a',
|
||||
'8a0e4077-b38a-4ccb-bfc4-99786b1f577c',
|
||||
'9d0f88cd-f02d-4864-bf15-93ec95fef4f8',
|
||||
'8f2e558f-c8a3-4e00-81fd-d52d62917977',
|
||||
'985ec22e-546b-49fc-ab3c-af490fbefdf3',
|
||||
'16cf70d8-9263-4eb0-a8a9-5eb91a23b462',
|
||||
'0e4aa403-de9a-4f69-be4a-b141184db4a9',
|
||||
'e51753c7-3ef3-4404-a352-11a18e5760c9',
|
||||
'7a770333-8c1b-4008-b630-9d3cb4f0c171',
|
||||
'84dff22d-5520-49f7-9c0a-d4b7a49de8cf',
|
||||
'97426980-08b7-4627-a076-be6f4b3a95c8',
|
||||
'69b557be-22a3-48fd-971c-0381d867ec0c',
|
||||
'f8ee2934-7981-4cd4-8abc-e91239c50c97',
|
||||
'c70c16aa-6c86-4ad0-b2f6-82fc748f49a2',
|
||||
'088d34d3-8b99-4928-ba26-9a0c6098a616',
|
||||
'0c393561-dd13-4b7c-ac49-20ac469aa276'
|
||||
]
|
||||
},
|
||||
"val" : {
|
||||
"level1" : [
|
||||
'e1fc63a2-da7a-432f-be78-7c4a95598703',
|
||||
'8e867cd7-cff9-4e6c-867a-ff5ddc2550be',
|
||||
'ec09fa32-d03f-4bf8-84b0-1f16922c3ae4',
|
||||
'5d0080cb-90d7-4712-bc33-848150e917d3',
|
||||
'a1e91b78-d3d8-4675-bb8d-62741b4b68a6',
|
||||
'46719c30-f4c3-4cad-be07-d5cb21eee6bb',
|
||||
'4b6bb5f7-f634-410e-815d-e673ab7f8632',
|
||||
'cffe0e32-c9a6-4c52-9877-78ceb4aaa9fb',
|
||||
'2d83110e-a098-4ebb-9987-066c06fa42d0',
|
||||
'5cfb274c-0207-4aa7-9575-6ac0bd95d9b2',
|
||||
'27d5d136-8563-469e-92bf-fd103c28b57c',
|
||||
'dc28cf18-6431-458b-83ef-64b3ce566c10',
|
||||
'b816bfce-3d80-4913-a07d-69b752ce6377',
|
||||
'72e110e7-464c-453c-a309-90a95aed6538',
|
||||
'42576abe-0deb-4869-8c63-225c2d75a95a',
|
||||
'b415aba4-4b68-4fc6-9b89-2c812e55a3e1',
|
||||
'cca530fc-4052-43b2-b130-b30968d8aa44',
|
||||
'935e2cff-ae78-4218-b3f5-115589b19dae',
|
||||
'4fc2f1ae-8625-45b5-ab34-ad4433bc21f8',
|
||||
'5188369a-3bbe-43d8-8b94-11558f909a08',
|
||||
'6f37996b-2ac7-44b0-8e68-6d28256631b4',
|
||||
'9318445f-fe6a-4e1b-acbf-c68228c9906a',
|
||||
'389793a7-ca17-4e82-81cb-2b3a2391b4b9',
|
||||
'4b650a35-8529-4695-89ed-8dc7a500a498',
|
||||
'a3fbeb63-0e8c-4a11-bff6-0e3b484c3e9c',
|
||||
'c714ab3a-da30-4603-bacd-d008800188b9',
|
||||
'9d191bce-651d-4746-be2d-7ef8ecadb9c2',
|
||||
'65afbc8a-89ca-4ad5-8d62-355bb401f61d',
|
||||
'cabe07ed-9eca-40ea-8ead-410ef5e83f91',
|
||||
'3cef3a44-215e-4aed-8e3b-b1e3f08063b7',
|
||||
'99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
|
||||
'd0633230-7067-47a9-9dbf-ee11e0a2cdd6',
|
||||
'305ac316-eef6-4446-960a-92d80d542f82',
|
||||
'0383a3ee-47a7-41a4-b493-519bdefe0488',
|
||||
'f918266a-b3e0-4914-865d-4faa564f1aef',
|
||||
'11af4e1a-5f45-467d-9aeb-46f4bb0bf034',
|
||||
'e142056d-56ab-4352-b091-b56054bd1359',
|
||||
'50ad0280-0819-4bd9-b275-5de32d3b5bcb',
|
||||
'7673d772-ef80-4f0f-a602-1bf4485c9b43',
|
||||
'c365c1c7-a3db-4d5e-a9a1-66f56eae7865',
|
||||
'7d4a7d1d-cac6-44a8-96e8-ea9584a70825',
|
||||
'dc22a632-937f-4e6a-b72f-ba0ff3f5ff97',
|
||||
'3f57289b-8c60-48be-bd80-01f8099ca449',
|
||||
'23dd907f-1261-4488-b21c-e9185af91d5e',
|
||||
'1f975693-876d-457b-a649-393859e79bf3',
|
||||
'840bfca7-4f7b-481a-8794-c560c340185d',
|
||||
'a0068077-79f4-461a-adfe-75c1a4148545',
|
||||
'bda648d7-d618-4883-88f4-3466eabd860e',
|
||||
'50ec8903-b81f-4257-9450-1085afd2c319',
|
||||
'cf106601-ab4f-4af9-b045-5295fe67b37d',
|
||||
'a0c07678-e491-4bbc-8f0b-07405144218f',
|
||||
'7bd855d8-463d-4ed5-93ca-5fe35145f733',
|
||||
'5a0c1adf-205e-4841-a666-7c3ef95def9d'
|
||||
],
|
||||
"level2" : [
|
||||
'c61d22de-5f6c-4958-a7f6-5e9707bd3466',
|
||||
'17b5a6a3-bc87-42e8-b0fb-6ab0781ef2cc',
|
||||
'04a04a9b-226c-43fd-b319-d5e89743676f',
|
||||
'14569e28-c88c-43e4-8c32-097d35b9a67d',
|
||||
'32102e3e-d12a-4209-9163-7b3a104efe5d',
|
||||
'3627a8be-a77f-41bb-b807-7e1bd4c0ebdf',
|
||||
'7619a514-5fa8-43ef-9143-83b66a43d7a4',
|
||||
'7dd30055-0198-452e-8c25-f73dbe27dcb8',
|
||||
'2a649bb1-795f-4a01-b3be-9a01868dae73',
|
||||
'87c610df-bef7-4932-b950-1d83ef4e282b',
|
||||
'624cbf11-6a41-4692-af9c-36b3e5ca3130',
|
||||
'dd3c7503-f62a-4bd0-9f67-1b63b94194cc',
|
||||
'df6561b2-7ee5-4540-baab-5095f742716a',
|
||||
'f0f46385-fc03-4599-b5d3-f56496c3e69f',
|
||||
'e4e91f1c-1dcd-439e-9fdd-cb976f5293fd',
|
||||
'56137764-b4e0-45b8-9c52-1866420c3df5',
|
||||
'8b3379c0-0981-4f5b-8407-6444610cb212',
|
||||
'0ff53813-3367-4f43-bcbd-3fd725c1bf4b',
|
||||
'a7feb290-76bb-4cb7-8800-7edaf7954f2f',
|
||||
'b4cc024b-3f5e-480e-b96a-6656493255b5',
|
||||
'33d8ea3b-6c6b-4ff1-803d-7e270dea8a57',
|
||||
'e8cb5b03-41e0-4086-99e5-f6806cd97211',
|
||||
'f46b4380-207e-4434-820b-f32ce04ae2a4',
|
||||
'05407167-39ec-4d3a-a234-73a9120c325d',
|
||||
'b9763138-c053-4832-9f55-86200cb1f99c',
|
||||
'16d825ff-1623-4176-a5b5-42e0f5c2b0ac',
|
||||
'2b3ef98c-cc05-450b-a719-711aee40ac65',
|
||||
'bfcd99e1-0690-4b53-a85c-0174a8629083',
|
||||
'544b7f0c-173a-4377-8d56-57b36eb26ddf',
|
||||
'6b078778-0b90-464d-83f6-59511c811b01',
|
||||
'076c8171-9b3b-49b9-a477-244d2a532826',
|
||||
'08cae58d-4084-4616-b6dd-dd6534e4825b',
|
||||
'2dfc4c37-fec1-4518-84a7-10095d30ad75',
|
||||
'9f41b083-683e-4dcf-9185-ccfeaa88fa45',
|
||||
'ecbc4f94-95a3-4cc7-b255-6741a458a625',
|
||||
'e9a2c537-8232-4c3f-85b0-b52de6bcba99',
|
||||
'71345b0a-9c7d-4b50-b2bf-937ec5879845',
|
||||
'7b5377b0-3f38-4103-8ad2-90fe89864c04',
|
||||
'114d5fd0-e2ae-4b6d-a65a-870da2d19c08',
|
||||
'8f80e01c-1296-4371-9486-bb3d68651a60',
|
||||
'ad37a656-079a-49f9-a493-7b739c9167d1',
|
||||
'366e2f2b-8632-4ef2-81eb-bc3877489217',
|
||||
'f3917a3d-1d17-4ee2-90c5-683b072218fe',
|
||||
'48eb8242-1099-4c26-95d4-ef22b002457a',
|
||||
'c8b7e059-c60d-472e-ad64-3b04ae1166dc',
|
||||
'd1af70ea-a9a4-421a-b9cc-94b5e02f1788',
|
||||
'08f3a05f-5947-4089-a4c4-d4bcfaa6b7a0',
|
||||
'54612da3-fd56-4941-80f4-5eb82330de25',
|
||||
'ded28325-3447-4c56-860f-e497d6fb3577',
|
||||
'6359a0b1-8f7b-499b-9336-840f9ab90688',
|
||||
'7cc4acfa-63fd-4acc-a1a1-e8e529e0a97f',
|
||||
'd700d50d-c707-4dca-90dc-4528cddd0c80',
|
||||
'0a3cd321-3e76-4622-911b-0fda2e5d6b1a',
|
||||
'f2feb6a4-363c-4c09-a804-0db564eafd68',
|
||||
'0b260a57-3f3a-4405-9f29-6d7a1012dbfb',
|
||||
'ed58682d-bc52-4baa-9eb0-4eb81e1edacc',
|
||||
'cca70ce6-1952-45d2-acd4-80c903b0bc49',
|
||||
'b7f857e4-d8aa-4387-af2a-0e844df5b9d8',
|
||||
'd8152ad6-e4d5-4c12-8bb7-8d57dc10c6de',
|
||||
'67e8878b-5cef-4375-804e-e6291fdbe78a',
|
||||
'023e9d44-96ae-4eed-b912-244ee8c3b994',
|
||||
'0e9e85b8-52b9-4de4-b402-5f635ab9631f',
|
||||
'20194330-9976-4043-8632-f8485c6c71b2',
|
||||
'4d51c4bf-4b0e-4f3d-897b-3f6687a7d9f2',
|
||||
'65638e28-7f37-4fa7-b7b9-8c19bb609879',
|
||||
'3ff6b7a9-a5bd-4412-ad92-0cd0d45c0fee',
|
||||
'708b99c5-e4a7-49cb-a5cf-933c8d46470d',
|
||||
'0a65cb96-cb6e-4a6a-8aae-c1084f613456',
|
||||
'65da0822-a48a-4a68-bbad-8ed1b835a834',
|
||||
'0bb3b44a-ede5-4db5-a520-4e844b0079c5',
|
||||
'73c1b9fe-ee1d-4cf4-96ca-35c08f97b054',
|
||||
'e2d69698-bc99-4e85-9880-67eaccd66e6c',
|
||||
'a56f1527-3abf-41d6-91f8-7296d6336c3f',
|
||||
'42d4198c-5895-4f0a-b0c0-424a66465d83',
|
||||
'edd4d4f2-1a58-45c4-b038-67337af4e029',
|
||||
'a26649c6-1cb2-470a-871e-6910c64c3e53',
|
||||
'4d0aa727-86b1-406b-9b33-f870dd14a4a5',
|
||||
'd5141ca5-e7a0-469f-bf3e-e773507c86e2',
|
||||
'1dcc160f-c187-48c2-b68e-319bd4354f3d',
|
||||
'b2c257e0-3ad7-4f05-b8e3-d9da973be36e',
|
||||
'e0c10771-d627-4fd7-9694-05348e54ee36',
|
||||
'e29834fd-413a-455c-a33e-c3915b07401c',
|
||||
'08c0b6e9-1b43-4c2e-ae55-4e3fce2c2715',
|
||||
'db4fd70a-2d37-40ea-873f-9433dc5e301f',
|
||||
'853c8244-429e-46ca-89f2-addf40dfb2bd',
|
||||
'7a4a336d-dcfa-45a0-b014-824c7619e8de'
|
||||
],
|
||||
"level3" : [
|
||||
'676e5e31-a554-4acc-9286-b60d90a92d26',
|
||||
'bec74516-02fc-48dc-b202-55e78d0e17cf',
|
||||
'00d579ea-0889-4fd9-a771-2c8d79835c8d',
|
||||
'384d0dd8-e8a4-4cfe-963c-d37f256e7662',
|
||||
'de9887f5-ead8-4727-876f-5a4078f8598c',
|
||||
'983bba7c-c092-455f-b6c9-7857003d48fc',
|
||||
'9b54f9d9-35ee-4a14-b62f-d130ea00317f',
|
||||
'56db2318-640f-477a-a82f-bc93ad13e882',
|
||||
'8131e2c0-0083-4265-9ce7-78c2d568425d',
|
||||
'72c06643-a2fa-4186-aa5c-9ec33ae9b445',
|
||||
'ebbc1f13-d24d-40df-9068-adcf735b4240',
|
||||
'c526d8d6-5987-4da9-b24c-83466fa172f3',
|
||||
'3da89939-209c-4086-8520-7eb734e6b4ef',
|
||||
'8d46b8d6-b38a-47ff-ac74-cda14cf2d19b',
|
||||
'e961a717-6b25-4175-8a68-874d28190ee4',
|
||||
'851e570a-e3de-4d84-bcfa-cc85578baa59',
|
||||
'50f58759-7bd6-406f-9b0d-5692beb2a926',
|
||||
'872bfbb1-9ccf-49f6-8c5f-aa22818ccd66',
|
||||
'c3a79cfe-8206-451f-aca8-3fec8ebe51d3',
|
||||
'da52d699-e8d2-4dc5-9191-a2199e0b6a9b',
|
||||
'ad2b4d70-9314-4fe6-bfbe-894a45f6055f',
|
||||
'5b2a14e8-6e59-479c-80e3-4696e8980152',
|
||||
'9e1fc53b-46ff-49a1-9d05-9e6faac34cc5',
|
||||
'5f982798-16b9-4051-ab57-cfc7ebdb2a91',
|
||||
'0512426f-4d28-49f0-be77-06d05daec096',
|
||||
'0bdb7c40-671d-4ad1-9ce3-986b159c0ddc'
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
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"
|
||||
|
||||
# use to create new skills
|
||||
jarvis_agent = JarvisAgent(config_path="./config.json", action_lib_dir=action_lib_path)
|
||||
planning_agent = jarvis_agent.planner
|
||||
|
||||
|
||||
task = '''Create the dzc.txt file in the working directory and write "dzc" into the file.'''
|
||||
planning_agent.decompose_task(task)
|
||||
|
||||
# print(planning_agent.extract_json_from_string('''```json
|
||||
# {
|
||||
# "reasoning": "The provided code defines a class 'retrieve_document' that inherits from 'BaseAction'. The '__call__' method of this class is designed to search for .txt files containing a specific keyword within a designated folder and log their paths to a file named 'agent.txt'. The code sets the working directory, searches for .txt files containing the keyword, and writes the paths of matching files to 'agent.txt'. The code output indicates that the task was executed and the paths were written to the specified file in the working directory. The presence of 'agent.txt' in the working directory, as shown in the provided files and folders list, suggests that the file was successfully created. The task description matches the code's functionality, and the code output confirms that the task was completed as intended.",
|
||||
# "judge": true,
|
||||
# "score": 7
|
||||
# }
|
||||
# ```'''
|
||||
# ))
|
||||
@@ -1,28 +0,0 @@
|
||||
import re
|
||||
import json
|
||||
|
||||
|
||||
# 示例字符串
|
||||
data = '''
|
||||
|
||||
'''
|
||||
|
||||
# 找出所有单引号的位置
|
||||
quote_positions = [pos for pos, char in enumerate(data) if char == "'"]
|
||||
|
||||
# 检查是否至少有两个单引号
|
||||
if len(quote_positions) >= 4:
|
||||
# 获取第三个单引号的位置
|
||||
start_pos = quote_positions[2]
|
||||
# 获取最后一个单引号的位置
|
||||
end_pos = quote_positions[-1]
|
||||
# 提取所需文本
|
||||
extracted_text = data[start_pos+1:end_pos]
|
||||
else:
|
||||
extracted_text = "不足以提取文本"
|
||||
|
||||
|
||||
file_path = ""
|
||||
with open(file_path,"w",encoding="utf-8") as f2:
|
||||
f2.write(extracted_text)
|
||||
|
||||
55
friday/action/base_action.py
Normal file
55
friday/action/base_action.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class BaseAction:
|
||||
"""Base class for all actions.
|
||||
|
||||
Args:
|
||||
description (str, optional): The description of the action. Defaults to
|
||||
None.
|
||||
name (str, optional): The name of the action. If None, the name will
|
||||
be class name. Defaults to None.
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
description: Optional[str] = None,
|
||||
name: Optional[str] = None,
|
||||
timeout: int = 2,
|
||||
action_type: Optional[str] = 'BASH') -> None:
|
||||
if name is None:
|
||||
name = self.__class__.__name__
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._timeout = timeout
|
||||
assert action_type in ['BASH', 'CODE', 'TOOL']
|
||||
self.action_type = action_type
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def _python(self, *lines):
|
||||
return f'python -Bc "{"; ".join(lines)}"'
|
||||
|
||||
def _import(self, *packages):
|
||||
return f'from jarvis.{".".join(packages)} import *'
|
||||
|
||||
@property
|
||||
def timeout(self):
|
||||
return self._timeout
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self._description
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.name}:{self.description}'
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
if __name__ == '__main__':
|
||||
action = BaseAction()
|
||||
@@ -1,5 +1,4 @@
|
||||
import platform
|
||||
# import os
|
||||
|
||||
def get_os_version():
|
||||
system = platform.system()
|
||||
@@ -8,7 +7,6 @@ def get_os_version():
|
||||
# macOS
|
||||
return 'macOS ' + platform.mac_ver()[0]
|
||||
elif system == "Linux":
|
||||
# Linux: 尝试读取 /etc/os-release 文件
|
||||
try:
|
||||
with open("/etc/os-release") as f:
|
||||
lines = f.readlines()
|
||||
@@ -18,7 +16,6 @@ def get_os_version():
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# 如果 /etc/os-release 不存在或无法提供所需信息
|
||||
return platform.version()
|
||||
else:
|
||||
return "Unknown Operating System"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user