Test Agent.create_agent_feedback (#3209)

This commit is contained in:
merwanehamadi
2023-04-25 08:41:57 -07:00
committed by GitHub
parent 6fc6ea69d2
commit 58d84787f3
2 changed files with 48 additions and 12 deletions

View File

@@ -0,0 +1,40 @@
from autogpt.agent.agent import Agent
from autogpt.config import AIConfig
from autogpt.llm_utils 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