-
Notifications
You must be signed in to change notification settings - Fork 44.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an initial test for chat_with_ai #3793
Changes from all commits
882b408
8ca6cf5
605c803
a286bdc
1f9226f
9e04b2d
a681692
26991ed
b7f3489
c7168c4
9618530
8c6c30c
f9388aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from autogpt.agent import Agent | ||
from autogpt.config.ai_config import AIConfig | ||
from autogpt.llm.base import Message | ||
from autogpt.llm.chat import chat_with_ai | ||
|
||
|
||
@pytest.fixture | ||
def agent(): | ||
ai_name = "Test AI" | ||
memory = MagicMock() | ||
next_action_count = 0 | ||
command_registry = MagicMock() | ||
config = AIConfig() | ||
system_prompt = "System prompt" | ||
triggering_prompt = "Triggering prompt" | ||
workspace_directory = "workspace_directory" | ||
|
||
agent = Agent( | ||
ai_name, | ||
memory, | ||
next_action_count, | ||
command_registry, | ||
config, | ||
system_prompt, | ||
triggering_prompt, | ||
workspace_directory, | ||
) | ||
return agent | ||
|
||
|
||
def test_chat_with_ai_basic_response(mocker, agent): | ||
prompt = "Welcome to the autogpt!" | ||
user_input = "Hello, how are you?" | ||
token_limit = 4000 | ||
mocker.patch( | ||
"autogpt.llm.chat.create_chat_completion", | ||
return_value="I'm doing well, thank you for asking.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im still learning more about mocker so excuse me if im incorrect, but by doing this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the patched module is create_chat_completion it might be a correct implementation, so let me know if I'm missing something |
||
) | ||
|
||
response = chat_with_ai(agent, prompt, user_input, token_limit) | ||
|
||
assert response == "I'm doing well, thank you for asking." | ||
assert agent.history.messages == [ | ||
Message("user", "Hello, how are you?", None), | ||
Message("assistant", "I'm doing well, thank you for asking.", "ai_response"), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this fixture live in the
conftest.py
? there might be a agent fixture already defined therem, if so lets just use that other fixture