mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-08 22:58:01 -05:00
Prevent docker compose to break config by creating folders (#4125)
This commit is contained in:
@@ -73,7 +73,7 @@ class 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 = {}
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ class Config(metaclass=Singleton):
|
||||
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 = (
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -43,3 +43,32 @@ ai_role: A hungry AI
|
||||
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
|
||||
|
||||
@@ -4,6 +4,7 @@ for the AI and ensures it behaves as a singleton.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from openai import InvalidRequestError
|
||||
|
||||
from autogpt.configurator import create_config
|
||||
@@ -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 == {}
|
||||
|
||||
Reference in New Issue
Block a user