Files
AutoGPT/autogpt/tests/integration/test_setup.py
Krzysztof Czerwinski c19ab2b24f feat(forge): Component-specific configuration (#7170)
Remove many env vars and use component-level configuration that could be loaded from file instead.

### Changed

- `BaseAgent` provides `serialize_configs` and `deserialize_configs` that can save and load all component configuration as json `str`. Deserialized components/values overwrite existing values, so not all values need to be present in the serialized config.
- Decoupled `forge/content_processing/text.py` from `Config`
- Kept `execute_local_commands` in `Config` because it's needed to know if OS info should be included in the prompt
- Updated docs to reflect changes
- Renamed `Config` to `AppConfig`

### Added

- Added `ConfigurableComponent` class for components and following configs:
  - `ActionHistoryConfiguration`
  - `CodeExecutorConfiguration`
  - `FileManagerConfiguration` - now file manager allows to have multiple agents using the same workspace
  - `GitOperationsConfiguration`
  - `ImageGeneratorConfiguration`
  - `WebSearchConfiguration`
  - `WebSeleniumConfiguration`
- `BaseConfig` in `forge` and moved `Config` (now inherits from `BaseConfig`) back to `autogpt`
- Required `config_class` attribute for the `ConfigurableComponent` class that should be set to configuration class for a component
`--component-config-file` CLI option and `COMPONENT_CONFIG_FILE` env var and field in `Config`. This option allows to load configuration from a specific file, CLI option takes precedence over env var.
- Added comments to config models

### Removed

- Unused `change_agent_id` method from `FileManagerComponent`
- Unused `allow_downloads` from `Config` and CLI options (it should be in web component config if needed)
- CLI option `--browser-name` (the option is inside `WebSeleniumConfiguration`)
- Unused `workspace_directory` from CLI options
- No longer needed variables from `Config` and docs
- Unused fields from `Config`: `image_size`, `audio_to_text_provider`, `huggingface_audio_to_text_model`
- Removed `files` and `workspace` class attributes from `FileManagerComponent`
2024-06-19 09:14:01 +01:00

72 lines
2.0 KiB
Python

from unittest.mock import patch
import pytest
from forge.config.ai_directives import AIDirectives
from forge.config.ai_profile import AIProfile
from autogpt.app.config import AppConfig
from autogpt.app.setup import (
apply_overrides_to_ai_settings,
interactively_revise_ai_settings,
)
@pytest.mark.asyncio
async def test_apply_overrides_to_ai_settings():
ai_profile = AIProfile(ai_name="Test AI", ai_role="Test Role")
directives = AIDirectives(
resources=["Resource1"],
constraints=["Constraint1"],
best_practices=["BestPractice1"],
)
apply_overrides_to_ai_settings(
ai_profile,
directives,
override_name="New AI",
override_role="New Role",
replace_directives=True,
resources=["NewResource"],
constraints=["NewConstraint"],
best_practices=["NewBestPractice"],
)
assert ai_profile.ai_name == "New AI"
assert ai_profile.ai_role == "New Role"
assert directives.resources == ["NewResource"]
assert directives.constraints == ["NewConstraint"]
assert directives.best_practices == ["NewBestPractice"]
@pytest.mark.asyncio
async def test_interactively_revise_ai_settings(config: AppConfig):
ai_profile = AIProfile(ai_name="Test AI", ai_role="Test Role")
directives = AIDirectives(
resources=["Resource1"],
constraints=["Constraint1"],
best_practices=["BestPractice1"],
)
user_inputs = [
"n",
"New AI",
"New Role",
"NewConstraint",
"",
"NewResource",
"",
"NewBestPractice",
"",
"y",
]
with patch("autogpt.app.setup.clean_input", side_effect=user_inputs):
ai_profile, directives = await interactively_revise_ai_settings(
ai_profile, directives, config
)
assert ai_profile.ai_name == "New AI"
assert ai_profile.ai_role == "New Role"
assert directives.resources == ["NewResource"]
assert directives.constraints == ["NewConstraint"]
assert directives.best_practices == ["NewBestPractice"]