Merge pull request #1471 from gersh/fix_agents

Fix list_agents to return string instead of JSON object
pull/1656/head
Richard Beales 2023-04-15 18:46:50 +01:00 committed by GitHub
commit e0590e08d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -276,9 +276,9 @@ def list_agents():
"""List all agents
Returns:
list: A list of all agents
str: A list of all agents
"""
return AGENT_MANAGER.list_agents()
return "List of agents:\n" + "\n".join([str(x[0]) + ": " + x[1] for x in AGENT_MANAGER.list_agents()])
def delete_agent(key: str) -> str:

View File

@ -0,0 +1,18 @@
import autogpt.agent.agent_manager as agent_manager
from autogpt.app import start_agent, list_agents
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
start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2")
agents = list_agents()
self.assertEqual("List of agents:\n0: chat", agents)
start_agent("Test Agent 2", "write", "Hello, how are you?", "gpt2")
agents = list_agents()
self.assertEqual("List of agents:\n0: chat\n1: write", agents)