Skip to content

Commit

Permalink
remove inappropriate api_type (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonichi authored Jan 10, 2024
1 parent 083ba32 commit b548e55
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def config_list_openai_aoai(
exclude (str, optional): The API type to exclude from the configuration list. Can be 'openai' or 'aoai'. Defaults to None.
Returns:
List[Dict]: A list of configuration dictionaries. Each dictionary contains keys for 'api_key', 'base_url', 'api_type',
and 'api_version'.
List[Dict]: A list of configuration dictionaries. Each dictionary contains keys for 'api_key',
and optionally 'base_url', 'api_type', and 'api_version'.
Raises:
FileNotFoundError: If the specified key files are not found and the corresponding API key is not set in the environment variables.
Expand Down Expand Up @@ -241,7 +241,6 @@ def config_list_openai_aoai(
# Assuming OpenAI API_KEY in os.environ["OPENAI_API_KEY"]
api_keys=os.environ.get("OPENAI_API_KEY", "").split("\n"),
base_urls=base_urls,
# "api_type": "open_ai",
)
if exclude != "openai"
else []
Expand Down Expand Up @@ -366,23 +365,23 @@ def filter_config(config_list, filter_dict):
```
# Example configuration list with various models and API types
configs = [
{'model': 'gpt-3.5-turbo', 'api_type': 'openai'},
{'model': 'gpt-4', 'api_type': 'openai'},
{'model': 'gpt-3.5-turbo'},
{'model': 'gpt-4'},
{'model': 'gpt-3.5-turbo', 'api_type': 'azure'},
]
# Define filter criteria to select configurations for the 'gpt-3.5-turbo' model
# that are also using the 'openai' API type
# that are also using the 'azure' API type
filter_criteria = {
'model': ['gpt-3.5-turbo'], # Only accept configurations for 'gpt-3.5-turbo'
'api_type': ['openai'] # Only accept configurations for 'openai' API type
'api_type': ['azure'] # Only accept configurations for 'azure' API type
}
# Apply the filter to the configuration list
filtered_configs = filter_config(configs, filter_criteria)
# The resulting `filtered_configs` will be:
# [{'model': 'gpt-3.5-turbo', 'api_type': 'openai'}]
# [{'model': 'gpt-3.5-turbo', 'api_type': 'azure', ...}]
```
Note:
Expand Down Expand Up @@ -426,10 +425,10 @@ def config_list_from_json(
Example:
```
# Suppose we have an environment variable 'CONFIG_JSON' with the following content:
# '[{"model": "gpt-3.5-turbo", "api_type": "openai"}, {"model": "gpt-4", "api_type": "openai"}]'
# '[{"model": "gpt-3.5-turbo", "api_type": "azure"}, {"model": "gpt-4"}]'
# We can retrieve a filtered list of configurations like this:
filter_criteria = {"api_type": ["openai"], "model": ["gpt-3.5-turbo"]}
filter_criteria = {"model": ["gpt-3.5-turbo"]}
configs = config_list_from_json('CONFIG_JSON', filter_dict=filter_criteria)
# The 'configs' variable will now contain only the configurations that match the filter criteria.
```
Expand Down Expand Up @@ -472,14 +471,12 @@ def get_config(
config = get_config(
api_key="sk-abcdef1234567890",
base_url="https://api.openai.com",
api_type="openai",
api_version="v1"
)
# The 'config' variable will now contain:
# {
# "api_key": "sk-abcdef1234567890",
# "base_url": "https://api.openai.com",
# "api_type": "openai",
# "api_version": "v1"
# }
```
Expand Down

0 comments on commit b548e55

Please sign in to comment.