@@ -474,7 +474,7 @@ async def test_a_generate_reply_raises_on_messages_and_sender_none(conversable_a
474
474
def test_update_function_signature_and_register_functions () -> None :
475
475
with pytest .MonkeyPatch .context () as mp :
476
476
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
477
- agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
477
+ agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
478
478
479
479
def exec_python (cell : str ) -> None :
480
480
pass
@@ -618,9 +618,9 @@ def get_origin(d: Dict[str, Callable[..., Any]]) -> Dict[str, Callable[..., Any]
618
618
def test_register_for_llm ():
619
619
with pytest .MonkeyPatch .context () as mp :
620
620
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
621
- agent3 = ConversableAgent (name = "agent3" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
622
- agent2 = ConversableAgent (name = "agent2" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
623
- agent1 = ConversableAgent (name = "agent1" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
621
+ agent3 = ConversableAgent (name = "agent3" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
622
+ agent2 = ConversableAgent (name = "agent2" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
623
+ agent1 = ConversableAgent (name = "agent1" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
624
624
625
625
@agent3 .register_for_llm ()
626
626
@agent2 .register_for_llm (name = "python" )
@@ -691,9 +691,9 @@ async def exec_sh(script: Annotated[str, "Valid shell script to execute."]) -> s
691
691
def test_register_for_llm_api_style_function ():
692
692
with pytest .MonkeyPatch .context () as mp :
693
693
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
694
- agent3 = ConversableAgent (name = "agent3" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
695
- agent2 = ConversableAgent (name = "agent2" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
696
- agent1 = ConversableAgent (name = "agent1" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
694
+ agent3 = ConversableAgent (name = "agent3" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
695
+ agent2 = ConversableAgent (name = "agent2" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
696
+ agent1 = ConversableAgent (name = "agent1" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
697
697
698
698
@agent3 .register_for_llm (api_style = "function" )
699
699
@agent2 .register_for_llm (name = "python" , api_style = "function" )
@@ -762,7 +762,7 @@ async def exec_sh(script: Annotated[str, "Valid shell script to execute."]) -> s
762
762
def test_register_for_llm_without_description ():
763
763
with pytest .MonkeyPatch .context () as mp :
764
764
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
765
- agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
765
+ agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
766
766
767
767
with pytest .raises (ValueError ) as e :
768
768
@@ -774,33 +774,33 @@ def exec_python(cell: Annotated[str, "Valid Python cell to execute."]) -> str:
774
774
775
775
776
776
def test_register_for_llm_without_LLM ():
777
- try :
777
+ with pytest .raises (
778
+ ValueError ,
779
+ match = "Please either set llm_config to False, or specify a non-empty 'model' either in 'llm_config' or in each config of 'config_list'." ,
780
+ ):
778
781
ConversableAgent (name = "agent" , llm_config = None )
779
- assert False , "Expected ConversableAgent to throw ValueError."
780
- except ValueError as e :
781
- assert e .args [0 ] == "Please specify the value for 'llm_config'."
782
782
783
783
784
784
def test_register_for_llm_without_configuration ():
785
- try :
785
+ with pytest .raises (
786
+ ValueError ,
787
+ match = "Please either set llm_config to False, or specify a non-empty 'model' either in 'llm_config' or in each config of 'config_list'." ,
788
+ ):
786
789
ConversableAgent (name = "agent" , llm_config = {"config_list" : []})
787
- assert False , "Expected ConversableAgent to throw ValueError."
788
- except ValueError as e :
789
- assert e .args [0 ] == "Please specify a value for the 'model' in 'llm_config'."
790
790
791
791
792
792
def test_register_for_llm_without_model_name ():
793
- try :
794
- ConversableAgent ( name = "agent" , llm_config = { "config_list" : [{ "model" : "" , "api_key" : "" }]})
795
- assert False , "Expected ConversableAgent to throw ValueError."
796
- except ValueError as e :
797
- assert e . args [ 0 ] == "Please specify a non-empty ' model' value for every item in 'config_list'."
793
+ with pytest . raises (
794
+ ValueError ,
795
+ match = "Please either set llm_config to False, or specify a non-empty 'model' either in 'llm_config' or in each config of 'config_list'." ,
796
+ ) :
797
+ ConversableAgent ( name = "agent" , llm_config = { "config_list" : [{ " model" : "" }]})
798
798
799
799
800
800
def test_register_for_execution ():
801
801
with pytest .MonkeyPatch .context () as mp :
802
802
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
803
- agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
803
+ agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
804
804
user_proxy_1 = UserProxyAgent (name = "user_proxy_1" )
805
805
user_proxy_2 = UserProxyAgent (name = "user_proxy_2" )
806
806
@@ -835,7 +835,7 @@ async def exec_sh(script: Annotated[str, "Valid shell script to execute."]):
835
835
def test_register_functions ():
836
836
with pytest .MonkeyPatch .context () as mp :
837
837
mp .setenv ("OPENAI_API_KEY" , MOCK_OPEN_AI_API_KEY )
838
- agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" , "api_key" : "" }]})
838
+ agent = ConversableAgent (name = "agent" , llm_config = {"config_list" : [{"model" : "gpt-4" }]})
839
839
user_proxy = UserProxyAgent (name = "user_proxy" )
840
840
841
841
def exec_python (cell : Annotated [str , "Valid Python cell to execute." ]) -> str :
@@ -1028,20 +1028,6 @@ def stopwatch(num_seconds: Annotated[str, "Number of seconds in the stopwatch."]
1028
1028
stopwatch_mock .assert_called_once_with (num_seconds = "5" )
1029
1029
1030
1030
1031
- @pytest .mark .skipif (
1032
- skip ,
1033
- reason = "do not run if skipping openai" ,
1034
- )
1035
- def test_no_llm_config ():
1036
- # We expect a TypeError when the model isn't specified
1037
- with pytest .raises (TypeError , match = r".*Missing required arguments.*" ):
1038
- agent1 = ConversableAgent (name = "agent1" , llm_config = False , human_input_mode = "NEVER" , default_auto_reply = "" )
1039
- agent2 = ConversableAgent (
1040
- name = "agent2" , llm_config = {"api_key" : "Intentionally left blank." }, human_input_mode = "NEVER"
1041
- )
1042
- agent1 .initiate_chat (agent2 , message = "hi" )
1043
-
1044
-
1045
1031
if __name__ == "__main__" :
1046
1032
# test_trigger()
1047
1033
# test_context()
0 commit comments