mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-23 17:04:21 +01:00
Additional changes: * Improve typing * Modularize message history memory & fix/refactor lots of things * Fix summarization * Move memory relevance calculation to MemoryItem & improve test * Fix import warnings in web_selenium.py * Remove `memory_add` ghost command * Implement overlap in `split_text` * Move memory tests into subdirectory * Remove deprecated `get_ada_embedding()` and helpers * Fix used token calculation in `chat_with_ai` * Replace Message TypedDict by dataclass * Fix AgentManager singleton issues in tests --------- Co-authored-by: Auto-GPT-Bot <github-bot@agpt.co>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import pytest
|
|
|
|
from autogpt.agent.agent_manager import AgentManager
|
|
from autogpt.llm.chat import create_chat_completion
|
|
|
|
|
|
@pytest.fixture
|
|
def agent_manager():
|
|
# Hack, real gross. Singletons are not good times.
|
|
yield AgentManager()
|
|
del AgentManager._instances[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-3.5-turbo"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_create_chat_completion(mocker):
|
|
mock_create_chat_completion = mocker.patch(
|
|
"autogpt.agent.agent_manager.create_chat_completion",
|
|
wraps=create_chat_completion,
|
|
)
|
|
mock_create_chat_completion.return_value = "irrelevant"
|
|
return mock_create_chat_completion
|
|
|
|
|
|
def test_create_agent(agent_manager: AgentManager, 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
|
|
|
|
|
|
def test_message_agent(agent_manager: AgentManager, 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)
|
|
|
|
|
|
def test_list_agents(agent_manager: AgentManager, 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
|
|
|
|
|
|
def test_delete_agent(agent_manager: AgentManager, 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
|