mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-22 06:34:32 +01:00
Changed abilities to async
This commit is contained in:
@@ -16,7 +16,7 @@ from ..registry import ability
|
||||
],
|
||||
output_type="list[str]",
|
||||
)
|
||||
def list_files(agent, task_id:str, path: str) -> List[str]:
|
||||
async def list_files(agent, task_id:str, path: str) -> List[str]:
|
||||
"""
|
||||
List files in a workspace directory
|
||||
"""
|
||||
@@ -41,11 +41,15 @@ def list_files(agent, task_id:str, path: str) -> List[str]:
|
||||
],
|
||||
output_type="None",
|
||||
)
|
||||
def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
|
||||
async def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
|
||||
"""
|
||||
Write data to a file
|
||||
"""
|
||||
if isinstance(data, str):
|
||||
data = data.encode()
|
||||
|
||||
agent.workspace.write(task_id=task_id, path=file_path, data=data)
|
||||
await agent.db.create_artifact(task_id=task_id, file_name=file_path.split('/')[-1], relative_path=file_path, agent_created=True)
|
||||
|
||||
|
||||
@ability(
|
||||
@@ -61,7 +65,7 @@ def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
|
||||
],
|
||||
output_type="bytes",
|
||||
)
|
||||
def read_file(agent, task_id: str, file_path: str) -> bytes:
|
||||
async def read_file(agent, task_id: str, file_path: str) -> bytes:
|
||||
"""
|
||||
Read data from a file
|
||||
"""
|
||||
|
||||
@@ -18,7 +18,7 @@ logger = ForgeLogger(__name__)
|
||||
],
|
||||
output_type="None"
|
||||
)
|
||||
def finish(agent, task_id: str, reason: str,) -> str:
|
||||
async def finish(agent, task_id: str, reason: str,) -> str:
|
||||
"""
|
||||
A function that takes in a string and exits the program
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ def ability(
|
||||
[AbilityParameter.parse_obj(param).name for param in parameters]
|
||||
)
|
||||
param_names.add("agent")
|
||||
param_names.add("task_id")
|
||||
func_param_names = set(func_params.keys())
|
||||
if param_names != func_param_names:
|
||||
raise ValueError(
|
||||
@@ -104,7 +105,6 @@ class AbilityRegister:
|
||||
self.agent = agent
|
||||
|
||||
def register_abilities(self) -> None:
|
||||
print(os.path.join(os.path.dirname(__file__), "*.py"))
|
||||
for ability_path in glob.glob(
|
||||
os.path.join(os.path.dirname(__file__), "**/*.py"), recursive=True
|
||||
):
|
||||
@@ -117,7 +117,7 @@ class AbilityRegister:
|
||||
).replace("/", ".")
|
||||
try:
|
||||
module = importlib.import_module(
|
||||
f".{ability[:-3]}", package="autogpt.sdk.abilities"
|
||||
f".{ability[:-3]}", package="forge.sdk.abilities"
|
||||
)
|
||||
for attr in dir(module):
|
||||
func = getattr(module, attr)
|
||||
@@ -156,7 +156,7 @@ class AbilityRegister:
|
||||
|
||||
return abilities_description
|
||||
|
||||
def run_ability(self, task_id: str, ability_name: str, *args: Any, **kwds: Any) -> Any:
|
||||
async def run_ability(self, task_id: str, ability_name: str, *args: Any, **kwds: Any) -> Any:
|
||||
"""
|
||||
This method runs a specified ability with the provided arguments and keyword arguments.
|
||||
|
||||
@@ -177,7 +177,7 @@ class AbilityRegister:
|
||||
"""
|
||||
try:
|
||||
ability = self.abilities[ability_name]
|
||||
return ability(self.agent, task_id, *args, **kwds)
|
||||
return await ability(self.agent, task_id, *args, **kwds)
|
||||
except Exception:
|
||||
raise
|
||||
|
||||
|
||||
Reference in New Issue
Block a user