mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-26 10:24:30 +01:00
Merge branch 'master' into refactor/add-indirection-layer-around-entry-point
This commit is contained in:
50
tests/test_agent.py
Normal file
50
tests/test_agent.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from autogpt.agent import Agent
|
||||
from autogpt.chat import chat_with_ai
|
||||
from autogpt.config import Config
|
||||
from autogpt.speech import say_text
|
||||
from autogpt.utils import clean_input
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def agent():
|
||||
ai_name = "Test AI"
|
||||
memory = MagicMock()
|
||||
full_message_history = []
|
||||
next_action_count = 0
|
||||
command_registry = MagicMock()
|
||||
config = Config()
|
||||
system_prompt = "System prompt"
|
||||
triggering_prompt = "Triggering prompt"
|
||||
workspace_directory = "workspace_directory"
|
||||
|
||||
agent = Agent(
|
||||
ai_name,
|
||||
memory,
|
||||
full_message_history,
|
||||
next_action_count,
|
||||
command_registry,
|
||||
config,
|
||||
system_prompt,
|
||||
triggering_prompt,
|
||||
workspace_directory,
|
||||
)
|
||||
return agent
|
||||
|
||||
|
||||
def test_agent_initialization(agent):
|
||||
assert agent.ai_name == "Test AI"
|
||||
assert agent.memory == agent.memory
|
||||
assert agent.full_message_history == []
|
||||
assert agent.next_action_count == 0
|
||||
assert agent.command_registry == agent.command_registry
|
||||
assert agent.config == agent.config
|
||||
assert agent.system_prompt == "System prompt"
|
||||
assert agent.triggering_prompt == "Triggering prompt"
|
||||
|
||||
|
||||
# More test methods can be added for specific agent interactions
|
||||
# For example, mocking chat_with_ai and testing the agent's interaction loop
|
||||
58
tests/test_agent_manager.py
Normal file
58
tests/test_agent_manager.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
|
||||
from autogpt.agent.agent_manager import AgentManager
|
||||
from tests.utils import requires_api_key
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def agent_manager():
|
||||
return AgentManager()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def task():
|
||||
return "translate English to French"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def prompt():
|
||||
return "Translate the following English text to French: 'Hello, how are you?'"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def model():
|
||||
return "gpt-4"
|
||||
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_create_agent(agent_manager, task, prompt, model):
|
||||
key, agent_reply = agent_manager.create_agent(task, prompt, model)
|
||||
assert isinstance(key, int)
|
||||
assert isinstance(agent_reply, str)
|
||||
assert key in agent_manager.agents
|
||||
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_message_agent(agent_manager, task, prompt, model):
|
||||
key, _ = agent_manager.create_agent(task, prompt, model)
|
||||
user_message = "Please translate 'Good morning' to French."
|
||||
agent_reply = agent_manager.message_agent(key, user_message)
|
||||
assert isinstance(agent_reply, str)
|
||||
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_list_agents(agent_manager, task, prompt, model):
|
||||
key, _ = agent_manager.create_agent(task, prompt, model)
|
||||
agents_list = agent_manager.list_agents()
|
||||
assert isinstance(agents_list, list)
|
||||
assert (key, task) in agents_list
|
||||
|
||||
|
||||
@requires_api_key("OPENAI_API_KEY")
|
||||
def test_delete_agent(agent_manager, task, prompt, model):
|
||||
key, _ = agent_manager.create_agent(task, prompt, model)
|
||||
success = agent_manager.delete_agent(key)
|
||||
assert success
|
||||
assert key not in agent_manager.agents
|
||||
Reference in New Issue
Block a user