Lee-W commented on code in PR #76802:
URL: https://github.com/apache/airflow/pull/76802#discussion_r4696095796
##########
providers/common/ai/src/airflow/providers/common/ai/hooks/pydantic_ai.py:
##########
@@ -630,15 +631,17 @@ def ensure_model_ready(
Opt-in, blocks the worker slot, and loads only this hook's own
connection. Details and
limits: :ref:`self_hosted_models_ensure_model_ready`.
- :param timeout: Seconds to wait for the load request, passed to the
backend as is.
+ :param timeout: Seconds to wait for the load request, passed to the
backend as is. A backend
+ may spend it over several requests.
:param backend_factory: Callable that takes the keyword arguments
``model_name`` (the
resolved name without its provider prefix) and ``base_url`` (the
connection host, or
``None``) and returns an object with ``load()`` (see
ModelReadinessBackend). When
given, the model prefix and connection host checks are skipped; a
missing model still
raises ``ValueError``. See
:ref:`self_hosted_models_readiness_backend`.
:raises ValueError: If *timeout* is not a positive finite number or no
model is configured;
also from the default ``OllamaBackend`` when neither the
connection host nor the
- ``OLLAMA_BASE_URL`` environment variable is set.
+ ``OLLAMA_BASE_URL`` environment variable is set, and from
``LMStudioBackend`` when the
+ model list has an unexpected shape.
Review Comment:
`:raises ValueError` now names `LMStudioBackend` for a connection with no
host.
##########
providers/common/ai/tests/unit/common/ai/hooks/test_pydantic_ai.py:
##########
@@ -1940,6 +1941,30 @@ def test_backend_factory_skips_the_host_check(self,
mock_ollama_cls):
stub.load.assert_called_once()
mock_ollama_cls.assert_not_called()
+ def test_backend_factory_can_return_an_lmstudio_backend(self):
+ requests: list[httpx2.Request] = []
+
+ def handler(request: httpx2.Request) -> httpx2.Response:
+ requests.append(request)
+ if request.method == "GET":
+ return httpx2.Response(200, json={"models": [{"key": "qwen3",
"loaded_instances": []}]})
+ return httpx2.Response(200, json={"status": "loaded"})
+
+ hook, conn = self._build_hook(model_id="openai:qwen3",
host="http://lmstudio:1234/v1")
+
+ with patch.object(hook, "get_connection", return_value=conn):
+ hook.ensure_model_ready(
+ backend_factory=lambda model_name, base_url: LMStudioBackend(
Review Comment:
The test now passes `functools.partial(LMStudioBackend, transport=...)`
instead of the lambda.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]