You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_human_input.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3 -m pytest
  2. import autogen
  3. import pytest
  4. from unittest.mock import MagicMock
  5. from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
  6. import sys
  7. import os
  8. sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
  9. from conftest import skip_openai as skip # noqa: E402
  10. @pytest.mark.skipif(skip, reason="requested to skip")
  11. def test_get_human_input():
  12. config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, KEY_LOC)
  13. # create an AssistantAgent instance named "assistant"
  14. assistant = autogen.AssistantAgent(
  15. name="assistant",
  16. max_consecutive_auto_reply=2,
  17. llm_config={"timeout": 600, "cache_seed": 41, "config_list": config_list, "temperature": 0},
  18. )
  19. user_proxy = autogen.UserProxyAgent(name="user", human_input_mode="ALWAYS", code_execution_config=False)
  20. # Use MagicMock to create a mock get_human_input function
  21. user_proxy.get_human_input = MagicMock(return_value="This is a test")
  22. res = user_proxy.initiate_chat(assistant, clear_history=True, message="Hello.")
  23. print("Result summary:", res.summary)
  24. print("Human input:", res.human_input)
  25. # Test without supplying messages parameter
  26. res = user_proxy.initiate_chat(assistant, clear_history=True)
  27. print("Result summary:", res.summary)
  28. print("Human input:", res.human_input)
  29. # Assert that custom_a_get_human_input was called at least once
  30. user_proxy.get_human_input.assert_called()
  31. if __name__ == "__main__":
  32. test_get_human_input()