From bac898f9934fb1766869def0246808d9b7ade255 Mon Sep 17 00:00:00 2001 From: Gershon Bialer Date: Fri, 14 Apr 2023 20:59:58 -0700 Subject: [PATCH 1/4] Fix list_agents to not call it self. --- autogpt/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogpt/commands.py b/autogpt/commands.py index 352b3340b..7301ff68b 100644 --- a/autogpt/commands.py +++ b/autogpt/commands.py @@ -265,7 +265,7 @@ def message_agent(key, message): def list_agents(): """List all agents""" - return list_agents() + return agents.list_agents() def delete_agent(key): From 0b4f0f56226a756cdb9dad28ddb4ff25cb499263 Mon Sep 17 00:00:00 2001 From: Gershon Bialer Date: Fri, 14 Apr 2023 21:34:28 -0700 Subject: [PATCH 2/4] Add unit test for testing adding a gent --- tests/unit/test_commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/unit/test_commands.py diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py new file mode 100644 index 000000000..b7bddcec1 --- /dev/null +++ b/tests/unit/test_commands.py @@ -0,0 +1,13 @@ +from autogpt import commands +import unittest +from unittest.mock import patch,MagicMock + +class TestCommands(unittest.TestCase): + def test_make_agent(self): + with patch("openai.ChatCompletion.create") as mock: + obj = MagicMock() + obj.response.choices[0].messages[0].content = "Test message" + mock.return_value = obj + commands.start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2") + agents = commands.list_agents() + self.assertEqual(agents[0], (0,'chat')) \ No newline at end of file From 2644bc86db12cc51b3a2794c4280ceb838753b43 Mon Sep 17 00:00:00 2001 From: Gershon Bialer Date: Fri, 14 Apr 2023 21:42:54 -0700 Subject: [PATCH 3/4] list_agents should return string not JSON --- autogpt/commands.py | 2 +- tests/unit/test_commands.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autogpt/commands.py b/autogpt/commands.py index 7301ff68b..122b453e0 100644 --- a/autogpt/commands.py +++ b/autogpt/commands.py @@ -265,7 +265,7 @@ def message_agent(key, message): def list_agents(): """List all agents""" - return agents.list_agents() + return "List of agents:\n" + "\n".join([str(x[0]) + ": " + x[1] for x in agents.list_agents()]) def delete_agent(key): diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py index b7bddcec1..1ecfc517b 100644 --- a/tests/unit/test_commands.py +++ b/tests/unit/test_commands.py @@ -10,4 +10,7 @@ class TestCommands(unittest.TestCase): mock.return_value = obj commands.start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2") agents = commands.list_agents() - self.assertEqual(agents[0], (0,'chat')) \ No newline at end of file + self.assertEqual("List of agents:\n0: chat", agents) + commands.start_agent("Test Agent 2", "write", "Hello, how are you?", "gpt2") + agents = commands.list_agents() + self.assertEqual("List of agents:\n0: chat\n1: write", agents) From 9990b78702caabca3fdbb02488dde53eae75df2b Mon Sep 17 00:00:00 2001 From: Gershon Bialer Date: Fri, 14 Apr 2023 22:44:42 -0700 Subject: [PATCH 4/4] Fix linter issues. --- tests/unit/test_commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py index 1ecfc517b..9bb4c9c42 100644 --- a/tests/unit/test_commands.py +++ b/tests/unit/test_commands.py @@ -1,6 +1,7 @@ from autogpt import commands import unittest -from unittest.mock import patch,MagicMock +from unittest.mock import patch, MagicMock + class TestCommands(unittest.TestCase): def test_make_agent(self):