Skip to content

Commit

Permalink
docker setup more small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HMDCrew committed Oct 8, 2023
1 parent 9bb96db commit f4303d3
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 120 deletions.
2 changes: 1 addition & 1 deletion autogpts/autogpt/autogpt/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def execute(
)

# Intercept ContextItem if one is returned by the command
if type(return_value) == tuple and isinstance(
if isinstance(return_value, tuple) and isinstance(
return_value[1], ContextItem
):
context_item = return_value[1]
Expand Down
5 changes: 4 additions & 1 deletion autogpts/autogpt/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def workspace(workspace_root: Path) -> Workspace:

@pytest.fixture
def temp_plugins_config_file():
"""Create a plugins_config.yaml file in a temp directory so that it doesn't mess with existing ones"""
"""
Create a plugins_config.yaml file in a temp directory so that it doesn't
mess with existing ones
"""
config_directory = TemporaryDirectory()
config_file = os.path.join(config_directory.name, "plugins_config.yaml")
with open(config_file, "w+") as f:
Expand Down
147 changes: 99 additions & 48 deletions autogpts/autogpt/tests/unit/_test_json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def test_invalid_json_minor():


def test_invalid_json_major_with_gpt():
"""Test that an invalid JSON string raises an error when try_to_fix_with_gpt is False."""
"""
Test that an invalid JSON string raises an error when try_to_fix_with_gpt is False.
"""
json_str = 'BEGIN: "name": "John" - "age": 30 - "city": "New York" :END'
assert fix_and_parse_json(json_str, try_to_fix_with_gpt=True) == {
"name": "John",
Expand All @@ -31,17 +33,24 @@ def test_invalid_json_major_with_gpt():


def test_invalid_json_major_without_gpt():
"""Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False."""
"""
Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt
is False.
"""
json_str = 'BEGIN: "name": "John" - "age": 30 - "city": "New York" :END'
# Assert that this raises an exception:
with pytest.raises(Exception):
fix_and_parse_json(json_str, try_to_fix_with_gpt=False)


def test_invalid_json_leading_sentence_with_gpt():
"""Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False."""
"""
Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt
is False.
"""

json_str = """I suggest we start by browsing the repository to find any issues that we can fix.
json_str = """
I suggest we start by browsing the repository to find any issues that we can fix.
{
"command": {
Expand All @@ -52,10 +61,17 @@ def test_invalid_json_leading_sentence_with_gpt():
},
"thoughts":
{
"text": "I suggest we start browsing the repository to find any issues that we can fix.",
"reasoning": "Browsing the repository will give us an idea of the current state of the codebase and identify any issues that we can address to improve the repo.",
"plan": "- Look through the repository to find any issues.\n- Investigate any issues to determine what needs to be fixed\n- Identify possible solutions to fix the issues\n- Open Pull Requests with fixes",
"criticism": "I should be careful while browsing so as not to accidentally introduce any new bugs or issues.",
"text": "I suggest we start browsing the repository to find any issues
that we can fix.",
"reasoning": "Browsing the repository will give us an idea of the current
state of the codebase and identify any issues that we can address
to improve the repo.",
"plan": "- Look through the repository to find any issues.\n
- Investigate any issues to determine what needs to be fixed\n
- Identify possible solutions to fix the issues\n
- Open Pull Requests with fixes",
"criticism": "I should be careful while browsing so as not to accidentally
introduce any new bugs or issues.",
"speak": "I will start browsing the repository to find any issues we can fix."
}
}"""
Expand All @@ -65,49 +81,84 @@ def test_invalid_json_leading_sentence_with_gpt():
"args": {"url": "https://github.com/Significant-Gravitas/AutoGPT"},
},
"thoughts": {
"text": "I suggest we start browsing the repository to find any issues that we can fix.",
"reasoning": "Browsing the repository will give us an idea of the current state of the codebase and identify any issues that we can address to improve the repo.",
"plan": "- Look through the repository to find any issues.\n- Investigate any issues to determine what needs to be fixed\n- Identify possible solutions to fix the issues\n- Open Pull Requests with fixes",
"criticism": "I should be careful while browsing so as not to accidentally introduce any new bugs or issues.",
"speak": "I will start browsing the repository to find any issues we can fix.",
"text": (
"I suggest we start browsing the repository to find any issues"
"that we can fix."
),
"reasoning": (
"Browsing the repository will give us an idea of the current state "
"of the codebase and identify any issues that we can address to "
"improve the repo."
),
"plan": (
"- Look through the repository to find any issues.\n"
"- Investigate any issues to determine what needs to be fixed\n"
"- Identify possible solutions to fix the issues\n"
"- Open Pull Requests with fixes"
),
"criticism": (
"I should be careful while browsing so as not to accidentally "
"introduce any new bugs or issues."
),
"speak": (
"I will start browsing the repository to find any issues we can fix."
),
},
}
# Assert that this raises an exception:
assert fix_and_parse_json(json_str, try_to_fix_with_gpt=False) == good_obj


def test_invalid_json_leading_sentence_with_gpt(self):
"""Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False."""
json_str = """I will first need to browse the repository (https://github.com/Significant-Gravitas/AutoGPT) and identify any potential bugs that need fixing. I will use the "browse_website" command for this.
{
"command": {
"name": "browse_website",
"args":{
"url": "https://github.com/Significant-Gravitas/AutoGPT"
}
},
"thoughts":
{
"text": "Browsing the repository to identify potential bugs",
"reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.",
"plan": "- Analyze the repository for potential bugs and areas of improvement",
"criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.",
"speak": "I am browsing the repository to identify potential bugs."
}
}"""
good_obj = {
"command": {
"name": "browse_website",
"args": {"url": "https://github.com/Significant-Gravitas/AutoGPT"},
},
"thoughts": {
"text": "Browsing the repository to identify potential bugs",
"reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.",
"plan": "- Analyze the repository for potential bugs and areas of improvement",
"criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.",
"speak": "I am browsing the repository to identify potential bugs.",
},
}

assert fix_and_parse_json(json_str, try_to_fix_with_gpt=False) == good_obj
# def test_invalid_json_leading_sentence_with_gpt(self):
# """
# Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt
# is False.
# """
# json_str = """
# I will first need to browse the repository
# (https://github.com/Significant-Gravitas/AutoGPT) and identify any potential
# bugs that need fixing. I will use the "browse_website" command for this.

# {
# "command": {
# "name": "browse_website",
# "args":{
# "url": "https://github.com/Significant-Gravitas/AutoGPT"
# }
# },
# "thoughts":
# {
# "text": "Browsing the repository to identify potential bugs",
# "reasoning": "Before fixing bugs, I need to identify what needs fixing.
# I will use the 'browse_website' command to analyze the
# repository.",
# "plan": "- Analyze the repository for potential bugs and areas of
# improvement",
# "criticism": "I need to ensure I am thorough and pay attention to detail while
# browsing the repository.",
# "speak": "I am browsing the repository to identify potential bugs."
# }
# }"""
# good_obj = {
# "command": {
# "name": "browse_website",
# "args": {"url": "https://github.com/Significant-Gravitas/AutoGPT"},
# },
# "thoughts": {
# "text": "Browsing the repository to identify potential bugs",
# "reasoning": (
# "Before fixing bugs, I need to identify what needs fixing. "
# "I will use the 'browse_website' command to analyze the repository."
# ),
# "plan": (
# "- Analyze the repository for potential bugs and areas of improvement"
# ),
# "criticism": (
# "I need to ensure I am thorough and pay attention to detail "
# "while browsing the repository."
# ),
# "speak": "I am browsing the repository to identify potential bugs.",
# },
# }

# assert fix_and_parse_json(json_str, try_to_fix_with_gpt=False) == good_obj
14 changes: 7 additions & 7 deletions autogpts/autogpt/tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_initial_values(config: Config) -> None:
"""
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.debug_mode is False
assert config.continuous_mode is False
assert config.speak_mode is False
assert config.fast_llm == "gpt-3.5-turbo-16k"
assert config.smart_llm == "gpt-4-0314"

Expand All @@ -33,7 +33,7 @@ def test_set_continuous_mode(config: Config) -> None:
continuous_mode = config.continuous_mode

config.continuous_mode = True
assert config.continuous_mode == True
assert config.continuous_mode is True

# Reset continuous mode
config.continuous_mode = continuous_mode
Expand All @@ -47,7 +47,7 @@ def test_set_speak_mode(config: Config) -> None:
speak_mode = config.speak_mode

config.speak_mode = True
assert config.speak_mode == True
assert config.speak_mode is True

# Reset speak mode
config.speak_mode = speak_mode
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_set_debug_mode(config: Config) -> None:
debug_mode = config.debug_mode

config.debug_mode = True
assert config.debug_mode == True
assert config.debug_mode is True

# Reset debug mode
config.debug_mode = debug_mode
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_missing_azure_config(workspace: Workspace) -> None:

def test_azure_config(config: Config, workspace: Workspace) -> None:
config_file = workspace.get_path("azure_config.yaml")
yaml_content = f"""
yaml_content = """
azure_api_type: azure
azure_api_base: https://dummy.openai.azure.com
azure_api_version: 2023-06-01-preview
Expand Down
9 changes: 6 additions & 3 deletions autogpts/autogpt/tests/unit/test_file_operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This set of unit tests is designed to test the file operations that autoGPT has access to.
This set of unit tests is designed to test the file operations that autoGPT
has access to.
"""

import hashlib
Expand Down Expand Up @@ -169,9 +170,10 @@ def test_is_duplicate_operation(agent: Agent, mocker: MockerFixture):
# Test logging a file operation
def test_log_operation(agent: Agent):
file_ops.log_operation("log_test", "path/to/test", agent=agent)
expected_path = "path/to/test"
with open(agent.legacy_config.file_logger_path, "r", encoding="utf-8") as f:
content = f.read()
assert f"log_test: path/to/test\n" in content
assert f"log_test: {expected_path}\n" in content


def test_text_checksum(file_content: str):
Expand All @@ -183,9 +185,10 @@ def test_text_checksum(file_content: str):

def test_log_operation_with_checksum(agent: Agent):
file_ops.log_operation("log_test", "path/to/test", agent=agent, checksum="ABCDEF")
expected_path = "path/to/test"
with open(agent.legacy_config.file_logger_path, "r", encoding="utf-8") as f:
content = f.read()
assert f"log_test: path/to/test #ABCDEF\n" in content
assert f"log_test: {expected_path} #ABCDEF\n" in content


def test_read_file(
Expand Down
3 changes: 2 additions & 1 deletion autogpts/autogpt/tests/unit/test_git_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def test_clone_auto_gpt_repository(workspace, mock_clone_from, agent: Agent):

assert clone_result == expected_output
mock_clone_from.assert_called_once_with(
url=f"{scheme}{agent.legacy_config.github_username}:{agent.legacy_config.github_api_key}@{repo}",
url=f"{scheme}{agent.legacy_config.github_username}:\
{agent.legacy_config.github_api_key}@{repo}",
to_path=clone_path,
)

Expand Down
16 changes: 12 additions & 4 deletions autogpts/autogpt/tests/unit/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
"raw_text, clean_text",
[
(
"COMMAND = \x1b[36mbrowse_website\x1b[0m ARGUMENTS = \x1b[36m{'url': 'https://www.google.com', 'question': 'What is the capital of France?'}\x1b[0m",
"COMMAND = browse_website ARGUMENTS = {'url': 'https://www.google.com', 'question': 'What is the capital of France?'}",
"COMMAND = \x1b[36mbrowse_website\x1b[0m ARGUMENTS = \x1b[36m"
"{'url': 'https://www.google.com',"
" 'question': 'What is the capital of France?'}\x1b[0m",
"COMMAND = browse_website ARGUMENTS ="
"{'url': 'https://www.google.com',"
" 'question': 'What is the capital of France?'}",
),
(
"{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten': 'https://github.com/Significant-Gravitas/AutoGPT, https://discord.gg/autogpt und https://twitter.com/Auto_GPT'}",
"{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten': 'https://github.com/Significant-Gravitas/AutoGPT, https://discord.gg/autogpt und https://twitter.com/Auto_GPT'}",
"{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten':"
"'https://github.com/Significant-Gravitas/AutoGPT,"
"https://discord.gg/autogpt und https://twitter.com/Auto_GPT'}",
"{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten':"
"'https://github.com/Significant-Gravitas/AutoGPT,"
"https://discord.gg/autogpt und https://twitter.com/Auto_GPT'}",
),
("", ""),
("hello", "hello"),
Expand Down
9 changes: 7 additions & 2 deletions autogpts/autogpt/tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def test_inspect_zip_for_modules():


def test_create_base_config(config: Config):
"""Test the backwards-compatibility shim to convert old plugin allow/deny list to a config file"""
"""
Test the backwards-compatibility shim to convert old plugin allow/deny list to a
config file
"""
config.plugins_allowlist = ["a", "b"]
config.plugins_denylist = ["c", "d"]

Expand Down Expand Up @@ -96,7 +99,9 @@ def test_create_base_config(config: Config):


def test_load_config(config: Config):
"""Test that the plugin config is loaded correctly from the plugins_config.yaml file"""
"""
Test that the plugin config is loaded correctly from the plugins_config.yaml file
"""
# Create a test config and write it to disk
test_config = {
"a": {"enabled": True, "config": {"api_key": "1234"}},
Expand Down
10 changes: 7 additions & 3 deletions autogpts/autogpt/tests/unit/test_retry_provider_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def test_retry_open_api_passing(
retry_count: int,
failure: bool,
):
"""Tests the retry with simulated errors [RateLimitError, ServiceUnavailableError, APIError], but should ulimately pass"""
"""
Tests the retry with simulated errors
[RateLimitError, ServiceUnavailableError, APIError],
but should ulimately pass
"""

# Add capture handler to non-propagating logger
logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER).addHandler(caplog.handler)
Expand All @@ -81,10 +85,10 @@ def test_retry_open_api_passing(
output = caplog.text

if error_count and retry_count:
if type(error) == RateLimitError:
if type(error) is RateLimitError:
assert "Reached rate limit" in output
assert "Please double check" in output
if type(error) == ServiceUnavailableError:
if type(error) is ServiceUnavailableError:
assert "The OpenAI API engine is currently overloaded" in output
assert "Please double check" in output
else:
Expand Down
Loading

0 comments on commit f4303d3

Please sign in to comment.