Skip to content

Commit

Permalink
Prevent docker compose to break config by creating folders (Significa…
Browse files Browse the repository at this point in the history
  • Loading branch information
k-boikov authored May 22, 2023
1 parent dcb1cbe commit 360d5cd
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion autogpt/config/ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def load(config_file: str = SAVE_FILE) -> "AIConfig":

try:
with open(config_file, encoding="utf-8") as file:
config_params = yaml.load(file, Loader=yaml.FullLoader)
config_params = yaml.load(file, Loader=yaml.FullLoader) or {}
except FileNotFoundError:
config_params = {}

Expand Down
2 changes: 1 addition & 1 deletion autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def load_azure_config(self, config_file: str = AZURE_CONFIG_FILE) -> None:
None
"""
with open(config_file) as file:
config_params = yaml.load(file, Loader=yaml.FullLoader)
config_params = yaml.load(file, Loader=yaml.FullLoader) or {}
self.openai_api_type = config_params.get("azure_api_type") or "azure"
self.openai_api_base = config_params.get("azure_api_base") or ""
self.openai_api_version = (
Expand Down
11 changes: 8 additions & 3 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ Get your OpenAI API key from: [https://platform.openai.com/account/api-keys](htt
- ./data:/app/data
## allow auto-gpt to write logs to disk
- ./logs:/app/logs
## uncomment following lines if you have / want to make use of these files
#- ./azure.yaml:/app/azure.yaml
#- ./ai_settings.yaml:/app/ai_settings.yaml
## uncomment following lines if you want to make use of these files
## you must have them existing in the same folder as this docker-compose.yml
#- type: bind
# source: ./azure.yaml
# target: /app/azure.yaml
#- type: bind
# source: ./ai_settings.yaml
# target: /app/ai_settings.yaml
redis:
image: "redis/redis-stack-server:latest"

Expand Down
29 changes: 29 additions & 0 deletions tests/test_ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,32 @@ def test_goals_are_always_lists_of_strings(tmp_path):
api_budget: 0.0
"""
assert config_file.read_text() == yaml_content2


def test_ai_config_file_not_exists(workspace):
"""Test if file does not exist."""

config_file = workspace.get_path("ai_settings.yaml")

ai_config = AIConfig.load(str(config_file))
assert ai_config.ai_name == ""
assert ai_config.ai_role == ""
assert ai_config.ai_goals == []
assert ai_config.api_budget == 0.0
assert ai_config.prompt_generator is None
assert ai_config.command_registry is None


def test_ai_config_file_is_empty(workspace):
"""Test if file does not exist."""

config_file = workspace.get_path("ai_settings.yaml")
config_file.write_text("")

ai_config = AIConfig.load(str(config_file))
assert ai_config.ai_name == ""
assert ai_config.ai_role == ""
assert ai_config.ai_goals == []
assert ai_config.api_budget == 0.0
assert ai_config.prompt_generator is None
assert ai_config.command_registry is None
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from unittest.mock import patch

import pytest
from openai import InvalidRequestError

from autogpt.configurator import create_config
Expand Down Expand Up @@ -155,3 +156,17 @@ def test_smart_and_fast_llm_models_set_to_gpt4(mock_list_models, config):
# Reset config
config.set_fast_llm_model(fast_llm_model)
config.set_smart_llm_model(smart_llm_model)


def test_missing_azure_config(config, workspace):
config_file = workspace.get_path("azure_config.yaml")
with pytest.raises(FileNotFoundError):
config.load_azure_config(str(config_file))

config_file.write_text("")
config.load_azure_config(str(config_file))

assert config.openai_api_type == "azure"
assert config.openai_api_base == ""
assert config.openai_api_version == "2023-03-15-preview"
assert config.azure_model_to_deployment_id_map == {}

0 comments on commit 360d5cd

Please sign in to comment.