Skip to content

make_litellm_lm

gepa.optimize_anything.make_litellm_lm(model_name: str) -> LanguageModel

Convert a LiteLLM model name string to a :class:LanguageModel callable.

The returned callable conforms to the LanguageModel protocol and accepts a plain str prompt, a list[dict] chat-messages list, or a multimodal messages list (with content arrays containing images).

Uses :class:gepa.lm.LM which handles reasoning model detection (o1/o3/o4/gpt-5), retries with exponential backoff, truncation warnings, and drop_params=True for cross-model compatibility.

Source code in gepa/optimize_anything.py
def make_litellm_lm(model_name: str) -> LanguageModel:
    """Convert a LiteLLM model name string to a :class:`LanguageModel` callable.

    The returned callable conforms to the ``LanguageModel`` protocol and
    accepts a plain ``str`` prompt, a ``list[dict]`` chat-messages list, or
    a multimodal messages list (with content arrays containing images).

    Uses :class:`gepa.lm.LM` which handles reasoning model detection
    (o1/o3/o4/gpt-5), retries with exponential backoff, truncation
    warnings, and ``drop_params=True`` for cross-model compatibility.
    """
    from gepa.lm import LM

    return LM(model_name)