Lee-W commented on code in PR #76802:
URL: https://github.com/apache/airflow/pull/76802#discussion_r4706563682


##########
providers/common/ai/src/airflow/providers/common/ai/hooks/lmstudio.py:
##########
@@ -0,0 +1,158 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import time
+from typing import Any
+
+import httpx2
+
+from airflow.providers.common.ai.utils.readiness_errors import (
+    extract_error_detail,
+    translate_readiness_errors,
+)
+
+# Endpoints and fields: https://lmstudio.ai/docs/developer/rest/list and
+# https://lmstudio.ai/docs/developer/rest/load
+_LIST_MODELS_PATH = "/api/v1/models"
+_LOAD_MODEL_PATH = "/api/v1/models/load"
+
+
+def build_lmstudio_native_root(base_url: str) -> str:

Review Comment:
   yep, it's public for matching `build_ollama_native_root`



##########
providers/common/ai/tests/unit/common/ai/hooks/test_lmstudio.py:
##########
@@ -0,0 +1,326 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import json
+import re
+from unittest import mock
+
+import httpx2
+import pytest
+
+from airflow.providers.common.ai.hooks.lmstudio import LMStudioBackend, 
build_lmstudio_native_root
+
+_BASE_URL = "http://lmstudio:1234/v1";
+_TIME = "airflow.providers.common.ai.hooks.lmstudio.time"
+
+
+def _build_backend(handler, base_url: str = _BASE_URL, model_name: str = 
"qwen3") -> LMStudioBackend:
+    return LMStudioBackend(base_url, model_name, 
transport=httpx2.MockTransport(handler))
+
+
+def _build_models_response(*, loaded: bool, key: str = "qwen3") -> 
httpx2.Response:
+    instances = [{"id": key, "config": {"context_length": 4096}}] if loaded 
else []
+    return httpx2.Response(
+        200,
+        json={
+            "models": [
+                {"type": "llm", "key": "other-model", "loaded_instances": 
[{"id": "other-model"}]},
+                {"type": "llm", "key": key, "loaded_instances": instances},
+            ]
+        },
+    )
+
+
+class TestBuildNativeRoot:
+    @pytest.mark.parametrize(
+        "base_url",
+        [
+            "http://h:1234/v1";,
+            "http://h:1234/v1/";,
+            "http://h:1234/api/v1";,
+            "http://h:1234/api/v1/";,
+            "http://h:1234";,
+            "http://h:1234/";,
+        ],
+    )
+    def test_returns_server_root(self, base_url):
+        assert build_lmstudio_native_root(base_url) == "http://h:1234";
+
+
+class TestLMStudioBackendBaseUrl:
+    @pytest.mark.parametrize("base_url", [None, ""], ids=["base-url-none", 
"base-url-empty"])
+    def test_missing_base_url_raises_value_error(self, base_url):
+        with pytest.raises(ValueError, match="needs a base_url"):
+            LMStudioBackend(base_url=base_url, model_name="qwen3")
+
+    @pytest.mark.parametrize("base_url", ["http://h:1234/v1";, 
"http://h:1234/api/v1";])
+    def test_root_drops_api_suffix(self, base_url):

Review Comment:
   test_root_drops_api_suffix is removed



-- 
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]

Reply via email to