Files
Auto-GPT/tests/test_config.py
Nicholas Tindle acfd966aa4 Pass Configs to Commands and remove CFG = Config() in the commands/ folder (#4328)
* feat: pass config to call_ai_functions in coimmands

* feat: config for read_audio_from_file

* feat: file operations cfg

NOTE: we replaced the CFG in the command enable with TRUE b/c not sure how to handle this yet

* feat: git command conversion

* feat: google search

* feat: image generation

* feat: extract cfg from browser commands

* feat: remove cfg from execute code commands

* fix: file operation related tests

* fix: linting

* fix: tests for read_audio

* fix: test error

* feat: update cassettes

* fix: linting

* fix: test typechecking

* fix: google_search errors if unexpected kw arg is passed

* fix: pass config param to google search test

* fix: agent commands were broken + cassettes

* fix: agent test

* feat: cassettes

* feat: enable/disable logic for commands

* fix: some commands threw errors

* feat: fix tests

* Add new cassettes

* Add new cassettes

* ci: trigger ci

* Update autogpt/commands/execute_code.py

Co-authored-by: Reinier van der Leer <github@pwuts.nl>

* fix prompt

* fix prompt + rebase

* add config remove useless imports

* put back CFG just for download file

* lint

* The signature should be mandatory in the decorator

* black isort

* fix: remove the CFG

* fix: non typed arg

* lint: type some args

* lint: add types for libraries

* Add new cassettes

* fix: windows compatibility

* fix: add config access to decorator

* fix: remove twitter mention

* DDGS search works at 3.0.2 version

* ci: linting

---------

Co-authored-by: Auto-GPT-Bot <github-bot@agpt.co>
Co-authored-by: merwanehamadi <merwanehamadi@gmail.com>
Co-authored-by: Reinier van der Leer <github@pwuts.nl>
Co-authored-by: kinance <kinance@gmail.com>
2023-05-26 08:39:25 -07:00

174 lines
4.8 KiB
Python

"""
Test cases for the Config class, which handles the configuration settings
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
def test_initial_values(config):
"""
Test if the initial values of the Config class attributes are set correctly.
"""
assert config.debug_mode == False
assert config.continuous_mode == False
assert config.speak_mode == False
assert config.fast_llm_model == "gpt-3.5-turbo"
assert config.smart_llm_model == "gpt-4"
assert config.fast_token_limit == 4000
assert config.smart_token_limit == 8000
def test_set_continuous_mode(config):
"""
Test if the set_continuous_mode() method updates the continuous_mode attribute.
"""
# Store continuous mode to reset it after the test
continuous_mode = config.continuous_mode
config.set_continuous_mode(True)
assert config.continuous_mode == True
# Reset continuous mode
config.set_continuous_mode(continuous_mode)
def test_set_speak_mode(config):
"""
Test if the set_speak_mode() method updates the speak_mode attribute.
"""
# Store speak mode to reset it after the test
speak_mode = config.speak_mode
config.set_speak_mode(True)
assert config.speak_mode == True
# Reset speak mode
config.set_speak_mode(speak_mode)
def test_set_fast_llm_model(config):
"""
Test if the set_fast_llm_model() method updates the fast_llm_model attribute.
"""
# Store model name to reset it after the test
fast_llm_model = config.fast_llm_model
config.set_fast_llm_model("gpt-3.5-turbo-test")
assert config.fast_llm_model == "gpt-3.5-turbo-test"
# Reset model name
config.set_fast_llm_model(fast_llm_model)
def test_set_smart_llm_model(config):
"""
Test if the set_smart_llm_model() method updates the smart_llm_model attribute.
"""
# Store model name to reset it after the test
smart_llm_model = config.smart_llm_model
config.set_smart_llm_model("gpt-4-test")
assert config.smart_llm_model == "gpt-4-test"
# Reset model name
config.set_smart_llm_model(smart_llm_model)
def test_set_fast_token_limit(config):
"""
Test if the set_fast_token_limit() method updates the fast_token_limit attribute.
"""
# Store token limit to reset it after the test
fast_token_limit = config.fast_token_limit
config.set_fast_token_limit(5000)
assert config.fast_token_limit == 5000
# Reset token limit
config.set_fast_token_limit(fast_token_limit)
def test_set_smart_token_limit(config):
"""
Test if the set_smart_token_limit() method updates the smart_token_limit attribute.
"""
# Store token limit to reset it after the test
smart_token_limit = config.smart_token_limit
config.set_smart_token_limit(9000)
assert config.smart_token_limit == 9000
# Reset token limit
config.set_smart_token_limit(smart_token_limit)
def test_set_debug_mode(config):
"""
Test if the set_debug_mode() method updates the debug_mode attribute.
"""
# Store debug mode to reset it after the test
debug_mode = config.debug_mode
config.set_debug_mode(True)
assert config.debug_mode == True
# Reset debug mode
config.set_debug_mode(debug_mode)
@patch("openai.Model.list")
def test_smart_and_fast_llm_models_set_to_gpt4(mock_list_models, config):
"""
Test if models update to gpt-3.5-turbo if both are set to gpt-4.
"""
fast_llm_model = config.fast_llm_model
smart_llm_model = config.smart_llm_model
config.fast_llm_model = "gpt-4"
config.smart_llm_model = "gpt-4"
mock_list_models.return_value = {"data": [{"id": "gpt-3.5-turbo"}]}
create_config(
config=config,
continuous=False,
continuous_limit=False,
ai_settings_file="",
prompt_settings_file="",
skip_reprompt=False,
speak=False,
debug=False,
gpt3only=False,
gpt4only=False,
memory_type="",
browser_name="",
allow_downloads=False,
skip_news=False,
)
assert config.fast_llm_model == "gpt-3.5-turbo"
assert config.smart_llm_model == "gpt-3.5-turbo"
# 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 == {}