Skip to content

teff.provider.builtin.base

teff.provider.builtin.base

The :class:Provider value object.

A provider is a named model endpoint: how to speak to it (type selects the wire protocol) and where it lives (base_url / chat_path / auth keys). Built-in presets are subclasses that set the defaults; custom providers are plain instances declared in a workflow's providers: block or passed to graph.run(providers=...).

Classes:

Name Description
Provider

A named model endpoint: wire protocol + endpoint data.

Provider

A named model endpoint: wire protocol + endpoint data.

name is the registry key used by provider= references. type is the protocol discriminator — openai_compatible / anthropic_compatible / ollama — and decides the request body, streaming chunk parsing, and response extraction held by :class:~teff.harness.Harness.

Built-in presets subclass this and set name (and the other fields) once; a custom provider is a plain instance. Fields may be overridden at construction:

Provider(name="my-vllm", type="openai_compatible", base_url="http://vllm:8000/v1")

type is deliberately a distinct concept from name: the name is just a key and never carries protocol meaning.

Methods:

Name Description
from_mapping

Build from a config dict, keeping only known fields.

to_dict

All provider fields as a plain dict (for YAML serialisation).

Source code in teff/provider/builtin/base.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Provider:
    """A named model endpoint: wire protocol + endpoint data.

    ``name`` is the registry key used by ``provider=`` references.
    ``type`` is the protocol discriminator — ``openai_compatible`` /
    ``anthropic_compatible`` / ``ollama`` — and decides the request body,
    streaming chunk parsing, and response extraction held by
    :class:`~teff.harness.Harness`.

    Built-in presets subclass this and set ``name`` (and the other fields)
    once; a custom provider is a plain instance.  Fields may be overridden
    at construction:

        Provider(name="my-vllm", type="openai_compatible", base_url="http://vllm:8000/v1")

    ``type`` is deliberately a distinct concept from ``name``: the name is
    just a key and never carries protocol meaning.
    """

    name: str = ""
    type: str = "openai_compatible"
    base_url: str = ""
    chat_path: str = "/chat/completions"
    api_key_env: str = ""
    auth_header: str = "Authorization"
    auth_prefix: str = "Bearer "
    timeout: float = 120.0

    def __init__(self, **overrides):
        unknown = set(overrides) - set(PROVIDER_FIELDS)
        if unknown:
            raise TypeError(f"unknown Provider field(s): {', '.join(sorted(unknown))}")
        for field in PROVIDER_FIELDS:
            if field in overrides:
                setattr(self, field, overrides[field])

    @classmethod
    def from_mapping(cls, cfg: dict) -> "Provider":
        """Build from a config dict, keeping only known fields."""
        return cls(**{f: cfg[f] for f in PROVIDER_FIELDS if f in cfg})

    def to_dict(self) -> dict:
        """All provider fields as a plain dict (for YAML serialisation)."""
        return {f: getattr(self, f) for f in PROVIDER_FIELDS}

    def __repr__(self) -> str:
        shown = ", ".join(
            f"{f}={getattr(self, f)!r}" for f in PROVIDER_FIELDS if getattr(self, f)
        )
        return f"{type(self).__name__}({shown})"

from_mapping classmethod

from_mapping(cfg)

Build from a config dict, keeping only known fields.

Source code in teff/provider/builtin/base.py
58
59
60
61
@classmethod
def from_mapping(cls, cfg: dict) -> "Provider":
    """Build from a config dict, keeping only known fields."""
    return cls(**{f: cfg[f] for f in PROVIDER_FIELDS if f in cfg})

to_dict

to_dict()

All provider fields as a plain dict (for YAML serialisation).

Source code in teff/provider/builtin/base.py
63
64
65
def to_dict(self) -> dict:
    """All provider fields as a plain dict (for YAML serialisation)."""
    return {f: getattr(self, f) for f in PROVIDER_FIELDS}