uranusjr commented on code in PR #75369:
URL: https://github.com/apache/airflow/pull/75369#discussion_r4463157904


##########
providers/common/ai/src/airflow/providers/common/ai/hooks/ollama.py:
##########
@@ -0,0 +1,69 @@
+# 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 httpx2
+
+
+def build_ollama_native_root(base_url: str) -> str:
+    """Return the server root of an Ollama URL, dropping a trailing ``/v1`` 
(the OpenAI-compatible path)."""
+    return base_url.rstrip("/").removesuffix("/v1")
+
+
+class OllamaBackend:
+    """
+    Load control for a model served by Ollama, through its native 
``/api/generate`` endpoint.
+
+    :param base_url: Ollama URL; a trailing ``/v1`` is dropped to reach the 
native API.
+    :param model_name: Model name without the ``ollama:`` prefix.
+    :param transport: Optional httpx2 transport, mainly to stub the server in 
tests.
+
+    Known limitation: the connection password is not sent, so no 
``Authorization`` header is
+    added and servers behind authentication are not supported.
+    """
+
+    def __init__(
+        self,
+        base_url: str,
+        model_name: str,
+        *,
+        transport: httpx2.BaseTransport | None = None,
+    ) -> None:
+        self.root = build_ollama_native_root(base_url)

Review Comment:
   The hook calls the factory with `base_url=conn.host or None`. Documentation  
tells users to pass `backend_factory=OllamaBackend` for OpenAI models. With no 
host on the connection (the `OLLAMA_BASE_URL` setup), this ends up calling 
`None.rstrip("/")`.



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