airflow.providers.common.ai.hooks.lmstudio

Classes

LMStudioBackend

Load control for a model served by LM Studio, through its native /api/v1/models endpoints.

Functions

build_lmstudio_native_root(base_url)

Return the server root of an LM Studio URL, dropping a trailing /api/v1 or /v1.

Module Contents

airflow.providers.common.ai.hooks.lmstudio.build_lmstudio_native_root(base_url)[source]

Return the server root of an LM Studio URL, dropping a trailing /api/v1 or /v1.

class airflow.providers.common.ai.hooks.lmstudio.LMStudioBackend(base_url, model_name, *, transport=None)[source]

Load control for a model served by LM Studio, through its native /api/v1/models endpoints.

Pass the class to ensure_model_ready as backend_factory=LMStudioBackend.

The model list request gets timeout seconds and the load request gets what the list request left of them. Each is an httpx2 timeout, which applies to the connect, write and read phases separately, so the two requests together can still take longer than timeout.

Parameters:
  • base_url (str | None) – LM Studio URL; a trailing /v1 (OpenAI-compatible) or /api/v1 (native) is dropped to reach the server root.

  • model_name (str) – Model key as listed by GET /api/v1/models; any other name raises ValueError instead of loading a model.

  • transport (httpx2.BaseTransport | None) – Optional httpx2 transport, mainly to stub the server in tests.

Raises:

ValueError – If base_url is None or empty.

Known limitation: no Authorization header is sent, so LM Studio with API token authentication turned on is not supported.

root[source]
model_name[source]
load(*, timeout)[source]

Load the model unless LM Studio already lists it with a loaded instance, within timeout seconds.

Raises:
  • TimeoutError – If a request exceeds the time it was given (see the class docstring).

  • httpx2.ConnectError – If the server cannot be reached.

  • httpx2.HTTPStatusError – If the server answers with an error status; the message says whether listing or loading failed and carries the error text when the body has one, otherwise the start of the response body.

  • ValueError – If the model list is not a JSON object whose models is a list of objects (the message carries the body’s error text when there is one), or if none of its entries has a key equal to the model name; nothing is loaded then.

Was this entry helpful?