Skip to content

litellm_tracer

litellm_match_model(model_name)

Match according provider and model from a litellm model_name.

Parameters:

Name Type Description Default
model_name str

Name of the model as used in litellm.

required

Returns:

Type Description
Optional[tuple[str, str]]

A tuple (provider, model_name) matching a record of the ModelRepository.

Source code in ecologits/tracers/litellm_tracer.py
def litellm_match_model(model_name: str) -> Optional[tuple[str, str]]:
    """
    Match according provider and model from a litellm model_name.

    Args:
        model_name: Name of the model as used in litellm.

    Returns:
        A tuple (provider, model_name) matching a record of the ModelRepository.
    """
    candidate = process.extractOne(
        query=model_name,
        choices=_model_choices,
        scorer=fuzz.token_sort_ratio,
        score_cutoff=51
    )
    if candidate is not None:
        provider, model_name = candidate[0].split("/", 1)
        return provider, model_name
    return None