kaxil commented on code in PR #71437:
URL: https://github.com/apache/airflow/pull/71437#discussion_r3963512413


##########
providers/common/ai/src/airflow/providers/common/ai/hooks/pydantic_ai.py:
##########
@@ -160,30 +181,57 @@ def get_conn(self) -> Model:
 
         provider_kwargs = self._get_provider_kwargs(api_key, base_url, extra)
         if provider_kwargs:
-            _kwargs = provider_kwargs  # capture for closure
             self.log.info(
                 "Using explicit credentials for provider with model '%s': %s",
                 model_name,
                 list(provider_kwargs),
             )
-
-            def _provider_factory(pname: str) -> Any:
-                try:
-                    return infer_provider_class(pname)(**_kwargs)
-                except TypeError:
-                    self.log.warning(
-                        "Provider '%s' rejected kwargs %s; falling back to 
env-var auth",
-                        pname,
-                        list(_kwargs),
-                    )
-                    return infer_provider(pname)
-
-            self._model = infer_model(model_name, 
provider_factory=_provider_factory)
+            self._model = infer_model(
+                model_name,
+                
provider_factory=self._create_provider_factory(provider_kwargs),
+            )
             return self._model
 
         self._model = infer_model(model_name)
         return self._model
 
+    def get_embedder(self) -> Embedder:

Review Comment:
   Yes, check both. Nothing here makes an API call, so validating the embedding 
model when it's configured costs nothing, and as written a connection with a 
good `model` and a typo in `embed_model` reports green in the UI. The user 
finds out on the first task run instead.
   
   The new ordering also changed the failure message for a connection with 
neither field set: it now reads `No embedding model specified. Set 
embed_model_id on the hook or the embed_model field on the connection.`, which 
the updated assertion in `test_failed_connection_no_model` pins. The likelier 
mistake there is a forgotten Model field, so the message points at the wrong 
one. Naming both fields when neither is set would read better.
   
   For context, `LangChainHook` and `LlamaIndexHook` both resolve only the LLM 
in `test_connection` (#71841), so they carry the same blind spot for embed-only 
connections. Not something to fix here.



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