AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Updates to sync 0.4.1 to master
Luke71ca4ea9904e
diff --git a/autogpt/app.py b/autogpt/app.pyindex 8586653cc3..78e3a4dd20 100644--- a/autogpt/app.py+++ b/autogpt/app.py@@ -3,12 +3,6 @@ import jsonfrom typing import Dictfrom autogpt.agent.agent import Agent-from autogpt.agent.agent_manager import AgentManager-from autogpt.commands.command import command-from autogpt.commands.web_requests import scrape_links, scrape_text-from autogpt.processing.text import summarize_text-from autogpt.speech import say_text-from autogpt.url_utils.validators import validate_urldef is_valid_int(value: str) -> bool:diff --git a/tests/unit/test_api_manager.py b/tests/unit/test_api_manager.pyindex 4a21a891bc..e259f56adc 100644--- a/tests/unit/test_api_manager.py+++ b/tests/unit/test_api_manager.py@@ -1,4 +1,4 @@-from unittest.mock import patch+from unittest.mock import MagicMock, patchimport pytestfrom pytest_mock import MockerFixture@@ -29,6 +29,68 @@ def mock_costs(mocker: MockerFixture):class TestApiManager:+ @staticmethod+ def test_create_chat_completion_debug_mode(caplog):+ """Test if debug mode logs response."""+ api_manager_debug = ApiManager(debug=True)+ messages = [+ {"role": "system", "content": "You are a helpful assistant."},+ {"role": "user", "content": "Who won the world series in 2020?"},+ ]+ model = "gpt-3.5-turbo"++ with patch("openai.ChatCompletion.create") as mock_create:+ mock_response = MagicMock()+ del mock_response.error+ mock_response.usage.prompt_tokens = 10+ mock_response.usage.completion_tokens = 20+ mock_create.return_value = mock_response++ api_manager_debug.create_chat_completion(messages, model=model)++ assert "Response" in caplog.text++ @staticmethod+ def test_create_chat_completion_empty_messages():+ """Test if empty messages result in zero tokens and cost."""+ messages = []+ model = "gpt-3.5-turbo"++ with patch("openai.ChatCompletion.create") as mock_create:+ mock_response = MagicMock()+ del mock_response.error+ mock_response.usage.prompt_tokens = 0+ mock_response.usage.completion_tokens = 0+ mock_create.return_value = mock_response++ api_manager.create_chat_completion(messages, model=model)++ assert api_manager.get_total_prompt_tokens() == 0+ assert api_manager.get_total_completion_tokens() == 0+ assert api_manager.get_total_cost() == 0++ @staticmethod+ def test_create_chat_completion_valid_inputs():+ """Test if valid inputs result in correct tokens and cost."""+ messages = [+ {"role": "system", "content": "You are a helpful assistant."},+ {"role": "user", "content": "Who won the world series in 2020?"},+ ]+ model = "gpt-3.5-turbo"++ with patch("openai.ChatCompletion.create") as mock_create:+ mock_response = MagicMock()+ del mock_response.error+ mock_response.usage.prompt_tokens = 10+ mock_response.usage.completion_tokens = 20+ mock_create.return_value = mock_response++ api_manager.create_chat_completion(messages, model=model)++ assert api_manager.get_total_prompt_tokens() == 10+ assert api_manager.get_total_completion_tokens() == 20+ assert api_manager.get_total_cost() == (10 * 0.0013 + 20 * 0.0025) / 1000+def test_getter_methods(self):"""Test the getter methods for total tokens, cost, and budget."""api_manager.update_cost(600, 1200, "gpt-3.5-turbo")