A programming framework for agentic AI
[Core] Throw an error when the OAI_CONFIG_LIST is missing. (#1082)
afourney4fcc45f14034
diff --git a/autogen/oai/openai_utils.py b/autogen/oai/openai_utils.pyindex 70662668d..42e95d051 100644--- a/autogen/oai/openai_utils.py+++ b/autogen/oai/openai_utils.py@@ -436,6 +436,9 @@ def config_list_from_json(Returns:List[Dict]: A list of configuration dictionaries that match the filtering criteria specified in `filter_dict`.++ Raises:+ FileNotFoundError: if env_or_file is neither found as an environment variable nor a file"""env_str = os.environ.get(env_or_file)@@ -453,12 +456,8 @@ def config_list_from_json(# The environment variable does not exist.# So, `env_or_file` is a filename. We should use the file location.config_list_path = os.path.join(file_location, env_or_file)- try:- with open(config_list_path) as json_file:- config_list = json.load(json_file)- except FileNotFoundError:- logging.warning(f"The specified config_list file '{config_list_path}' does not exist.")- return []+ with open(config_list_path) as json_file:+ config_list = json.load(json_file)return filter_config(config_list, filter_dict)diff --git a/test/agentchat/contrib/test_compressible_agent.py b/test/agentchat/contrib/test_compressible_agent.pyindex 47a11ef16..298fd01e9 100644--- a/test/agentchat/contrib/test_compressible_agent.py+++ b/test/agentchat/contrib/test_compressible_agent.py@@ -6,25 +6,27 @@ from conftest import skip_openaifrom autogen.agentchat.contrib.compressible_agent import CompressibleAgenthere = os.path.abspath(os.path.dirname(__file__))-KEY_LOC = "notebook"-OAI_CONFIG_LIST = "OAI_CONFIG_LIST"--config_list = autogen.config_list_from_json(- OAI_CONFIG_LIST,- file_location=KEY_LOC,- filter_dict={- "model": ["gpt-3.5-turbo", "gpt-35-turbo", "gpt-3.5-turbo-16k", "gpt-35-turbo-16k"],- },-)+sys.path.append(os.path.join(os.path.dirname(__file__), ".."))+from test_assistant_agent import OAI_CONFIG_LIST, KEY_LOC # noqa: E402try:import openai+except ImportError:skip = Trueelse:skip = False or skip_openai+if not skip:+ config_list = autogen.config_list_from_json(+ OAI_CONFIG_LIST,+ file_location=KEY_LOC,+ filter_dict={+ "model": ["gpt-3.5-turbo", "gpt-35-turbo", "gpt-3.5-turbo-16k", "gpt-35-turbo-16k"],+ },+ )+@pytest.mark.skipif(sys.platform in ["darwin", "win32"] or skip,diff --git a/test/agentchat/contrib/test_gpt_assistant.py b/test/agentchat/contrib/test_gpt_assistant.pyindex fe92501c4..0a7e92e8c 100644--- a/test/agentchat/contrib/test_gpt_assistant.py+++ b/test/agentchat/contrib/test_gpt_assistant.py@@ -12,14 +12,16 @@ try:import openaifrom autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgentfrom autogen.oai.openai_utils import retrieve_assistants_by_name+except ImportError:skip = Trueelse:skip = False or skip_openai-config_list = autogen.config_list_from_json(- OAI_CONFIG_LIST, file_location=KEY_LOC, filter_dict={"api_type": ["openai"]}-)+if not skip:+ config_list = autogen.config_list_from_json(+ OAI_CONFIG_LIST, file_location=KEY_LOC, filter_dict={"api_type": ["openai"]}+ )def ask_ossinsight(question):diff --git a/test/oai/test_utils.py b/test/oai/test_utils.pyindex 7de8dc322..ab8d2544f 100644--- a/test/oai/test_utils.py+++ b/test/oai/test_utils.py@@ -73,7 +73,6 @@ def test_config_list_from_json():json_data = json.loads(JSON_SAMPLE)tmp_file.write(JSON_SAMPLE)tmp_file.flush()-config_list = autogen.config_list_from_json(tmp_file.name)assert len(config_list) == len(json_data)@@ -115,6 +114,10 @@ def test_config_list_from_json():del os.environ["config_list_test"]+ # Test that an error is thrown when the config list is missing+ with pytest.raises(FileNotFoundError):+ autogen.config_list_from_json("OAI_CONFIG_LIST.missing")+def test_config_list_openai_aoai():# Testing the functionality for loading configurations for different API types