mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-09 15:17:59 -05:00
Moved from `autogpt` to `forge`:
- `autogpt.config` -> `forge.config`
- `autogpt.processing` -> `forge.content_processing`
- `autogpt.file_storage` -> `forge.file_storage`
- `autogpt.logs` -> `forge.logging`
- `autogpt.speech` -> `forge.speech`
- `autogpt.agents.(base|components|protocols)` -> `forge.agent.*`
- `autogpt.command_decorator` -> `forge.command.decorator`
- `autogpt.models.(command|command_parameter)` -> `forge.command.(command|parameter)`
- `autogpt.(commands|components|features)` -> `forge.components`
- `autogpt.core.utils.json_utils` -> `forge.json.parsing`
- `autogpt.prompts.utils` -> `forge.llm.prompting.utils`
- `autogpt.core.prompting.(base|schema|utils)` -> `forge.llm.prompting.*`
- `autogpt.core.resource.model_providers` -> `forge.llm.providers`
- `autogpt.llm.providers.openai` + `autogpt.core.resource.model_providers.utils`
-> `forge.llm.providers.utils`
- `autogpt.models.action_history:Action*` -> `forge.models.action`
- `autogpt.core.configuration.schema` -> `forge.models.config`
- `autogpt.core.utils.json_schema` -> `forge.models.json_schema`
- `autogpt.core.resource.schema` -> `forge.models.providers`
- `autogpt.models.utils` -> `forge.models.utils`
- `forge.sdk.(errors|utils)` + `autogpt.utils.(exceptions|file_operations_utils|validators)`
-> `forge.utils.(exceptions|file_operations|url_validator)`
- `autogpt.utils.utils` -> `forge.utils.const` + `forge.utils.yaml_validator`
Moved within `forge`:
- forge/prompts/* -> forge/llm/prompting/*
The rest are mostly import updates, and some sporadic removals and necessary updates (for example to fix circular deps):
- Changed `CommandOutput = Any` to remove coupling with `ContextItem` (no longer needed)
- Removed unused `Singleton` class
- Reluctantly moved `speech` to forge due to coupling (tts needs to be changed into component)
- Moved `function_specs_from_commands` and `core/resource/model_providers` to `llm/providers` (resources were a `core` thing and are no longer relevant)
- Keep tests in `autogpt` to reduce changes in this PR
- Removed unused memory-related code from tests
- Removed duplicated classes: `FancyConsoleFormatter`, `BelowLevelFilter`
- `prompt_settings.yaml` is in both `autogpt` and `forge` because for some reason doesn't work when placed in just one dir (need to be taken care of)
- Removed `config` param from `clean_input`, it wasn't used and caused circular dependency
- Renamed `BaseAgentActionProposal` to `ActionProposal`
- Updated `pyproject.toml` in `forge` and `autogpt`
- Moved `Action*` models from `forge/components/action_history/model.py` to `forge/models/action.py` as those are relevant to the entire agent and not just `EventHistoryComponent` + to reduce coupling
- Renamed `DEFAULT_ASK_COMMAND` to `ASK_COMMAND` and `DEFAULT_FINISH_COMMAND` to `FINISH_COMMAND`
- Renamed `AutoGptFormatter` to `ForgeFormatter` and moved to `forge`
Includes changes from PR https://github.com/Significant-Gravitas/AutoGPT/pull/7148
---------
Co-authored-by: Reinier van der Leer <pwuts@agpt.co>
113 lines
3.3 KiB
Python
113 lines
3.3 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from forge.file_storage import FileStorage
|
|
|
|
from autogpt.agents.agent import Agent
|
|
|
|
|
|
@pytest.fixture()
|
|
def file_content():
|
|
return "This is a test file.\n"
|
|
|
|
|
|
@pytest.fixture
|
|
def file_manager_component(agent: Agent):
|
|
return agent.file_manager
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_file_name():
|
|
return Path("test_file.txt")
|
|
|
|
|
|
@pytest.fixture
|
|
def test_file_path(test_file_name: Path, storage: FileStorage):
|
|
return storage.get_path(test_file_name)
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_directory(storage: FileStorage):
|
|
return storage.get_path("test_directory")
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_nested_file(storage: FileStorage):
|
|
return storage.get_path("nested/test_file.txt")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_read_file(
|
|
test_file_path: Path,
|
|
file_content,
|
|
file_manager_component,
|
|
agent: Agent,
|
|
):
|
|
await agent.file_manager.workspace.write_file(test_file_path.name, file_content)
|
|
content = file_manager_component.read_file(test_file_path.name)
|
|
assert content.replace("\r", "") == file_content
|
|
|
|
|
|
def test_read_file_not_found(file_manager_component):
|
|
filename = "does_not_exist.txt"
|
|
with pytest.raises(FileNotFoundError):
|
|
file_manager_component.read_file(filename)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_write_to_file_relative_path(
|
|
test_file_name: Path, file_manager_component, agent: Agent
|
|
):
|
|
new_content = "This is new content.\n"
|
|
await file_manager_component.write_to_file(test_file_name, new_content)
|
|
with open(
|
|
agent.file_manager.workspace.get_path(test_file_name), "r", encoding="utf-8"
|
|
) as f:
|
|
content = f.read()
|
|
assert content == new_content
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_write_to_file_absolute_path(
|
|
test_file_path: Path, file_manager_component
|
|
):
|
|
new_content = "This is new content.\n"
|
|
await file_manager_component.write_to_file(test_file_path, new_content)
|
|
with open(test_file_path, "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
assert content == new_content
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_files(file_manager_component, agent: Agent):
|
|
# Create files A and B
|
|
file_a_name = "file_a.txt"
|
|
file_b_name = "file_b.txt"
|
|
test_directory = Path("test_directory")
|
|
|
|
await agent.file_manager.workspace.write_file(file_a_name, "This is file A.")
|
|
await agent.file_manager.workspace.write_file(file_b_name, "This is file B.")
|
|
|
|
# Create a subdirectory and place a copy of file_a in it
|
|
agent.file_manager.workspace.make_dir(test_directory)
|
|
await agent.file_manager.workspace.write_file(
|
|
test_directory / file_a_name, "This is file A in the subdirectory."
|
|
)
|
|
|
|
files = file_manager_component.list_folder(".")
|
|
assert file_a_name in files
|
|
assert file_b_name in files
|
|
assert os.path.join(test_directory, file_a_name) in files
|
|
|
|
# Clean up
|
|
agent.file_manager.workspace.delete_file(file_a_name)
|
|
agent.file_manager.workspace.delete_file(file_b_name)
|
|
agent.file_manager.workspace.delete_file(test_directory / file_a_name)
|
|
agent.file_manager.workspace.delete_dir(test_directory)
|
|
|
|
# Case 2: Search for a file that does not exist and make sure we don't throw
|
|
non_existent_file = "non_existent_file.txt"
|
|
files = file_manager_component.list_folder("")
|
|
assert non_existent_file not in files
|