Files
Auto-GPT/tests/unit/test_get_self_feedback.py
2023-04-28 12:00:54 -07:00

41 lines
1.2 KiB
Python

from autogpt.agent.agent import Agent
from autogpt.config import AIConfig
from autogpt.llm import create_chat_completion
def test_get_self_feedback(mocker):
# Define a sample thoughts dictionary
thoughts = {
"reasoning": "Sample reasoning.",
"plan": "Sample plan.",
"thoughts": "Sample thoughts.",
"criticism": "Sample criticism.",
}
# Define a fake response for the create_chat_completion function
fake_response = (
"Y The provided information is suitable for achieving the role's objectives."
)
# Mock the create_chat_completion function
mock_create_chat_completion = mocker.patch(
"autogpt.agent.agent.create_chat_completion", wraps=create_chat_completion
)
mock_create_chat_completion.return_value = fake_response
# Create a MagicMock object to replace the Agent instance
agent_mock = mocker.MagicMock(spec=Agent)
# Mock the config attribute of the Agent instance
agent_mock.config = AIConfig()
# Call the get_self_feedback method
feedback = Agent.get_self_feedback(
agent_mock,
thoughts,
"gpt-3.5-turbo",
)
# Check if the response is correct
assert feedback == fake_response