Keywords AI has a comprehensive routing-failover system. To ensure high efficiency, we can drop the models that don’t meet the hard requirements and fail before performing any computation.

models_to_route_between = [mode_1, model_2, model_3] # Users uploaded list from request

# Load the models into compatible_models_format
keywords_compatible_models_format = {k: v for k, v in model_dictionary.items() if k in models_to_route_between}

def filter_by_hard_requirements(scores, token_count, is_vision, kwargs):
    """
    Hard requirements:
    1. The model must support the context window size
    2. Does the model support vision?
    3. Does the model support the function call?
    """
    processed_scores = scores.copy()
    function_call = "tools" in kwargs or "tool_choice" in kwargs

    filtered_models = {}
    
    for key, value in scores.items():
        if model_dictionary[key]["max_context_window"] < token_count:
            processed_scores.pop(key)
            filtered_models[key] = "Filtered by context window size, consider reducing input tokens."
            continue
        if is_vision and not bool(model_dictionary[key]["image_support"]):
            processed_scores.pop(key)
            filtered_models[key] = "Filtered by vision support, consider changing the 'content' field to text in each message"
            continue
            
        if function_call and not bool(model_dictionary[key]["function_call"]):
            processed_scores.pop(key)
            filtered_models[key] = "Filtered by function call support, consider dropping the 'tools' and 'tool_choice' fields in the request"
            continue
    
    return processed_scores, filtered_models