autogen
autogen.filter_config
filter_config
This function filters config_list
by checking each configuration dictionary against the criteria specified in
filter_dict
. A configuration dictionary is retained if for every key in filter_dict
, see example below.
Name | Description |
---|---|
config_list | A list of configuration dictionaries to be filtered. Type: list[dict[str, typing.Any]] |
filter_dict | A dictionary representing the filter criteria, where each key is a field name to check within the configuration dictionaries, and the corresponding value is a list of acceptable values for that field. If the configuration’s field’s value is not a list, then a match occurs when it is found in the list of acceptable values. If the configuration’s field’s value is a list, then a match occurs if there is a non-empty intersection with the acceptable values. Type: dict[str, list[str | None] | set[str | None]] | None |
exclude | If False (the default value), configs that match the filter will be included in the returned list. If True, configs that match the filter will be excluded in the returned list. Type: bool Default: False |
Type | Description |
---|---|
list[dict[str, typing.Any]] | list of dict: A list of configuration dictionaries that meet all the criteria specified in filter_dict . Example: python # Example configuration list with various models and API types configs = [ \\{"model": "gpt-3.5-turbo"}, \\{"model": "gpt-4"}, \\{"model": "gpt-3.5-turbo", "api_type": "azure"}, \\{"model": "gpt-3.5-turbo", "tags": ["gpt35_turbo", "gpt-35-turbo"]}, ] # Define filter criteria to select configurations for the 'gpt-3.5-turbo' model # 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": ["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': 'azure', ...}] # Define a filter to select a given tag filter_criteria = \\{ "tags": ["gpt35_turbo"], } # 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', 'tags': ['gpt35_turbo', 'gpt-35-turbo']}] |