Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)


Expand Down
22 changes: 12 additions & 10 deletions test/agentchat/contrib/test_compressible_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
from autogen.agentchat.contrib.compressible_agent import CompressibleAgent

here = 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: E402

try:
import openai

except ImportError:
skip = True
else:
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,
Expand Down
8 changes: 5 additions & 3 deletions test/agentchat/contrib/test_gpt_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
import openai
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from autogen.oai.openai_utils import retrieve_assistants_by_name

except ImportError:
skip = True
else:
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):
Expand Down
5 changes: 4 additions & 1 deletion test/oai/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down