From fb05123713e635c5bd29dfbbcc7aa545d0390016 Mon Sep 17 00:00:00 2001 From: Tyler Suard Date: Wed, 6 Dec 2023 19:06:09 -0500 Subject: [PATCH 1/2] Add test for async group chat --- test/agentchat/test_async.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/agentchat/test_async.py b/test/agentchat/test_async.py index 76176131015..30a33f60e96 100644 --- a/test/agentchat/test_async.py +++ b/test/agentchat/test_async.py @@ -4,6 +4,7 @@ from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST + def get_market_news(ind, ind_upper): data = { "feed": [ @@ -44,6 +45,50 @@ def get_market_news(ind, ind_upper): ) return feeds_summary +@pytest.mark.asyncio +async def test_async_groupchat(): + + try: + import openai + except ImportError: + return + + config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, KEY_LOC) + + llm_config={ + "timeout": 600, + "cache_seed": 41, + "config_list": config_list, + "temperature": 0, + } + + # create an AssistantAgent instance named "assistant" + assistant = autogen.AssistantAgent( + name="assistant", + llm_config={ + "timeout": 600, + "cache_seed": 41, + "config_list": config_list, + "temperature": 0, + }, + system_message="You are a helpful assistant. Reply 'TERMINATE' to end the conversation.", + ) + # create a UserProxyAgent instance named "user" + user_proxy = autogen.UserProxyAgent( + name="user", + human_input_mode="NEVER", + max_consecutive_auto_reply=5, + code_execution_config=False, + default_auto_reply=None, + ) + + groupchat = autogen.GroupChat(agents=[user_proxy, assistant], messages=[], max_round=12) + manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config, + is_termination_msg=lambda x: "TERMINATE" in x.get("content", ""), + ) + await user_proxy.a_initiate_chat(manager, + message="""Have a short conversation with the assistant.""") + assert len(user_proxy.chat_messages)>0 @pytest.mark.asyncio async def test_stream(): From a9cf2f92339cbd787f927ac31b4d028690811c2c Mon Sep 17 00:00:00 2001 From: Qingyun Wu Date: Thu, 7 Dec 2023 12:27:10 -0500 Subject: [PATCH 2/2] run pre-commit --- test/agentchat/test_async.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/test/agentchat/test_async.py b/test/agentchat/test_async.py index 30a33f60e96..6c7236e581a 100644 --- a/test/agentchat/test_async.py +++ b/test/agentchat/test_async.py @@ -4,7 +4,6 @@ from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST - def get_market_news(ind, ind_upper): data = { "feed": [ @@ -45,23 +44,23 @@ def get_market_news(ind, ind_upper): ) return feeds_summary + @pytest.mark.asyncio async def test_async_groupchat(): - try: import openai except ImportError: return - + config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, KEY_LOC) - - llm_config={ - "timeout": 600, - "cache_seed": 41, - "config_list": config_list, - "temperature": 0, - } - + + llm_config = { + "timeout": 600, + "cache_seed": 41, + "config_list": config_list, + "temperature": 0, + } + # create an AssistantAgent instance named "assistant" assistant = autogen.AssistantAgent( name="assistant", @@ -83,12 +82,14 @@ async def test_async_groupchat(): ) groupchat = autogen.GroupChat(agents=[user_proxy, assistant], messages=[], max_round=12) - manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config, - is_termination_msg=lambda x: "TERMINATE" in x.get("content", ""), - ) - await user_proxy.a_initiate_chat(manager, - message="""Have a short conversation with the assistant.""") - assert len(user_proxy.chat_messages)>0 + manager = autogen.GroupChatManager( + groupchat=groupchat, + llm_config=llm_config, + is_termination_msg=lambda x: "TERMINATE" in x.get("content", ""), + ) + await user_proxy.a_initiate_chat(manager, message="""Have a short conversation with the assistant.""") + assert len(user_proxy.chat_messages) > 0 + @pytest.mark.asyncio async def test_stream():