Skip to content

yggdrasil.loki.engines.databricks_engine

databricks_engine

Databricks model-serving -backed :class:TokenEngine.

Reasons against a Databricks serving endpoint (a Foundation Model API endpoint, or any chat-shaped served model) using the authenticated DatabricksClient as the credential provider — so a Loki running on Databricks needs no extra API key.

DatabricksServingEngine

DatabricksServingEngine(
    *,
    client: Any = None,
    endpoint: Optional[str] = None,
    model: Optional[str] = None,
    available: Optional[bool] = None
)

Bases: TokenEngine

Reason via a Databricks serving endpoint.

model_label property

model_label: str

Human label for status output — the pin, or the adaptive ceiling.

warm

warm() -> None

Best-effort: build + cache the OpenAI-compatible client ahead of the first completion so the first submit isn't slowed by client setup.

A no-op when the openai dep isn't present yet (the first real call installs it) — the warmer must never trigger a background pip install.

choose_tier

choose_tier(
    messages: Optional[list[dict[str, Any]]] = None,
    system: Optional[str] = None,
) -> str

Adaptive tier for this request: "deep" or "fast".

Sizes on the message content (the actual work, not the fixed system boilerplate) and scans both message and system text for reasoning signals. Long or signalled requests get the deep tier; the rest stay fast. Override for a smarter policy.

resolve_model

resolve_model(
    *,
    messages: Optional[list[dict[str, Any]]] = None,
    system: Optional[str] = None,
    tier: Optional[str] = None
) -> Optional[str]

The model id to use for this request.

An explicit self.model pin wins. Otherwise a forced tier (arg or self.tier) selects from :attr:MODELS; with neither, the tier is chosen adaptively. Falls back to :attr:default_model when the tier isn't in the map.

usage

usage() -> list[Any]

This engine's per-model usage rows from the global meter.

generate

generate(
    prompt: str,
    *,
    system: Optional[str] = None,
    tier: Optional[str] = None,
    **options: Any
) -> str

Convenience: complete a single user prompt → reply text.

generate_stream

generate_stream(
    prompt: str,
    *,
    system: Optional[str] = None,
    tier: Optional[str] = None,
    **options: Any
) -> "Iterator[str]"

Convenience: stream a single user prompt → text chunks.